forked from cbrew/clear-nlp-packaged
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
executable file
·45 lines (34 loc) · 1.04 KB
/
client.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
#!/usr/bin/env python
import pandas
import sys
sys.path.append('./target/generated-sources/python/gen-py')
from sample import ClearNLP
from sample.ttypes import *
from sample.constants import *
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
try:
# Make socket
transport = TSocket.TSocket('localhost', 9090)
# Buffering is critical. Raw sockets are very slow
transport = TTransport.TBufferedTransport(transport)
# Wrap in a protocol
protocol = TBinaryProtocol.TBinaryProtocol(transport)
# Create a client to use the protocol encoder
client = ClearNLP.Client(protocol)
# Connect!
transport.open()
sentno = 0
for arg in sys.argv[1:]:
print arg
for i, sentence in enumerate(client.labelFile(arg)):
print i
for node in sentence:
print node
sentno += i + 1
transport.close()
except Thrift.TException, tx:
print "%s" % (tx.message)
print sentno