File tree Expand file tree Collapse file tree 3 files changed +140
-194
lines changed Expand file tree Collapse file tree 3 files changed +140
-194
lines changed Original file line number Diff line number Diff line change
1
+ * .pyc
2
+ /stanford-corenlp- *
3
+ . * project
4
+
Original file line number Diff line number Diff line change 1
- import jsonrpc
2
- try :
3
- import json
4
- except ImportError :
5
- import simplejson as json
1
+ import json
2
+ from jsonrpc import ServerProxy , JsonRpc20 , TransportTcpIp
3
+ from pprint import pprint
6
4
7
- server = jsonrpc .ServerProxy (jsonrpc .JsonRpc20 (),
8
- jsonrpc .TransportTcpIp (addr = ("127.0.0.1" , 8080 )))
5
+ class StanfordNLP :
6
+ def __init__ (self ):
7
+ self .server = ServerProxy (JsonRpc20 (),
8
+ TransportTcpIp (addr = ("127.0.0.1" , 8080 )))
9
+
10
+ def parse (self , text ):
11
+ return json .loads (self .server .parse (text ))
9
12
10
- # call a remote-procedure
11
- result = json . loads ( server . parse ("hello world" ) )
12
- print "Result" , result
13
+ nlp = StanfordNLP ()
14
+ result = nlp . parse ("Hello world! It is so beautiful." )
15
+ pprint ( result )
13
16
14
- # now handles imperatives
15
- result = json .loads (server .parse ("stop smoking" ))
16
- print "Result" , result
17
-
18
- result = json .loads (server .parse ("eat dinner" ))
19
- print "Result" , result
20
-
21
- import pprint
22
- result = json .loads (server .parse ("Hello world! It is so beautiful." ))
23
- pprint .pprint (result )
24
-
25
- # example using nltk
26
- from nltk .tree import *
17
+ from nltk .tree import Tree
27
18
tree = Tree .parse (result ['sentences' ][0 ]['parsetree' ])
28
- print tree
29
- print tree .leaves ()
19
+ pprint (tree )
You can’t perform that action at this time.
0 commit comments