9
9
import subprocess
10
10
import time
11
11
import sys
12
+ import datetime
12
13
13
14
from six .moves .urllib .parse import urlparse
14
15
@@ -168,11 +169,12 @@ def __init__(self, start_server=True,
168
169
self .default_properties = properties or self .DEFAULT_PROPERTIES
169
170
self .default_output_format = output_format or self .DEFAULT_OUTPUT_FORMAT
170
171
171
- def _request (self , buf , properties ):
172
+ def _request (self , buf , properties , date = None ):
172
173
"""Send a request to the CoreNLP server.
173
174
174
175
:param (str | unicode) text: raw text for the CoreNLPServer to parse
175
176
:param (dict) properties: properties that the server expects
177
+ :param (str) date: reference date of document, used by server to set docDate - expects YYYY-MM-DD
176
178
:return: request result
177
179
"""
178
180
self .ensure_alive ()
@@ -186,8 +188,13 @@ def _request(self, buf, properties):
186
188
else :
187
189
raise ValueError ("Unrecognized inputFormat " + input_format )
188
190
191
+ if date :
192
+ params = {'properties' : str (properties ),'date' : str (date )}
193
+ else :
194
+ params = {'properties' : str (properties )}
195
+
189
196
r = requests .post (self .endpoint ,
190
- params = { 'properties' : str ( properties )} ,
197
+ params = params ,
191
198
data = buf , headers = {'content-type' : ctype },
192
199
timeout = (self .timeout * 2 )/ 1000 )
193
200
r .raise_for_status ()
@@ -198,7 +205,7 @@ def _request(self, buf, properties):
198
205
else :
199
206
raise AnnotationException (r .text )
200
207
201
- def annotate (self , text , annotators = None , output_format = None , properties = None ):
208
+ def annotate (self , text , annotators = None , output_format = None , properties = None , date = None ):
202
209
"""Send a request to the CoreNLP server.
203
210
204
211
:param (str | unicode) text: raw text for the CoreNLPServer to parse
@@ -222,7 +229,7 @@ def annotate(self, text, annotators=None, output_format=None, properties=None):
222
229
if output_format is not None :
223
230
properties ["outputFormat" ] = output_format
224
231
# make the request
225
- r = self ._request (text .encode ('utf-8' ), properties )
232
+ r = self ._request (text .encode ('utf-8' ), properties , date )
226
233
# customize what is returned based outputFormat
227
234
if properties ["outputFormat" ] == "serialized" :
228
235
doc = Document ()
@@ -235,7 +242,7 @@ def annotate(self, text, annotators=None, output_format=None, properties=None):
235
242
else :
236
243
return r
237
244
238
- def update (self , doc , annotators = None , properties = None ):
245
+ def update (self , doc , annotators = None , properties = None , date = None ):
239
246
if properties is None :
240
247
properties = self .default_properties
241
248
properties .update ({
@@ -248,7 +255,7 @@ def update(self, doc, annotators=None, properties=None):
248
255
writeToDelimitedString (doc , stream )
249
256
msg = stream .getvalue ()
250
257
251
- r = self ._request (msg , properties )
258
+ r = self ._request (msg , properties , date )
252
259
doc = Document ()
253
260
parseFromDelimitedString (doc , r .content )
254
261
return doc
0 commit comments