/
parse.py
executable file
·60 lines (45 loc) · 2.01 KB
/
parse.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
60
import random
import nltk
from providedcode import dataset
from providedcode.transitionparser import TransitionParser
from providedcode.evaluate import DependencyEvaluator
from providedcode.dependencygraph import DependencyGraph
from featureextractor import FeatureExtractor
from transition import Transition
import sys
if __name__ == '__main__':
try:
model = sys.argv[1]
tp = TransitionParser.load(model)
for line in sys.stdin:
# temp = line.strip()
# temp = str(temp)
# parsing arbitrary sentences (english):
# print "[" + temp + "]"
temp = line
# temp = "Hi, this is a test."
sentence = DependencyGraph.from_sentence(temp)
for key, dct in sentence.nodes.items():
dct['ctag'] = nltk.tag.mapping.map_tag("en-ptb", "universal", dct['ctag'])
parsed = tp.parse([sentence])
print parsed[0].to_conll(10).encode('utf-8')
except NotImplementedError:
print """
This file is currently broken! We removed the implementation of Transition
(in transition.py), which tells the transitionparser how to go from one
Configuration to another Configuration. This is an essential part of the
arc-eager dependency parsing algorithm, so you should probably fix that :)
The algorithm is described in great detail here:
http://aclweb.org/anthology//C/C12/C12-1059.pdf
We also haven't actually implemented most of the features for for the
support vector machine (in featureextractor.py), so as you might expect the
evaluator is going to give you somewhat bad results...
Your output should look something like this:
LAS: 0.23023302131
UAS: 0.125273849831
Not this:
Traceback (most recent call last):
File "test.py", line 41, in <module>
...
NotImplementedError: Please implement shift!
"""