Is there a way to extract a data only with Duckling?
If an user would want to schedule a meeting on for example next week monday, it would retrieve data+time, which is 2018-08-13T00:00:00.000Z. But I need to extract a time seperatly in case a user only gives a date as input.
If you are: I would recommend a custom action. Duckling returns a granularity that would be day if the user just said “next Monday” or would be hour if the user said “next Monday at 3pm”. In your custom action you could use the granularity to split the date time returned by duckling and set a date slot and a time slot. But only set the time slot if the grain is hour or minute.
I don’t have the time at the moment to write the custom action, but give it a try and let me know if that works for you.
Nice of you to share your code Andre.
Alternatively, you can use dateutil to parse the ISO datetime format.
import dateutil.parser
Class ActionGetDate(Action):
def name(self):
return 'custom_act_get_date' #****This is used in the story!****
def run(self, dispatcher, tracker, domain):
dictData = next((e for e in tracker.latest_message.entities if
e['entity'] == 'time'), None)
date = dictData['value']
datetime_obj = dateutil.parser.parse(date)
humanDate = datetime_obj.strftime('%Y-%m-%d %H:%M:%S')
time = datetime_obj.time()
#dispatcher.utter_message("I got this time: " + time + ". This is the full date: " + humanDate)
return [SlotSet("slot_time", datetime_obj.time()]
Thanks for sharing! I’m not fully aware yet of the possiblities with the tracker (is there any documentation on what i can do with it?). Can you maybe explain what:
next((e for e in tracker.latest_message.entities if e['entity'] == 'time'), None)
I am getting the date and time for “now” text as :
“time”: {
“to”: “2020-03-20T13:55:35.000+05:30”,
“from”: “2020-03-20T13:55:35.000+05:30”
}
I am getting the same values for “to” and “from”.
Is there any way that i can get the 24 hours back from current time and date value in “from”?
I want like this:
“time”: {
“to”: “2020-03-20T13:55:35.000+05:30”,
“from”: “2020-03-19T13:55:35.000+05:30”
}
you can check on additional_info[“grain”] if it is an hour or not as a validation to know whether the user-provided time or the 00:00:00 is just the default