File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -8,26 +8,30 @@ def __init__(self, server_url):
8
8
self .server_url = server_url
9
9
10
10
def annotate (self , text , properties = None ):
11
- if not properties :
11
+ assert isinstance (text , str )
12
+ if properties is None :
12
13
properties = {}
13
-
14
+ else :
15
+ assert isinstance (properties , dict )
16
+
14
17
# Checks that the Stanford CoreNLP server is started.
15
18
try :
16
- requests .get (self .server_url ). ok == True
19
+ requests .get (self .server_url )
17
20
except requests .exceptions .ConnectionError :
18
21
raise Exception ('Check whether you have started the CoreNLP server e.g.\n '
19
22
'$ cd stanford-corenlp-full-2015-12-09/ \n '
20
23
'$ java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer' )
21
-
22
- r = requests .get (
24
+
25
+ data = text .encode ()
26
+ r = requests .post (
23
27
self .server_url , params = {
24
28
'properties' : str (properties )
25
- }, data = text )
29
+ }, data = data , headers = { 'Connection' : 'close' } )
26
30
output = r .text
27
31
if ('outputFormat' in properties
28
32
and properties ['outputFormat' ] == 'json' ):
29
33
try :
30
- output = json .loads (output , strict = False )
34
+ output = json .loads (output , encoding = 'utf-8' , strict = True )
31
35
except :
32
36
pass
33
37
return output
You can’t perform that action at this time.
0 commit comments