-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathaccent.py
140 lines (134 loc) · 5.48 KB
/
accent.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import re
from greek_accentuation.characters import accent, strip_length
from greek_accentuation.characters import strip_accents # noqa
from greek_accentuation.syllabify import rebreath
from greek_accentuation.syllabify import debreath # noqa
from greek_accentuation.accentuation import (
recessive, persistent, on_penult, make_oxytone)
def clean(w):
return rebreath(w).replace("|", "").replace("-", "")
def calculate_accent(w, parse, lemma, segmented_lemma, stem, inflexion,
accent_override):
if accent(w):
# explicit
return clean(w), "explicit"
elif list(stem)[0].endswith("{enclitic}"):
# enclitic
return clean(make_oxytone(w)), "enclitic"
elif len(parse) == 3 and parse[2] != "N": # nominal
base_accent = None
for key_regex, accented in accent_override.get(lemma, []):
if re.match(key_regex, parse):
base_accent = accented
break
if base_accent:
return (
clean(persistent(w, base_accent)),
"nominal: persistent from override {}".format(base_accent)
)
else:
return (
clean(persistent(w, lemma)),
"nominal: persistent from lemma"
)
else:
if parse[2] == "P":
base_accent = None
for key_regex, accented in accent_override.get(lemma, []):
if re.match(key_regex, parse):
base_accent = accented
break
if base_accent:
return (
clean(persistent(w, base_accent)),
f"participle: persistent from override {base_accent}"
)
elif parse == "AAP.NSM" and w.endswith("ων"):
return (
clean(make_oxytone(w)),
"participle: AAP.NSM -ων oxytone"
)
elif parse == "PAP.NSM" and w.endswith("ς"):
return (
clean(make_oxytone(w)),
"participle: PAP.NSM -ς oxtyone"
)
elif parse[0:3] == "AAP" and parse != "AAP.NSM":
# calculate NSM
nsms = [
calculate_accent(
w, "AAP.NSM", lemma, segmented_lemma, stem, inflexion,
accent_override
) for w in inflexion.generate(lemma, "AAP.NSM")
]
for nsm, _ in nsms:
if nsm.endswith(("ών", "ούς")):
# persistent participle (based on nsm)
return (
clean(persistent(w, nsm, default_short=True)),
f"participle: AAP persistent from NSM {nsm}"
)
else:
# persistent participle (based on lemma)
if "-" in w:
pre, rest = w.split("-")
lemma_pre, lemma_rest = segmented_lemma.split("-")
return (
clean(
pre + persistent(
rest, lemma_rest, default_short=True)),
"participle: AAP persistent"
" from lemma (using segmentation)"
)
else:
return (
clean(
persistent(w, lemma, default_short=True)),
"participle: AAP persistent from lemma"
)
elif parse[0:3] == "PAP" and parse != "PAP.NSM":
# calculate NSM
nsms = [
calculate_accent(
w, "PAP.NSM", lemma, segmented_lemma, stem, inflexion,
accent_override
) for w in inflexion.generate(lemma, "PAP.NSM")
]
for nsm, _ in nsms:
nsm = strip_length(nsm)
return (
clean(persistent(w, nsm, default_short=True)),
f"participle: PAP persistent from NSM {nsm}"
)
else:
return (
clean(recessive(w, default_short=True)),
"participle: recessive"
)
elif parse[0:3] in ["AAN", "XAN", "XMN", "XPN"]:
return (
clean(on_penult(w, default_short=True)),
"infinitive: AAN XAN XMN XPN penult"
)
elif parse[0:3] == "PAN" and stem.endswith("{athematic}"):
return (
clean(on_penult(w, default_short=True)),
"infinitive: PAN athematic penult"
)
elif parse[0:3] == "AMN" and stem.endswith(
("{root}", "{athematic}", "{2nd}")):
return (
clean(on_penult(w, default_short=True)),
"infinitive: AMN root/2nd penult"
)
elif parse[2] == "O":
return (
clean(recessive(
w, treat_final_AI_OI_short=False, default_short=True)),
"optative: recessive"
)
else:
return (
clean(recessive(w, default_short=True)),
"recessive (default)"
)