-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpure_python_glossing.py
More file actions
53 lines (45 loc) · 2.24 KB
/
pure_python_glossing.py
File metadata and controls
53 lines (45 loc) · 2.24 KB
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
import regex
def mk_glossing_dict(*strings):
gd = {}
for s in strings:
chunked = s.split("\t")
if chunked[0] not in gd: gd[chunked[0]] = chunked[1]
#else: gd[chunked[0]] = gd[chunked[0]] + " HOMOPHONE DEFINITION>" + chunked[1]
else: gd[chunked[0]] = gd[chunked[0]] + "/" + chunked[1]
return gd
def retrieve_glosses(*lemmata, **gloss_dict):
tinies = []
for l in lemmata:
try: gloss = gloss_dict[l]
except KeyError:
if "+" in l:
gloss = "-".join(retrieve_glosses(*l.split("+"), **gloss_dict, ))
else: gloss = "?"
tinies.append(gloss)
return tinies
def wrap_glosses(*glosses):
return ["'"+g+"'" for g in glosses]
def wrap_nod_entry_url(*lemmata, **nishIDdict):
h = []
#gotta split up the complex lemmata somehow
for l in lemmata:
tot = []
#if '+' in l: tot.append(l)
cmpd = l.split("+") #this can't do what is intended (split the IDs of conjuncts), and it is crashes when the word is not found in the dictionary
for c in cmpd:
#else:
#cmpd = regex.split("(?<=n)-(?=n)", nishIDdict[l]) #this can't do what is intended (split the IDs of conjuncts), and it is crashes when the word is not found in the dictionary
#for c in cmpd:
try:
alts = regex.split("(?<=n)/(?=n)", nishIDdict[c])
for i in range(len(alts)):
if i == 0:
tot.append('<a href='+"'https://dictionary.nishnaabemwin.atlas-ling.ca/#/entry/{0}' target='_blank' rel='noopener noreferrer'>{1}</a>".format(alts[i], c))
else: tot.append('<a href='+"'https://dictionary.nishnaabemwin.atlas-ling.ca/#/entry/{0}' target='_blank' rel='noopener noreferrer'>(alt {1})</a>".format(alts[i], str(i)))
except KeyError: tot.append(c)
h.append(" ".join(tot))
return h
#return ['<a href="https://dictionary.nishnaabemwin.atlas-ling.ca/#/entry/'+ln[1]+'">'+ln[0]+'</a>' for ln in lemmataAndNishIDs]
def undo_html(string):
return regex.sub('&\#x27;', "'", regex.sub('<', '<', regex.sub('>', '>', string)))
#return regex.sub('"', '', regex.sub('<', '<', regex.sub('>', '>', string)))