-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_roots.py
408 lines (333 loc) · 11.1 KB
/
get_roots.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
import add_path
from general import *
import random
from global_hiero import *
from mine_tle import tle_entry
import hieroglyphs as hi
from hieroglyphs import vocab_tester, temp_word, print_entries, other_tests
from collections import deque
class classify_words:
def __init__(self):
self.tle_dct = pi.open_pickle("tle_dct6", 'hi')
def is_unknown(self):
if reg(r'^-\.+-$', self.word):
self.unknown.append(self.word)
def split_infixes(words_in_sent, rejoin=False):
e = 0
while e < len(words_in_sent):
word = words_in_sent[e]
word = re.sub(r'[\(\)]', "", word)
if "-" in word and "." in word:
idx1 = word.rindex('-')
idx2 = word.rindex('.')
if idx1 < idx2:
pre_word = word[:idx1]
pre_word = pre_word.replace('.', ',')
post_word = word[idx1:]
word = pre_word + post_word
if word.startswith('j.'):
stem = word[2:]
words_in_sent[e] = 'j.'
e += 1
words_in_sent.insert(e, stem)
elif '.' in word:
lst = word.split('.')
lst[0] = lst[0].replace(',', '.')
words_in_sent[e] = lst[0]
e += 1
for x in lst[1:]:
words_in_sent.insert(e, "." + x)
e += 1
else:
e += 1
if not rejoin:
return ' '.join(words_in_sent)
else:
return words_in_sent
def get_new_mil_lem(dct_cls, tle_dct, w2a):
for x, y in tle_dct.items():
if int(y.lemma_no) > 999_999:
w2a.append(y.word)
return
def add_lemmas2vocab():
dct_cls = pi.open_pickle('dictionary', 'hi')
tle_dct = pi.open_pickle('tle_dct6', 'hi')
pro_spell = hi.get_pro_spell(tle_dct)
redun_tle = pi.open_pickle("redun_tle", 'hi')
for word, lemmas in pro_spell.items():
full_def = []
for lemma in lemmas:
lemma = redun_tle.get(lemma, lemma)
entry = tle_dct[lemma]
pos = entry.pos
eng = entry.eng_word
lst1 = [lemma, pos, entry.rank, eng]
full_def.append(lst1)
ins = tle_entry()
ins.word = word
ins.eng_word = full_def
ins.lemma_no = lemmas
ins.nxt_tst = time.time()
dct_cls[word] = ins
pi.save_pickle(dct_cls, 'dictionary', 'hi')
return
def reduce2root2(word, sentence, dct_cls):
suff_dct2 = {
'wt': ['wt', 't', ''],
'ww': ['w'],
'tjt': ['t'],
'yt': ['t'],
'j': ['j', ''],
'tj': ['tj'],
't': ['t', ''],
'w': ['w', ''],
'wj': ['w', ''],
'f': [''],
's': [''],
'n': [''],
'sn': [''],
'st': [''],
'k': [''],
'T': [''],
'Tn': [''],
'tn': [''],
'kw': ['']
}
lst = word.split('-')
for non_com in lst:
if '.' in lst1:
lst1 = non_com.split('.')
suffixes = lst1[1:]
candidates = [lst1[0]]
candidates = list(candidates)
lst1 = []
for lsuffix in suffixes:
lst1 = suff_dct2[lsuffix]
if len(lst1) == 1:
if not lst1[0]:
pass
else:
for candidate in candidates:
candidate.append(lst1[0])
else:
for suffix in lst:
if not suffix:
pass
else:
b = len(suffix)
for c in range(b):
new_cand = jsonc(candidates)
def fix_test_sents():
test_sents = pi.open_pickle('test_sentences', 'hi')
all_words = set()
delete_dot = set()
for cls in test_sents.values():
lst = cls.word.split()
all_words |= set(lst)
lst = [re.sub(r'[\(\)]', "", x) for x in all_words if '.' in x]
one_dot = [x for x in lst if x.count('.') == 1]
pl_dot = [x for x in lst if x.count('.') > 1]
for e, x in en(all_words):
p(f'{e} of {len(all_words)}')
p(x)
str1 = input('remove dot return for no: ')
if str1:
x.add(delete_dot)
to.from_lst2txt(delete_dot, fcdir + 'delete_dot')
class add2vocab:
def main(self, **kwargs):
self.word = kwargs['word']
self.tle_dct = kwargs['tle_dct']
self.dictionary = kwargs['dictionary']
self.sentence = kwargs['sentence']
self.mistake = True
while True:
p(f"""
begin with 1 to go back into root,
2 to not go back in
4 to add new lemma
5 to replace compound with 2 words
""")
self.word = input('spell again, n to move to next sent: ')
while True:
if self.word[0] not in ['1', '2', '3', '4', '5', 'n']:
self.word = input('wrong input')
else:
break
if self.word == 'n':
self.next_sent = True
break
elif self.word[0] == '1':
self.word = self.word[2:]
str3 = self.word
self.word = self.reduce2root(self.word)
if self.word in self.dictionary:
return self.word
else:
p(f'{self.word} is not in your dictionary')
elif self.word[0] == '2':
self.word = self.word[2:]
if self.word in self.dictionary:
return self.word
else:
p(f'{self.word} is not in your dictionary')
elif self.word[0] == '4':
self.handle_new_meanings()
break
elif self.word[0] == '5':
return self.word[2:]
def chop_off_suffix(self):
pass
def get_posssibilities(self):
special_suffixes = ['wt', 't', 'ww', 'w', ]
def reduce2root(self, word):
suff_dct = {
"wt": 't',
"ww": "w",
"tjt": "t",
'yt': 't'
}
repl_w_blank = ['f', 's', 'n', 'sn', 'st', 'k',
'T', 'Tn', 'tn', 'kw', 'y', 'kj', 'kwj',
'nw', 'wjn', 'tjwnj', 'wj', 'wjj', 'tjj',
]
has_diff_repl = ['wj']
keep = []
# keep = ['tj']
sometimes = ['j', 't', 'w', 'wt', 'tj']
second_delete = ['j']
if not "." in word:
return word
elif reg(r'\.[^\-]+\-[^\.]+$', word):
return word
end = word
begin = ""
if '-' in word:
didx = word.rindex(word)
begin = word[:didx + 1]
end = word[didx + 1]
lst = end.split('.')
for e, syl in en(lst[1:]):
repl = suff_dct.get(syl)
if e > 0 and syl in second_delete:
lst[e + 1] = ""
elif syl in sometimes:
p(' ')
p(self.sentence)
p(f'{word} {syl}')
str1 = input('keep? y or no ')
if str1 == 'y':
pass
elif repl:
lst[e + 1] = repl
else:
lst[e + 1] = ""
elif syl in has_diff_repl:
p('')
p(self.sentence)
p(f'input how you want to replace {syl} in {word}')
str1 = input('input: ')
if not str1:
lst[e + 1] = ""
else:
lst[e + 1] = str1
else:
if repl:
lst[e + 1] = repl
elif syl in repl_w_blank:
lst[e + 1] = ""
elif syl in keep:
pass
e = 1
while e < len(lst):
str1 = lst[e]
if not str1:
del lst[e]
else:
e += 1
end = ".".join(lst)
return begin + end
def split_infixes(self):
e = 0
while e < len(self.words_in_sent):
word = self.words_in_sent[e]
word = re.sub(r'[\(\)]', "", word)
self.words_in_sent[e] = word
if word.startswith('j.'):
stem = word[2:]
self.words_in_sent[e] = 'j='
self.words_in_sent.insert(e + 1, stem)
e += 1
return
def handle_new_meanings(self):
self.word = self.word[2:]
self.ins = temp_word()
p(f"""
put in
eng_word | source | pos
""")
str3 = input('input: ')
lst2 = vgf.strip_n_split(str3, "|")
self.ins.word = self.word
self.ins.eng_word = lst2[0]
self.ins.secondary_source = lst2[1]
self.ins.pos = lst2[2]
self.word1 = self.word
self.must_test()
lemma = hi.handle_new_meanings(self.tle_dct, self.ins)
hi.add_single_lemma(self.ins, self.dct_cls, lemma)
class get_top_words:
def __init__(self):
dct_cls = pi.open_pickle('dictionary', 'hi')
tle_dct = pi.open_pickle('tle_dct6', 'hi')
lemma2freq = pi.open_pickle('lemma2freq', 'hi')
ignore_for_now = pi.open_pickle('ignore_for_now', 'hi')
ignore_for_now = set(ignore_for_now)
done_lemmas = set()
for x, y in dct_cls.items():
for lemma in y['lemma_no']:
done_lemmas.add(lemma)
b = 0
new_words = set()
c = 0
lst = []
for x, y in lemma2freq.items():
lemma = tle_dct[x]
c += 1
if x not in ignore_for_now:
pos = lemma.pos
use = False
if pos[0] not in ['p', 'i', 'e', 'r', 'q', 'c', 'm', 'u']:
if "-" in x:
pass
elif pos == 'npa':
use = True
elif pos.startswith('np') or pos in ['jp', 'jn']:
pass
elif len(pos) > 1 and pos[:2] in ['vc']:
pass
else:
use = True
if use:
word = lemma['word']
if "-" not in word and word not in dct_cls \
and "(" not in word:
eng_word = lemma['eng_word']
lst.append([x, pos, word, eng_word])
new_words.add(word)
p(word)
# dc_entry = dct_cls.get(word)
# if dc_entry:
# eng_word = lemma['eng_word']
# p (eng_word)
#
if len(new_words) > 500:
break
pi.save_pickle(new_words, 'temp_lemmas', 'hi')
return
args = vgf.get_arguments()
if 'al' in args:
add_lemmas2vocab()
elif 'fs' in args:
fix_sentences(args)
## fix lacunae bug