forked from Peshowe/converter-web-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_vocabs.py
152 lines (139 loc) · 3.84 KB
/
process_vocabs.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
"""Read in and define the word lists that help when coverting
"""
import pandas as pd
from pathlib import Path
import os
FILE_DIR = os.path.dirname(os.path.realpath(__file__))
STATIC_DIR = os.path.join(FILE_DIR, "static/converter")
STATIC_DIR = Path(STATIC_DIR)
nouns_in_te = pd.read_csv(
Path(f"{STATIC_DIR}/word_lists/nouns_in_te.txt"), sep="\n", header=None
)[0].values
verbs_te = pd.read_csv(
Path(f"{STATIC_DIR}/word_lists/verbs-te.txt"), sep="\n", header=None
)[0].values
verbs_homonyms = pd.read_csv(
f"{STATIC_DIR}/word_lists/verbs_only_homonyms.txt", sep="\n", header=None
)
softEndingMasculine = set(
pd.read_csv(
Path(f"{STATIC_DIR}/word_lists/masculine_soft_ending.txt"),
sep="\n",
header=None,
)[0].values
)
softEndingFeminine = set(
pd.read_csv(
Path(f"{STATIC_DIR}/word_lists/feminine_soft_ending.txt"), sep="\n", header=None
)[0].values
)
yatRoots = set(
pd.read_csv(f"{STATIC_DIR}/word_lists/yatRoots.txt", sep="\n", header=None)[
0
].values
)
yatExcl = set(
pd.read_csv(f"{STATIC_DIR}/word_lists/yatExclusions.txt", sep="\n", header=None)[
0
].values
)
usRoots = set(
pd.read_csv(f"{STATIC_DIR}/word_lists/usRoots.txt", sep="\n", header=None)[0].values
)
usExcl = set(
pd.read_csv(f"{STATIC_DIR}/word_lists/usExclusions.txt", sep="\n", header=None)[
0
].values
)
abbreviations = set(
pd.read_csv(f"{STATIC_DIR}/word_lists/abbreviations.txt", sep="\n", header=None)[
0
].values
)
# these ending in "-те" could be verbs or non-verbs
verbsHomonymsTe = set(
verbs_homonyms[verbs_homonyms[0].apply(lambda x: x.endswith("те"))][0].values
)
# these ending in "-те" are always verbs
yatNotTe = (set(nouns_in_te).union(set(verbs_te))).difference(verbsHomonymsTe)
softEndingWords = softEndingMasculine.union(softEndingFeminine)
cons = {
"б",
"в",
"г",
"д",
"ж",
"з",
"к",
"л",
"м",
"н",
"п",
"р",
"с",
"т",
"ф",
"х",
"ц",
"ч",
"ш",
"щ",
}
vowels = {"а", "ъ", "о", "у", "е", "и", "ѣ", "ѫ"}
no_succeeding_yat = vowels.union(
{"ч", "ш", "ж", "г", "к", "х"}
) # letters after which we can't have a yat vowel
expandedVS = {"във", "със"}
usHomographs = {"кът", "път", "прът"}
usSecondVowel = {"гълъб", "жълъд"}
yatFullExclusions = {"сте", "вещ", "лев", "лева", "свет", "нея", "бей", "бея", "беят"}
yatFullWords = {
"ляв",
"лява",
"лявата",
"бях",
"бяха",
"бяхме",
"вежда",
"вежди",
"веждата",
"веждитѣ",
"де",
"бе",
"дето",
"утре",
"таме",
}
yatDoubleRoots = {
"бележ",
"белез",
"белег",
"белех",
"белел",
"беляз",
"белял",
"белях",
"предмет",
"донейде",
"колене",
}
yatPrefixes = {"пре", "две", "ня", "нався"}
yatSuffixes = {"еше", "еха"}
feminineTheEndings = {"тта", "щта"}
exclusionWords = {
("въстава", "възстава"),
("въстан", "възстан"),
("нишк", "нищк"),
("нужни", "нуждни"),
("овошк", "овощк"),
("празник", "праздник"),
("празнич", "празднич"),
("сърц", "сърдц"),
("сърчи", "сърдчи"),
}
usNotExcl = {"откъсн"}
noYatVerbs = {"клех", "взех", "клях", "взях"}
# read in the most frequently used words in the Bulgarian language (scraped from a set of various literature books)
freq_df = pd.read_csv(f"{STATIC_DIR}/word_lists/most_freq.txt", sep="\t", header=None)
freq_df.rename(columns={0: "freq", 1: "word"}, inplace=True)
freq_df = freq_df[~freq_df["word"].isin(verbsHomonymsTe)]