@@ -42,11 +42,15 @@ def parse_parser_results(text):
42
42
raise Exception ("Parse error. Could not find [Text=" )
43
43
tmp ['words' ] = {}
44
44
exp = re .compile ('\[([a-zA-Z0-9=. ]+)\]' )
45
- m = exp .findall (line )
46
- for s in m :
47
- av = re .split ("=| " , s ) # attribute-value tuples
48
- tmp ['words' ][av [1 ]] = dict (zip (* [av [2 :][x ::2 ] for x in (0 , 1 )]))
49
- print tmp
45
+ matches = exp .findall (line )
46
+ for s in matches :
47
+ # split into attribute-value list
48
+ av = re .split ("=| " , s )
49
+ # make [ignore,ignore,a,b,c,d] into [[a,b],[c,d]]
50
+ av = zip (* [av [2 :][x ::2 ] for x in (0 , 1 )])
51
+ # save as attr-value dict, convert numbers into ints
52
+ tmp ['words' ][av [1 ]] = dict (map (lambda x : (x [0 ], x .isdigit (x [1 ])
53
+ and int (x [1 ]) or x [1 ]), av ))
50
54
state = 3
51
55
elif state == 3 :
52
56
# skip over parse tree
@@ -60,7 +64,7 @@ def parse_parser_results(text):
60
64
split_entry = re .split ("\(|, " , line [:- 1 ])
61
65
if len (split_entry ) == 3 :
62
66
rel , left , right = map (lambda x : remove_id (x ), split_entry )
63
- tmp ['tuples' ].append ((rel ,left ,right ))
67
+ tmp ['tuples' ].append (tuple (rel ,left ,right ))
64
68
print "\n " , rel , left , right
65
69
elif "Coreference links" in line :
66
70
state = 5
0 commit comments