forked from langsci/259
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixindex.py
49 lines (36 loc) · 816 Bytes
/
fixindex.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
# -*- coding: utf-8 -*-
import re
from helpers import INITD, REPLACEMENTS
orig = ''
trans = ''
for k in INITD:
s = INITD[k]
for c in s:
orig+=c
trans+=k
transtable = str.maketrans(orig, trans)
p = re.compile(r"\\indexentry \{(.*)\|(\(?hyperpage|\)|infn)")
def process(s):
if s.strip()=='':
return s
m = p.match(s)
o = ''
try:
o = m.groups(1)[0]
except AttributeError:
print(repr(s))
t = o.translate(transtable)
for r in REPLACEMENTS:
t = t.replace(r[0],r[1])
if t == o:
return s
else:
return s.replace(o,"%s@%s"%(t,o))
if __name__ == '__main__':
fn = 'main.adx'
lines = open(fn).readlines()
print(len(lines))
lines2 = list(map(process, lines))
out = open('mainmod.adx','w')
out.write(''.join(lines2))
out.close()