Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
chaos_familien_duell_frontend
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mowoe
chaos_familien_duell_frontend
Commits
31b0dbf6
Commit
31b0dbf6
authored
6 years ago
by
Leonhard Strohmidel
Browse files
Options
Downloads
Patches
Plain Diff
+experimental evaluation
parent
ce87a664
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
evaluation.py
+83
-0
83 additions, 0 deletions
evaluation.py
with
83 additions
and
0 deletions
evaluation.py
0 → 100644
+
83
−
0
View file @
31b0dbf6
from
model
import
*
from
peewee
import
fn
import
json
punctuation
=
[
'
!
'
,
'
?
'
,
'
.
'
,
'
,
'
,
'
;
'
,
'
:
'
,
'
-
'
,
'
_
'
,
'"'
,
"'"
,
'
…
'
,
'
—
'
,
'
#
'
,
'
@
'
]
semantic
=
[
'
e.v.
'
,
'
ev
'
,
'
ev.
'
,
'
e.v
'
,
'
herr
'
,
'
hr
'
,
'
frau
'
,
'
fr
'
,
'
ag
'
,
'
gmbh
'
,
'
& co kg
'
]
def
remove_punctuation
(
text
):
for
char
in
punctuation
:
text
=
text
.
replace
(
char
,
"
"
)
return
text
def
remove_semantics
(
text
):
for
char
in
semantic
:
text
=
text
.
replace
(
char
,
"
"
)
return
text
def
replace_umlautes
(
text
):
text
=
text
.
replace
(
"
oe
"
,
"
ö
"
)
text
=
text
.
replace
(
"
ß
"
,
"
ss
"
)
text
=
text
.
replace
(
"
ae
"
,
"
ä
"
)
text
=
text
.
replace
(
"
ue
"
,
"
ü
"
)
return
text
def
normalize_text
(
text
):
text
=
replace_umlautes
(
text
)
text
=
remove_punctuation
(
text
)
text
=
text
.
lower
()
splitted
=
text
.
split
(
"
"
)
temp
=
""
for
splinter
in
splitted
:
if
len
(
splinter
)
>
0
:
temp
+=
splinter
+
"
"
text
=
temp
.
strip
()
return
text
def
normalize_answers
():
answers
=
Answer
.
select
()
for
answer
in
answers
:
text
=
answer
.
text
text
=
normalize_text
(
text
)
answer
.
text
=
text
answer
.
save
()
def
get_answer_groups_for_question
(
question
):
return
Answer
.
select
().
group_by
(
Answer
.
text
).
where
(
Answer
.
question
==
question
)
def
update_answer_text_batch
(
updates
=
[(
""
,
""
)]):
for
u
in
updates
:
update_answer_text
(
u
[
0
],
u
[
1
])
def
update_answer_text
(
old
,
new
):
answers
=
Answer
.
select
().
where
(
Answer
.
text
==
old
)
for
a
in
answers
:
a
.
text
=
new
a
.
save
()
def
update_answer_from_file
():
with
open
(
"
answer_update.json
"
,
"
r
"
)
as
file
:
jzon
=
json
.
load
(
file
)
update_answer_text_batch
(
jzon
)
def
generate_answer_classes
():
def
aggregate_answer_file
():
questions
=
Question
.
select
()
for
q
in
questions
:
answer_list
=
[]
answers
=
get_answer_groups_for_question
(
q
)
for
a
in
answers
:
count
=
Answer
.
select
(
fn
.
count
(
Answer
.
id
)).
where
(
Answer
.
text
==
a
.
text
).
scalar
()
count
=
int
(
count
)
answer_list
.
append
((
count
,
a
.
text
))
answer_list
=
sorted
(
answer_list
,
key
=
lambda
answer
:
answer
[
0
])
answer_dict
=
{
"
question
"
:
q
.
text
,
"
answers
"
:
answer_list
}
with
open
(
"
q%d.json
"
%
q
.
id
,
"
w
"
)
as
file
:
json
.
dump
(
answer_dict
,
file
,
indent
=
4
,
sort_keys
=
True
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment