dialogy.plugins.text.combine_date_time package¶
Module contents¶
- class CombineDateTimeOverSlots(dest=None, guards=None, input_column='alternatives', output_column=None, replace_output=True, use_transform=False, trigger_intents=None, debug=False)[source]¶
Bases:
dialogy.base.plugin.Plugin
Dialog case:
Assume that at the moment of dialog the date is 15th December 2019.
utterance
entity
1
BOT
When do you want to visit?
2
USER
Day after tomorrow
{‘type’: ‘date’, ‘value’: ‘2019-12-17’}
3
BOT
At what time?
4
USER
3 pm
{‘type’: ‘time’, ‘value’: ‘2019-12-15T15:00:00+0000’}
We want to use the slots such that the date from interaction [2] and the time from interaction [4] are combined into a single entity.
We receive this as a tracked slot:
[{ "name": "_callback_", "slots": [{ "name": "callback_datetime", "type": [ "time", "date", "datetime" ], "values": [{ "alternative_index": 0, "body": "tomorrow", "entity_type": "date", "grain": "day", "parsers": ["duckling"], "range": { "end": 8, "start": 0 }, "score": null, "type": "value", "value": "2021-10-15T00:00:00+05:30" }] }] }]
At interaction [4] we would have a TimeEntity from DucklingPlugin but as we can see, the tracked slot provides us previously filled values as json.
So we need to parse the first value in the slot (since they are the entities) if they are one of these date, time, datetime types. This would give us a date / time entity that we can subsequently combine with the available entity in the current turn.
- DATE = 'date'¶
- DATETIME = 'datetime'¶
- SUPPORTED_ENTITIES = ['date', 'time', 'datetime']¶
- TIME = 'time'¶
- combine_time_entities_from_slots(slot_tracker, entities)[source]¶
Combines the time entities from the slots with the entities from the current turn.
- Parameters
slot_tracker (Optional[List[Dict[str, Any]]]) – The slot tracker from the previous turn.
entities (List[BaseEntity]) – Entities found in the current turn.
- Returns
Combined set of entities.
- Return type
List[BaseEntity]
- pick_previously_filled_time_entity(tracked_slots)[source]¶
- Return type
Optional
[TimeEntity
]
- utility(input, output)[source]¶
Combine the date and time entities collected across turns into a single entity.
- Return type
List
[BaseEntity
]