-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_generation.py
31 lines (23 loc) · 1.09 KB
/
test_generation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from characters import strip_length
import yaml
from utils import Counter
from verbs import Lexicon
def test_generation(test_file, lexicon_file):
lexicon = Lexicon(lexicon_file)
counter = Counter()
with open(test_file) as f:
for test in yaml.load(f):
lemma = test.pop("lemma")
location = test.pop("location", "")
for parse, form in test.items():
predicted = lexicon.generate(lemma, parse, context=location)
if predicted is None:
counter.fail("didn't know how to work out {} {} {}".format(lemma, parse, form))
elif strip_length(form) == strip_length(predicted):
counter.success()
continue
elif strip_length(form) not in [strip_length(p) for p in predicted.split("/")]:
counter.fail("{} {} got {} instead of {} in {}".format(lemma, parse, predicted, form, location))
else:
counter.skip("{} {} {} {} {}".format(lemma, parse, form, predicted, location))
counter.results()