-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpython-server-wrapper.py
54 lines (43 loc) · 1.38 KB
/
python-server-wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/env python2.4
"""
Python XML-RPC server wrapper for KEA.
If the Java KEA service throws an exception, return an empty list of
keywords. This appears to happen on weird Unicode characters, in 0.3%
of page text. YMMV.
"""
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import xmlrpclib
import sys
# if we are passed a port use it
# else use 8000
if len(sys.argv) > 1:
jv_port = int(sys.argv[0])
else:
jv_port = 8000
print "jv_port = ", jv_port
s = xmlrpclib.ServerProxy('http://localhost:%d' % jv_port)
import sys
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("0.0.0.0", jv_port + 1),
requestHandler=RequestHandler)
server.register_introspection_functions()
from common.movingaverage import MovingAverage
broke = MovingAverage()
def extractKeyphrases(txt):
if broke.cnt % 100 == 0:
print >> sys.stderr, "%s documents could NOT have keyphrase extracted" % broke
try:
kw = s.kea.extractKeyphrases(txt)
broke.add(0)
return kw
except:
print >> sys.stderr, "Oops! Couldn't extract keyphrases over:", repr(txt)
broke.add(1)
return []
server.register_function(extractKeyphrases)
# Run the server's main loop
server.serve_forever()