def test_should_be_serializable_into_bytearray(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 --- type: intent name: MakeCoffee utterances: - make me [number_of_cups:snips/number](one) cup of coffee please - brew [number_of_cups] cups of coffee""") dataset = Dataset.from_yaml_files("en", [dataset_stream]).json shared = self.get_shared_data(dataset) engine = SnipsNLUEngine(**shared).fit(dataset) # When engine_bytes = engine.to_byte_array() loaded_engine = SnipsNLUEngine.from_byte_array(engine_bytes) result = loaded_engine.parse("Make me two cups of coffee") # Then self.assertEqual(result[RES_INTENT][RES_INTENT_NAME], "MakeCoffee")
def test_should_be_serializable_into_bytearray_when_empty(self): # Given engine = SnipsNLUEngine() engine_bytes = engine.to_byte_array() # When engine = SnipsNLUEngine.from_byte_array(engine_bytes) # Then self.assertFalse(engine.fitted)
def test_should_be_serializable_into_bytearray(self): # Given dataset = BEVERAGE_DATASET engine = SnipsNLUEngine().fit(dataset) # When engine_bytes = engine.to_byte_array() loaded_engine = SnipsNLUEngine.from_byte_array(engine_bytes) result = loaded_engine.parse("Make me two cups of coffee") # Then self.assertEqual(result[RES_INTENT][RES_INTENT_NAME], "MakeCoffee")
def test_should_be_serializable_into_bytearray(self): # Given dataset = BEVERAGE_DATASET engine = SnipsNLUEngine().fit(dataset) # When engine_bytes = engine.to_byte_array() builtin_entity_parser = BuiltinEntityParser.build(dataset=dataset) custom_entity_parser = CustomEntityParser.build( dataset, parser_usage=CustomEntityParserUsage.WITHOUT_STEMS) loaded_engine = SnipsNLUEngine.from_byte_array( engine_bytes, builtin_entity_parser=builtin_entity_parser, custom_entity_parser=custom_entity_parser) result = loaded_engine.parse("Make me two cups of coffee") # Then self.assertEqual(result[RES_INTENT][RES_INTENT_NAME], "MakeCoffee")