def test_slot_map_items_iteration(): from hermes_python.ontology.dialogue import SlotsList slots = hermes_python.ontology.dialogue.SlotMap({"test_slot": SlotsList()}) for slot, slot_value_list in slots.items(): assert slot == "test_slot" assert len(slot_value_list) == 0
def test_helper_method_access(): from hermes_python.ontology.dialogue import SlotsList, NluSlot, SlotMap, SlotValue, CustomValue custom_value_slot = CustomValue("Hello world") nlu_slot = NluSlot(0.1, SlotValue(1, custom_value_slot), "test", "test", "test_slot", 0, 0) slots = SlotMap({"test_slot": SlotsList()}) slots.test_slot.append(nlu_slot) assert type(slots.test_slot.first()) is CustomValue
def test_get_date_from_intent_with_time(self): """ Test whether the function get_date returns the data in the intent if it contains an instant time value. """ calendar_date_value = InstantTimeValue("2018-10-31 00:00:00" " +01:00", "grain", "precision") slot_map = SlotMap( {"calendar_date": SlotsList([NluSlot(calendar_date_value)])}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening today", intent, slot_map) self.assertEqual(tools.get_date(intent_message), "20181031")
def test_get_date_from_intent_with_interval(self): """ Test whether the function get_date returns the start date in the intent if it contains a time interval. """ calendar_date_value = TimeIntervalValue( "2018-11-05 18:00:00" " +01:00", "2018-11-06 00:00:00" " +01:00") slot_map = SlotMap( {"calendar_date": SlotsList([NluSlot(calendar_date_value)])}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening this night", intent, slot_map) self.assertEqual(tools.get_date(intent_message), "20181105")
def test_get_calendar_from_intent_with_calendar(self): """ Test whether the function get_calendar returns the calendar in the intent, even if a default calendar is set. """ calendar_file_value = CustomValue("computer") slot_map = SlotMap( {"calendar_file": SlotsList([NluSlot(calendar_file_value)])}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening today in computers", intent, slot_map) # Calendar computer in intent message, no default calendar # -> calendar computer self.assertEqual(tools.get_calendar(intent_message, ""), "computer") # Calendar computer in intent message, default calendar thai # -> calendar computer self.assertEqual(tools.get_calendar(intent_message, "thai"), "computer")
def test_slot_access_dot_notation(): from hermes_python.ontology.dialogue import SlotsList slots = hermes_python.ontology.dialogue.SlotMap({"test_slot": SlotsList()}) assert type(slots.test_slot) is SlotsList