-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
169 lines (160 loc) · 3.85 KB
/
common.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import re
FIN_NUM_CLASSES = {
"yksikkö": 0,
"monikko": 1,
}
FIN_NUM_CLASSES_UDEP = {
"Sing": 0,
"Plur": 1,
}
FIN_NUM_CLASSES_UNIMORPH = {
"SG": 0,
"PL": 1,
}
FIN_PERSON_CLASSES = {
"1. persoonan yksikkö": 0,
"2. persoonan yksikkö": 1,
"1. persoonan monikko": 2,
"2. persoonan monikko": 3,
"3. persoona": 4,
}
FIN_PERSON_CLASSES_UDEP = {
"Sing1": 0,
"Sing2": 1,
"Plur1": 2,
"Plur2": 3,
"3": 4,
}
FIN_PERSON_CLASSES_UNIMORPH = {
"SG1": 0,
"SG2": 1,
"PL1": 2,
"PL2": 3,
"3": 4,
}
FIN_CASE_CLASSES = {
"abessiiivi": 0,
"ablatiivi": 1,
"adessiivi": 2,
"allatiivi": 3,
"elatiivi": 4,
"essiivi": 5,
"genetiivi": 6,
"illatiivi": 7,
"inessiivi": 8,
"instruktiivi": 9,
"nominatiivi": 10,
"partitiivi": 11,
"translatiivi": 12,
"komitatiivi": 13,
}
FIN_CASE_CLASSES_UDEP = {
"Abe": 0,
"Abl": 1,
"Ade": 2,
"All": 3,
"Ela": 4,
"Ess": 5,
"Gen": 6,
"Ill": 7,
"Ine": 8,
"Ins": 9,
"Nom": 10,
"Par": 11,
"Tra": 12,
"Com": 13,
}
FIN_CASE_CLASSES_UNIMORPH = {s.upper(): i for s, i in FIN_CASE_CLASSES_UDEP.items()}
FIN_FEATS_CLASSES = {
"number": {**FIN_NUM_CLASSES_UDEP, **FIN_NUM_CLASSES_UNIMORPH, **FIN_NUM_CLASSES},
"person": {**FIN_PERSON_CLASSES_UDEP, **FIN_PERSON_CLASSES_UNIMORPH, **FIN_PERSON_CLASSES},
"case": {**FIN_CASE_CLASSES_UDEP, **FIN_CASE_CLASSES_UNIMORPH, **FIN_CASE_CLASSES},
}
NUM_LABELS = {
"yksikkö": "SG",
"monikko": "PL",
"Sing": "SG",
"Plur": "PL",
"SG": "SG",
"PL": "PL",
"other": "other",
}
PERSON_LABELS = {
"yksikön ensimmäinen persoona": "SG1",
"yksikön toinen persoona": "SG2",
"yksikön kolmas persoona": "3",
"monikon ensimmäinen persoona": "PL1",
"monikon toinen persoona": "PL2",
"monikon kolmas persoona": "3",
"kolmas persoona": "3",
"1. persoonan yksikkö": "SG1",
"2. persoonan yksikkö": "SG2",
"1. persoonan monikko": "PL1",
"2. persoonan monikko": "PL2",
"3. persoona": "3",
"3. persoonan yksikkö": "3",
"3. persoonan monikko": "3",
"Sing1": "SG1",
"Sing2": "SG2",
"Plur1": "PL1",
"Plur2": "PL2",
"3": "3",
"other": "other",
"1. persoonan yksikön omistusliite": "SG1",
"2. persoonan yksikön omistusliite": "SG2",
"3. persoonan yksikön omistusliite": "3",
"1. persoonan monikon omistusliite": "PL1",
"2. persoonan monikon omistusliite": "PL2",
"3. persoonan monikon omistusliite": "3",
"ensimmäisen persoonan yksikkö": "SG1",
"toisen persoonan yksikkö": "SG2",
"kolmannen persoonan yksikkö": "3",
"ensimmäisen persoonan monikko": "PL1",
"toisen persoonan monikko": "PL2",
"kolmannen persoonan monikko": "3",
}
CASE_LABELS = {
"abessiivi": "ABE",
"ablatiivi": "ABL",
"adessiivi": "ADE",
"allatiivi": "ALL",
"elatiivi": "ELA",
"essiivi": "ESS",
"genetiivi": "GEN",
"illatiivi": "ILL",
"inessiivi": "INE",
"instruktiivi": "other", # "INS",
"nominatiivi": "NOM",
"partitiivi": "PAR",
"translatiivi": "TRA",
"komitatiivi": "other", # "COM",
"Abe": "ABE",
"Abl": "ABL",
"Ade": "ADE",
"All": "ALL",
"Ela": "ELA",
"Ess": "ESS",
"Gen": "GEN",
"Ill": "ILL",
"Ine": "INE",
"Ins": "other", #"INS",
"Nom": "NOM",
"Par": "PAR",
"Tra": "TRA",
"Com": "other", #"COM",
"other": "other",
}
def parse_omorstring(omorstring):
"""Parse the omorstring and return the classes."""
regex2key = {
"NUM=": "number",
"POSS=": "person",
"CASE=": "case",
"WORD_ID=": "lemma",
"UPOS=": "upos",
}
classes = {}
for key, value in regex2key.items():
if key in omorstring:
classes[value] = re.search(rf'(?<={key}).*?(?=])', omorstring).group()
return classes