Passing current datetime to sutime through corenlp server?
daniel-brenot opened this issue · 7 comments
I've been reading the documentation and i'm left quite stumped.
I'm trying to parse the string "tomorrow" using the sutime annotator for the CORENLP server and I can't figure out how to provide the current datetime so that it's able to use it in the response. I know that it can be done from java directly, but i'm hoping to just use the server with a configuration that would let me do this.
Is there a specific property I have to pass? Any help would be appreciated greatly as I'm on a bit of a deadline.
At a high level this was just too vague of a question, but it's possible to pass in the current date as part of a query. For example, if you're using the Stanza interface, this will label tomorrow
as normalizedNER: "OFFSET P1D"
from stanza.server import CoreNLPClient
text = "Chris Manning will give a talk tomorrow."
with CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner'], timeout=60000, memory='16G', classpath='$CLASSPATH') as client:
# submit the request to the server
ann = client.annotate(text, properties={'date': '2023-08-12'})
print(ann)
whereas this will label it as normalizedNER: "2023-08-13"
from stanza.server import CoreNLPClient
text = "Chris Manning will give a talk tomorrow."
with CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner'], timeout=60000, memory='16G', classpath='$CLASSPATH') as client:
# submit the request to the server
ann = client.annotate(text, properties={'date': '2023-08-12'})
print(ann)
As far as I can see, the server does not consider the current day or time by default, nor is there a way to tell the server at startup time what the date is. However, queries that have the date
field included will use that as the basis for relative times.
If that's not enough of an answer, please be more specific about how you're communicating with the server and what you need to happen.
Apologies if i wasn't clear enough.
I'm attempting to communicate via a post call to the server. I'm in python and want to use this as a separate service i call.
I didn't know about stanza, thank you. I'll see about using that and see if it lets me do what i want.
Although something odd from your example is that it doesn't seem to use SUTIME. I'm referring to trying to evaluate a string with just the word of the datetime/range i'm looking to evaluate.
Will this work with the SUTIME annotator?
The sutime annotator is included by default in the ner annotator, so it is actually using sutime for that date expansion.
Regardless of how you POST requests to CoreNLP, if you include properties: {'date': '...'}
as one of the headers, it should work. Stanza has that mechanism as shown above, but you should be able to do it yourself using whatever you were using for the requests. It should be noted that installing Stanza comes with a bunch of other stuff, such as pytorch, but maybe that's not an issue for you.
Installing pytorch wouldn't have been an issue, however i see that the client requires the jvm to be on the same machine. The implementation i'm going for has the jvm in it's own container for separation of concerns.
Regardless, i'll try out sending the date as a property. If that works, you just made my night.
Aaaaand it worked. Thank you so much @AngledLuffa, this has saved me alot of work on a day before we are supposed to release a product that relies on this.
Have a great night and thanks for all your help!
Glad it worked - I was just in the process of telling you that Stanza doesn't actually have the limitation you found, as you can start the client with endpoint
and start_server
parameters set to talk to an already started server on a different machine
Anyway, I'll just leave that correction there for posterity and be glad to check something off today's TODO list
class CoreNLPClient(RobustService):
...
def __init__(self, start_server=StartServer.FORCE_START,
endpoint=DEFAULT_ENDPOINT,