-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_bxd.py
59 lines (54 loc) · 2.1 KB
/
convert_bxd.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
import argparse
import re
parser = argparse.ArgumentParser(description='Whatever...')
parser.add_argument('-i', metavar='BXD-FILE', type=str,
help='input bxd file')
parser.add_argument('-o', metavar='TXT-FILE', type=str,
help='input txt file')
args = parser.parse_args()
skip = 3
with open(args.o, 'w') as out:
with open(args.i, 'r') as dic:
line = dic.readline()
while line:
if skip == 2:
m = re.match('Delimiter=(.)', line)
dmt = m.group(1)
if skip <= 0:
voc = line.replace('\n', '').split(dmt)
if int(voc[4]) == 1:
voc[8] = re.sub(r'\$(\d+)', r'\\g<\1>', voc[8])
else:
voc[7] = re.sub(r'(\)|\(|\.|\?|\+)', r'\\\1', voc[7])
voc[8] = re.sub(r'\(', r'\(', voc[8])
voc[8] = re.sub(r'\)', r'\)', voc[8])
newLine = voc[7] + '/s/' + voc[8] + '/s/'
voc[5] = int(voc[5])
if voc[5] == 0:
if (not re.match(r'\w', voc[7][0])) & (int(voc[6]) == 0):
voc[5] += 2
if (not re.match(r'\w', voc[7][-1])) & (int(voc[6]) == 0):
voc[5] += 1
if voc[5] == 0:
newLine += 'b/s/'
if voc[5] == 1:
if (not re.match(r'\w', voc[7][0])) & (int(voc[6]) == 0):
voc[5] += 2
else:
newLine += 'l/s/'
if voc[5] == 2:
if (not re.match(r'\w', voc[7][-1])) & (int(voc[6]) == 0):
voc[5] += 1
else:
newLine += 'r/s/'
if voc[5] == 3:
newLine += 'n/s/'
newLine += voc[3] + '\n'
out.write(newLine)
if int(voc[6] == 1):
print(skip)
skip -= 1
line = dic.readline()
dic.close()
out.close()
print('Done. ' + str(-skip + 1) + ' lines parsed.')