This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
StanfordCoreNLP-remote
executable file
·151 lines (130 loc) · 3.93 KB
/
StanfordCoreNLP-remote
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (0.9.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
# options string: py:utf8strings,slots,new_style
#
import sys
import pprint
from urlparse import urlparse
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol
import StanfordCoreNLP
from ttypes import *
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print ''
print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
print ''
print 'Functions:'
print ' void ping()'
print ' void zip()'
print ' parse_text(string text, outputFormat)'
print ' ParseTree parse_tokens( tokens, outputFormat)'
print ' get_entities_from_text(string text)'
print ' get_entities_from_tokens( tokens)'
print ' get_entities_from_trees( trees)'
print ' resolve_coreferences_in_text(string text)'
print ' resolve_coreferences_in_tokenized_sentences( sentencesWithTokensSeparatedBySpace)'
print ' resolve_coreferences_in_trees( trees)'
print ''
sys.exit(0)
pp = pprint.PrettyPrinter(indent = 2)
host = 'localhost'
port = 9090
uri = ''
framed = False
http = False
argi = 1
if sys.argv[argi] == '-h':
parts = sys.argv[argi+1].split(':')
host = parts[0]
if len(parts) > 1:
port = int(parts[1])
argi += 2
if sys.argv[argi] == '-u':
url = urlparse(sys.argv[argi+1])
parts = url[1].split(':')
host = parts[0]
if len(parts) > 1:
port = int(parts[1])
else:
port = 80
uri = url[2]
if url[4]:
uri += '?%s' % url[4]
http = True
argi += 2
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
framed = True
argi += 1
cmd = sys.argv[argi]
args = sys.argv[argi+1:]
if http:
transport = THttpClient.THttpClient(host, port, uri)
else:
socket = TSocket.TSocket(host, port)
if framed:
transport = TTransport.TFramedTransport(socket)
else:
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = StanfordCoreNLP.Client(protocol)
transport.open()
if cmd == 'ping':
if len(args) != 0:
print 'ping requires 0 args'
sys.exit(1)
pp.pprint(client.ping())
elif cmd == 'zip':
if len(args) != 0:
print 'zip requires 0 args'
sys.exit(1)
pp.pprint(client.zip())
elif cmd == 'parse_text':
if len(args) != 2:
print 'parse_text requires 2 args'
sys.exit(1)
pp.pprint(client.parse_text(args[0],eval(args[1]),))
elif cmd == 'parse_tokens':
if len(args) != 2:
print 'parse_tokens requires 2 args'
sys.exit(1)
pp.pprint(client.parse_tokens(eval(args[0]),eval(args[1]),))
elif cmd == 'get_entities_from_text':
if len(args) != 1:
print 'get_entities_from_text requires 1 args'
sys.exit(1)
pp.pprint(client.get_entities_from_text(args[0],))
elif cmd == 'get_entities_from_tokens':
if len(args) != 1:
print 'get_entities_from_tokens requires 1 args'
sys.exit(1)
pp.pprint(client.get_entities_from_tokens(eval(args[0]),))
elif cmd == 'get_entities_from_trees':
if len(args) != 1:
print 'get_entities_from_trees requires 1 args'
sys.exit(1)
pp.pprint(client.get_entities_from_trees(eval(args[0]),))
elif cmd == 'resolve_coreferences_in_text':
if len(args) != 1:
print 'resolve_coreferences_in_text requires 1 args'
sys.exit(1)
pp.pprint(client.resolve_coreferences_in_text(args[0],))
elif cmd == 'resolve_coreferences_in_tokenized_sentences':
if len(args) != 1:
print 'resolve_coreferences_in_tokenized_sentences requires 1 args'
sys.exit(1)
pp.pprint(client.resolve_coreferences_in_tokenized_sentences(eval(args[0]),))
elif cmd == 'resolve_coreferences_in_trees':
if len(args) != 1:
print 'resolve_coreferences_in_trees requires 1 args'
sys.exit(1)
pp.pprint(client.resolve_coreferences_in_trees(eval(args[0]),))
else:
print 'Unrecognized method %s' % cmd
sys.exit(1)
transport.close()