Skip to content

Commit 73e6b1d

Browse files
author
Robert Elwell
committed
updated README
1 parent d394613 commit 73e6b1d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
This is a fork of Dustin Smith's [stanford-corenlp-python](https://github.com/dasmith/stanford-corenlp-python), a Python interface to [Stanford CoreNLP](http://nlp.stanford.edu/software/corenlp.shtml). It can either use as python package, or run as a JSON-RPC server.
55

66
## Edited
7+
* Added multi-threaded load balancing
78
* Update to Stanford CoreNLP v3.2.0
89
* Fix many bugs & improve performance
910
* Using jsonrpclib for stability and performance
@@ -38,6 +39,10 @@ Optionally, you can specify a host or port:
3839

3940
python corenlp/corenlp.py -H 0.0.0.0 -p 3456
4041

42+
For additional concurrency, you can add a load-balancing layer on top:
43+
44+
python corenlp/corenlp.py --ports=8081,8082,8083,8084
45+
4146
That will run a public JSON-RPC server on port 3456.
4247
And you can specify Stanford CoreNLP directory:
4348

@@ -53,6 +58,24 @@ Assuming you are running on port 8080 and CoreNLP directory is `stanford-corenlp
5358
result = loads(server.parse("Hello world. It is so beautiful"))
5459
print "Result", result
5560

61+
If you are using the load balancing component, then you can use the following approach:
62+
63+
import jsonrpclib
64+
from simplejson import loads
65+
server = jsonrpclib.Server("http://localhost:8080")
66+
67+
result = loads(server.send("Hello world. It is so beautiful"))
68+
print "Result", server.getForKey(result['key'])
69+
70+
# asynchronous parsing and retrieval
71+
sents = [ 'add in as many sentences as you want', 'your mileage may vary' ]
72+
for sent in sents:
73+
server.send(sent)
74+
# this approach is non-blocking
75+
print server.getCompleted()
76+
# this approach waits for all in-progress parses to finish (i.e. blocks)
77+
print server.getAll()
78+
5679
That returns a dictionary containing the keys `sentences` and (when applicable) `corefs`. The key `sentences` contains a list of dictionaries for each sentence, which contain `parsetree`, `text`, `tuples` containing the dependencies, and `words`, containing information about parts of speech, NER, etc:
5780

5881
{u'sentences': [{u'parsetree': u'(ROOT (S (VP (NP (INTJ (UH Hello)) (NP (NN world)))) (. !)))',
@@ -139,3 +162,5 @@ The function uses XML output feature of Stanford CoreNLP, and you can take all i
139162
## Developer
140163
* Hiroyoshi Komatsu [[email protected]]
141164
* Johannes Castner [[email protected]]
165+
* Robert Elwell [[email protected]]
166+
* Tristan Chong [[email protected]]

0 commit comments

Comments
 (0)