"I want to go swimming next Tuesday" I want to machine to learn the date I want to go swimming. Is there any approaches or libraries that can
Extract "next Tuesday"
And calculate the exact date?
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.
Sign up to join this community"I want to go swimming next Tuesday" I want to machine to learn the date I want to go swimming. Is there any approaches or libraries that can
Extract "next Tuesday"
And calculate the exact date?
There is a Python library called dateparser that will accept a wide variety of formats, including relative dates like "next Tuesday", and return exact datetime
representation.
A good solution as a service can be using Microsoft LUIS. In LUIS, you can use a prebuilt datetimeV2 entity which recognizes dates, times, date ranges and time durations. To know more about this prebuilt entity see the documentation.
I will list possible ways to approach you problem:
A- Naïve approach
If you are using python, you will need re
and calendar
packages.
Pros:
Cons:
B- Classification
Create a ground truth of strings with positive and negative examples and feed it into a classifier to learn from those examples.
You would need to parse the text first as a pre-processing step (but this would be the case for most approaches, isn't it?)
Pros:
Cons:
nlp
)C- Do it the Apple way
Have a look at some information on the Apple Data Detectors
There are two parts to the question.
To solve the first problem, you can use something called Named Entity Recognition . The problem of finding date is actually a sub problem of the more general NER problem . Nevertheless , you can try the awesome Spacy NER Finder .
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp(u'I want to go swimming next Tuesday')
for ent in doc.ents:
print(ent.text , ent.label_)
next Tuesday DATE
The code finds all the named entities in the text. You can filter out your relevant DATE entity if you get more than one kind of entity
The second problem is a bit simpler, once you have the DATE entity , its only a matter of your Python abilities. You can go by the following: