def test_should_parse_after_deserialization(self): # Given dataset = BEVERAGE_DATASET engine = SnipsNLUEngine().fit(dataset) input_ = "Give me 3 cups of hot tea please" # When engine_dict = engine.to_dict() deserialized_engine = SnipsNLUEngine.from_dict(engine_dict) result = deserialized_engine.parse(input_) # Then msg = "SnipsNLUEngine dict should be json serializable to utf-8" with self.fail_if_exception(msg): json.dumps(engine_dict).encode("utf-8") expected_slots = [ resolved_slot({ START: 8, END: 9 }, '3', { 'kind': 'Number', 'value': 3.0 }, 'snips/number', 'number_of_cups'), custom_slot( unresolved_slot({ START: 18, END: 21 }, 'hot', 'Temperature', 'beverage_temperature')) ] self.assertEqual(result[RES_INPUT], input_) self.assertEqual(result[RES_INTENT][RES_INTENT_NAME], 'MakeTea') self.assertListEqual(result[RES_SLOTS], expected_slots)
def test_should_parse_after_deserialization_from_dir(self): # Given dataset = BEVERAGE_DATASET engine = SnipsNLUEngine().fit(dataset) input_ = "Give me 3 cups of hot tea please" # When engine.persist(self.tmp_file_path) deserialized_engine = SnipsNLUEngine.from_path(self.tmp_file_path) result = deserialized_engine.parse(input_) # Then expected_slots = [ resolved_slot({ START: 8, END: 9 }, "3", { "kind": "Number", "value": 3.0 }, "snips/number", "number_of_cups"), custom_slot( unresolved_slot({ START: 18, END: 21 }, "hot", "Temperature", "beverage_temperature")) ] self.assertEqual(result[RES_INPUT], input_) self.assertEqual(result[RES_INTENT][RES_INTENT_NAME], "MakeTea") self.assertListEqual(result[RES_SLOTS], expected_slots)
def test_should_parse_after_deserialization(self): # Given dataset = BEVERAGE_DATASET engine = SnipsNLUEngine().fit(dataset) input_ = "Give me 3 cups of hot tea please" # When engine_dict = engine.to_dict() deserialized_engine = SnipsNLUEngine.from_dict(engine_dict) result = deserialized_engine.parse(input_) # Then msg = "SnipsNLUEngine dict should be json serializable to utf-8" with self.fail_if_exception(msg): json.dumps(engine_dict).encode("utf-8") expected_slots = [ resolved_slot({START: 8, END: 9}, '3', {'kind': 'Number', 'value': 3.0}, 'snips/number', 'number_of_cups'), custom_slot( unresolved_slot({START: 18, END: 21}, 'hot', 'Temperature', 'beverage_temperature')) ] self.assertEqual(result[RES_INPUT], input_) self.assertEqual(result[RES_INTENT][RES_INTENT_NAME], 'MakeTea') self.assertListEqual(result[RES_SLOTS], expected_slots)
def test_should_parse_after_deserialization_from_dir(self): # Given dataset_stream = io.StringIO(""" --- type: intent name: MakeTea utterances: - make me a [beverage_temperature:Temperature](hot) cup of tea - make me [number_of_cups:snips/number](five) tea cups - i want [number_of_cups] cups of [beverage_temperature](boiling hot) tea pls - can you prepare [number_of_cups] cup of [beverage_temperature](cold) tea ? --- type: intent name: MakeCoffee utterances: - make me [number_of_cups:snips/number](one) cup of coffee please - brew [number_of_cups] cups of coffee - can you prepare [number_of_cups] cup of coffee""") dataset = Dataset.from_yaml_files("en", [dataset_stream]).json shared = self.get_shared_data(dataset) engine = SnipsNLUEngine(**shared).fit(dataset) text = "Give me 3 cups of hot tea please" # When engine.persist(self.tmp_file_path) deserialized_engine = SnipsNLUEngine.from_path(self.tmp_file_path) result = deserialized_engine.parse(text) # Then expected_slots = [ resolved_slot({ START: 8, END: 9 }, "3", { "kind": "Number", "value": 3.0 }, "snips/number", "number_of_cups"), custom_slot( unresolved_slot({ START: 18, END: 21 }, "hot", "Temperature", "beverage_temperature")) ] self.assertEqual(result[RES_INPUT], text) self.assertEqual(result[RES_INTENT][RES_INTENT_NAME], "MakeTea") self.assertListEqual(result[RES_SLOTS], expected_slots)