-
Notifications
You must be signed in to change notification settings - Fork 12
/
generate_homer_lexicon.py
executable file
·89 lines (77 loc) · 2.81 KB
/
generate_homer_lexicon.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
from collections import defaultdict
from accent import strip_length
from greek_inflexion import GreekInflexion
from homer_utils import key_to_part, trim_multiples
ginflexion = GreekInflexion(
"stemming.yaml", "STEM_DATA/homer_lexicon.yaml"
)
STEM_GUESSES = defaultdict(lambda: defaultdict(set))
with open("homer-data/verbs.tsv") as f:
for row in f:
lemma, key, form = row.strip().split("\t")
tags = set([
"fixed-final-nu-aai.3s",
"no-final-nu-aai.3s",
"no-final-nu-aao.3s",
"no-final-nu-fai.3p",
"no-final-nu-pai.3p",
"no-final-nu-iai.3s",
"no-final-nu-xai.3s",
"no-final-nu-xai.3p",
"no-final-nu-yai.3s",
"no-final-nu-aps.3p",
"no-final-nu-pai.3s",
"no-final-nu-aas.3p",
"no-final-nu-xas.3p",
"no-sigma-loss-imi.2s",
"alt-apo-pl",
"Homer",
])
c = form.count("/") + 1
stem = ginflexion.find_stems(lemma, key, tags)
generated = ginflexion.generate(lemma, key, tags)
if stem:
stem_guess = None
else:
stem_guess = [
stem for key, stem in
ginflexion.possible_stems2(form, "^" + key + "$")]
if [strip_length(w) for w in sorted(generated)] == \
[strip_length(w) for w in sorted(form.split("/"))]:
correct = "✓"
else:
correct = "✕"
if correct == "✕":
if stem_guess:
STEM_GUESSES[lemma][key_to_part(key)].add(
frozenset(stem_guess))
for lemma, parts in sorted(STEM_GUESSES.items()):
printed = False
for part, stem_sets in sorted(
parts.items(), key=lambda x: (x[0][0], {"-": 0, "+": 1}[x[0][1]])):
stem = set.intersection(*(set(s) for s in stem_sets))
if len(stem) == 0:
if False:
if not printed:
print()
print("{}:".format(lemma))
print(" stems:".format(lemma))
printed = True
print(" {}: {} # @0".format(part, stem_sets))
elif len(stem) == 1:
if not printed:
print()
print("{}:".format(lemma))
print(" stems:".format(lemma))
printed = True
print(" {}: {} # @1".format(part, stem.pop()))
else:
if True:
if not printed:
print()
print("{}:".format(lemma))
print(" stems:".format(lemma))
printed = True
print(" {}: {}".format(part, trim_multiples(
stem, part, lemma, parts)))