def test_get_slots_should_raise_with_unknown_intent(self): # Given slots_dataset_stream = io.StringIO(""" --- type: intent name: greeting1 utterances: - Hello [name1](John) --- type: intent name: goodbye utterances: - Goodbye [name](Eric)""") dataset = Dataset.from_yaml_files("en", [slots_dataset_stream]).json # pylint:disable=unused-variable @IntentParser.register("first_intent_parser", True) class FirstIntentParser(MockIntentParser): pass @IntentParser.register("second_intent_parser", True) class SecondIntentParser(MockIntentParser): pass # pylint:enable=unused-variable config = NLUEngineConfig( ["first_intent_parser", "second_intent_parser"]) nlu_engine = SnipsNLUEngine(config).fit(dataset) # When / Then with self.assertRaises(IntentNotFoundError): nlu_engine.get_slots("Hello John", "greeting3")
def test_should_get_slots(self): # Given dataset_stream = io.StringIO(""" --- type: intent name: greeting utterances: - hello [greeted:name](john)""") dataset = Dataset.from_yaml_files("en", [dataset_stream]).json input_text = "hello snips" greeting_intent = "greeting" expected_slots = [ unresolved_slot(match_range=(6, 11), value="snips", entity="name", slot_name="greeted") ] # pylint:disable=unused-variable @IntentParser.register("first_intent_parser", True) class FirstIntentParser(MockIntentParser): pass @IntentParser.register("second_intent_parser", True) class SecondIntentParser(MockIntentParser): def get_slots(self, text, intent): if text == input_text and intent == greeting_intent: return expected_slots return [] # pylint:enable=unused-variable config = NLUEngineConfig( ["first_intent_parser", "second_intent_parser"]) engine = SnipsNLUEngine(config).fit(dataset) # When res_slots = engine.get_slots(input_text, greeting_intent) # Then expected_slots = [custom_slot(s) for s in expected_slots] self.assertListEqual(expected_slots, res_slots)