1. Hiroyoshi Komatsu
  2. corenlp-python

Commits

dustin smith  committed 1deab19

rename server.py to corenlpy.py

Comments (0)

Files changed (2)

File README.md Modified

View file
  • Ignore whitespace
  • Hide word diff
 
 Then, to launch a server:
 
-    python server.py
+    python corenlp.py
 
 Optionally, you can specify a host or port:
 
-    python server.py -H 0.0.0.0 -p 3456
+    python corenlp.py -H 0.0.0.0 -p 3456
 
 That will run a public JSON-RPC server on port 3456.
 
 
 To use it in a regular script or to edit/debug, load the module instead:
 
-    from server import *
+    from corenlp import *
     corenlp = StanfordCoreNLP() 
     corenlp.parse("Parse an imperative sentence, damnit!")
 

File server.py → corenlp.py (94% similar) Renamed

View file
  • Ignore whitespace
  • Hide word diff
                 if len(split_entry) == 3:
                     rel, left, right = map(lambda x: remove_id(x), split_entry)
                     tmp['tuples'].append(tuple([rel,left,right]))
-                    print "\n", rel, left, right
             elif "Coreference links" in line:
                 state = 5
         elif state == 5:
         with one dictionary entry for each parsed sentence, in JSON format.
         """
         print "Request", text
-        print self._server.sendline(text)
-        # How much time should we give the parser to parse it?it
-        #
+        self._server.sendline(text)
+        # How much time should we give the parser to parse it?
+        # the idea here is that you increase the timeout as a 
+        # function of the text's length.
+        
+        # anything longer than 5 seconds requires that you also
+        # increase timeout=5 in jsonrpc.py
         max_expected_time = min(5, 2 + len(text) / 200.0)
         print "Timeout", max_expected_time
         end_time = time.time() + max_expected_time 
         '-H', '--host', default='127.0.0.1',
         help='Host to serve on (default localhost; 0.0.0.0 to make public)')
     options, args = parser.parse_args()
-    #parser.print_help()
     server = jsonrpc.Server(jsonrpc.JsonRpc20(), 
                             jsonrpc.TransportTcpIp(addr=(options.host, int(options.port))))
-    corenlp = StanfordCoreNLP() 
-    server.register_function(corenlp.parse)
-    #server.register_instance(StanfordCoreNLP())
+    server.register_instance(StanfordCoreNLP())
     print 'Serving on http://%s:%s' % (options.host, options.port)
     server.serve()