-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathusing_predpatt.py
59 lines (45 loc) · 1.89 KB
/
using_predpatt.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
"""
Example of programmatic PredPatt usage.
"""
# Run PredPatt on sentence
from predpatt import PredPatt
sentence = 'Chris loves silly dogs and clever cats .'
P = PredPatt.from_sentence(sentence)
# Pretty-print output
print P.pprint(track_rule=True, color=True)
print '______________________________________________________________________________'
# A deeper look into PredPatt's internal representations.
#
# Each extraction is kept in a list called instances. Below we will loop through
# each instance and print it's arguments.
for x in P.instances:
print
print x, x.phrase()
for a in x.arguments:
print ' ', a, a.phrase()
# Uncomment to list rules which fired on this proposition. Along with
# an explanation.
#for r in a.rules:
# print ' %s: %s' % (r, r.explain())
print '______________________________________________________________________________'
print
# To change certain behaviors, you can pass different options for the PredPatt
# instance. For example, to disable expansion of conjunctions and extraction of
# amods, use the following:
from predpatt import PredPattOpts
P = PredPatt.from_sentence(sentence, opts=PredPattOpts(resolve_amod=0, resolve_conj=0))
print P.pprint(color=1)
print '______________________________________________________________________________'
print
#______________________________________________________________________________
# Bonus material
# Already have a constituency parse? No problem!
P = PredPatt.from_constituency('( (S (NP (NNP Chris)) (VP (VBZ loves) (NP (NNP Pat))) (. .)) )')
print P.pprint(track_rule=True, color=True)
print '______________________________________________________________________________'
print
# Using PredPatt's Parser interface
from predpatt import Parser
parser = Parser.get_instance() # Create UD parser instance
parse = parser(sentence) # Parse sentence
print parse.pprint()