8000 Cleanup corenlp state machine · orazaro/stanford-corenlp-python@d35e713 · GitHub
[go: up one dir, main page]

Skip to content < 8000 react-partial partial-name="keyboard-shortcuts-dialog" data-ssr="false" data-attempted-ssr="false" data-react-profiling="false" >

Commit d35e713

Browse files
committed
Cleanup corenlp state machine
1 parent f86fdd9 commit d35e713

File tree

3 files changed

+140
-194
lines changed

3 files changed

+140
-194
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
/stanford-corenlp-*
3+
.*project
4+

client.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
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
64

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))
912

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)
1316

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
2718
tree = Tree.parse(result['sentences'][0]['parsetree'])
28-
print tree
29-
print tree.leaves()
19+
pprint(tree)

0 commit comments

Comments
 (0)
0