-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdp2dot.py
More file actions
executable file
·27 lines (23 loc) · 802 Bytes
/
dp2dot.py
File metadata and controls
executable file
·27 lines (23 loc) · 802 Bytes
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
#!/usr/bin/env python
import argparse
import fileinput
def main():
parser = argparse.ArgumentParser('Translates a DP into a DOT graph')
parser.add_argument('dp_file')
args = parser.parse_args()
i = 0
for l in fileinput.input(args.dp_file):
if l == '<s>\n':
print "digraph sentence_{0} {{".format(i)
label = ""
elif l == '</s>\n':
print 'label = "{0}"'.format(label.strip())
print '}'
i+=1
elif not l.startswith("<"):
word,lemma,pos,id,dep_id,dep_tag = l.split()
label = label + " " + word
print 'n_{0}[label="{1}"];'.format(id, word+"/"+pos)
print 'n_{0} -> n_{1} [label="{2}"];'.format(id, dep_id, dep_tag)
if __name__ == '__main__':
main()