forked from jderuiter/statelearner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleaner.py
41 lines (35 loc) · 1.44 KB
/
cleaner.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
import sys, os
if __name__ == '__main__':
extra = []
with open(sys.argv[1]) as f:
comb2 = {}
for line in f:
if "->" in line and "/ -\"" not in line and "__" not in line and "BRD" not in line:
quote = line.find("\"")+1
quote2 = line.find("\"", quote)
responseStart = line.find("/")
responseEnd = quote2
transition = line[:quote]
transitionOutput = transition, line[responseStart:responseEnd]
labelInput = line[quote:responseStart] + line[responseStart:responseEnd]
if transitionOutput in comb2:
comb2[transitionOutput] = comb2[transitionOutput] + labelInput + "\\n"
else:
comb2[transitionOutput] = labelInput + "\\n"
else:
extra.append(line)
f.close()
# label = line[quote:quote2]
# if transition in comb:
# comb[transition] = comb[transition] + "\\n" + label
# else:
# comb[transition] = label
with open("stripped"+sys.argv[1], "w") as w:
for x in extra:
if "}" not in x and "/ -\"" not in x:
w.write(x)
for trans in comb2:
x = '' + trans[0] + comb2[trans] + "\"];\n"
w.write(x)
w.write("}")
os.system("dot -Tpdf -O " + "stripped"+sys.argv[1])