Commits

Anonymous committed 56b973c

jsonrpc

Comments (0)

Files changed (2)

-from webob import Request
-from wsgiproxy.exactproxy import proxy_exact_request
-from simplejson import loads, dumps
-
-proxy = proxy_exact_request        
-
-json = dict(method='parse', id=None, params=['this is a sentence'])
-req = Request.blank("http://localhost:8080")
-req.method = 'POST'
-req.content_type = 'application/json'
-req.body = dumps(json)
-resp = req.get_response(proxy)
-json = loads(resp.body)
-print json
+import jsonrpc
+server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(),
+        jsonrpc.TransportTcpIp(addr=("127.0.0.1", 8080)))
 
+# call a remote-procedure 
+result = server.parse("hello world")
+print "Result", result
 import sys
 import os
 
-from SimpleJSONRPCServer import *
+import jsonrpc
+
 from progressbar import *
 
 class StanfordCoreNLP(object):
         pbar.update(3)
         self._server.expect("done.", timeout=600) # Load CoNLL classifier (~50sec)
         pbar.update(4)
-        self._server.expect("done.", timeout=200)
+        self._server.expect("done.", timeout=200) # Loading PCFG (~3sec)
         pbar.update(5)
         self._server.expect("Entering interactive shell.")
         pbar.finish()
         print self._server.before
     
-    def _listMethods(self):
-        return ['parse']
-
-    def _dispatch(self, method, params):
-        if method == 'parse':
-            self._server.sendline(*params)
-            return self._server.readlines()
-        return 'bad method'
+    def parse(self, text):
+        self._server.sendline(text)
+        return self._server.readlines()
 
 
 if __name__ == '__main__':
         help='Host to serve on (default localhost; 0.0.0.0 to make public)')
     options, args = parser.parse_args()
     parser.print_help()
-    server = SimpleJSONRPCServer((options.host, int(options.port)))
-    server.register_introspection_functions()
+    server = jsonrpc.Server(jsonrpc.JsonRrpc20(), 
+                            jsonrpc.TransportTcpIp(addr=(options.host, int(options.port))),
+                            logfunc=jsonrpc.log_file("stanford_server.log"))
+    corenlp = StanfordCoreNLP() 
+    server.register_function(corenlp.parse)
+    #server.register_instance(StanfordCoreNLP())
     print 'Serving on http://%s:%s' % (options.host, options.port)
-    server.register_instance(StanfordCoreNLP())
-    server.serve_forever()
+    server.serve()