-
Notifications
You must be signed in to change notification settings - Fork 1
/
invertdictionary.old.py
55 lines (50 loc) · 1.33 KB
/
invertdictionary.old.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
import re
class Entry():
def __init__(self,a):
for l in a:
l = l.strip()
if l.endswith('%'):
l = l[:-1]
if r'\glosses' in l:
self.gloss = l[9:-1]
if r'\citationform' in l:
try:
self.vernaculars.append(l)
except AttributeError:
self.vernaculars = [l]
continue
if l.strip().startswith(r'\pos'):
try:
self.poss.append(l)
except AttributeError:
self.poss = [l]
continue
d = {}
entries = open('chapters/dictionary.tex').read().split('%------------------------------')
for e in entries[1:]:
#print e
a = e.split('\n')[1:]
x = Entry(a)
try:
for g in x.gloss.split(';'):
try:
d[g.strip()].append(x)
except KeyError:
d[g.strip()] = [x]
except AttributeError:
s = "%% no gloss for %s" % x.vernaculars
print(s)
except AttributeError:
continue
for k in sorted(d.keys(),key=lambda s: s.strip().lower()):
print('%'+30*'-')
print('\\newentry')
print('\\lsgloss{%s}' % k.strip())
out = []
for e in d[k]:
try:
out.append(''.join(['~'.join(l)
for l in zip(e.vernaculars,e.poss)]))
except AttributeError:
print("%%insufficient information for %s" % k)
print(';\n'.join(out))