athulvingt
(Athul Suresh)
1
How to handle this kind of situation?
[{'start': 0, 'end': 17, 'text': 'today 3 am to 4am', 'value': {'to': '2021-09-17T05:00:00.000-07:00', 'from': '2021-09-17T03:00:00.000-07:00'}, 'confidence': 1.0, 'additional_info': {'values': [{'to': {'value': '2021-09-17T05:00:00.000-07:00', 'grain': 'hour'}, 'from': {'value': '2021-09-17T03:00:00.000-07:00', 'grain': 'hour'}, 'type': 'interval'}], 'to': {'value': '2021-09-17T05:00:00.000-07:00', 'grain': 'hour'}, 'from': {'value': '2021-09-17T03:00:00.000-07:00', 'grain': 'hour'}, 'type': 'interval'}, 'entity': 'time', 'extractor': 'DucklingEntityExtractor'}]
Is it possible to handle using role in DIETclassifier? or someother way that I can put the values in “to” and “from” into respective slots?
nik202
(NiK202)
2
@athulvingt Heya! Please see this concept on the doc : Forms whilst using roles.
athulvingt
(Athul Suresh)
3
that “role” can only be used with DIETClassifier, Righr? Is it possible to use with Duckling?
nik202
(NiK202)
4
@athulvingt Bro, honestly that’s a trick question you asked I not tried, but give it a try please. Make sure you prove good examples for the same.
athulvingt
(Athul Suresh)
5
I wrote a separate code to handle this, purely duckling
nik202
(NiK202)
6
@athulvingt Nice, If you got time please do share your code and solution with us and close this thread
athulvingt
(Athul Suresh)
7
the solution is depended on use case. This is how i coded
def convert_time(time_str):
date_time = time_str[:19]
time_str = datetime.datetime.strptime(date_time, "%Y-%m-%dT%H:%M:%S")
return time_str
def process_time(entity,tracker):
checkin = tracker.get_slot("checkin")
checkout = tracker.get_slot('checkout')
entry_t= tracker.get_slot('entry_t')
exit_t= tracker.get_slot('exit_t')
if entity['entity'] == 'time':
if isinstance(entity['value'],str):
time_ = entity['value']
if not checkin:
checkin = time_
elif checkin and not entry_t:
checkin = checkin[:11] + time_[11:19]
entry_t = time_[11:19]
else:
checkout = checkin[:11] + time_[11:19]
exit_t = time_[11:19]
if isinstance(entity['value'], dict):
to_ = entity['value']['to']
from_ = entity['value']['from']
if not checkin :
checkin, checkout, entry_t, exit_t = to_ , from_, to_[11:19],from_[11:19]
else:
checkin, entry_t = checkin[:11] + to_[11:19], to_[11:19]
checkout, exit_t = checkin[:11] + from_[11:19], from_[11:19]
return {"checkin": checkin, "entry_t": entry_t, "checkout":checkout, "exit_t":exit_t}
class ValidateAttractionBookingForm(FormValidationAction):
def name(self) -> Text:
return "validate_attraction_booking_form"
( ........)
async def validate(self, dispatcher, tracker, domain):
slots: Dict[Text, Any] = tracker.slots_to_validate()
entity_list = tracker.latest_message['entities']
for entity in entity_list:
if entity['extractor'] == 'DucklingEntityExtractor':
time_slot = process_time(entity,tracker)
for i in time_slot :
slots[i] = time_slot[i]
( ........)
return [SlotSet(slot, value) for slot, value in slots.items()]
nik202
(NiK202)
8
@athulvingt mark above post as solution for other and thanks a lot for sharing your code with us