def test_parse(self): # Given / When train(BEVERAGE_DATASET_PATH, str(self.tmp_file_path), config_path=None) # When with self.fail_if_exception("Failed to parse using CLI script"): parse(str(self.tmp_file_path), "Make me two cups of coffee")
def test_parse(self): # Given / When dataset_stream = io.StringIO(u""" --- 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: - brew [number_of_cups:snips/number](one) cup of coffee please - make me [number_of_cups] cups of coffee""") dataset = Dataset.from_yaml_files("en", [dataset_stream]).json nlu_engine = SnipsNLUEngine().fit(dataset) nlu_engine.persist(self.tmp_file_path) # When / Then output_target = io.StringIO() with self.fail_if_exception("Failed to parse using CLI script"): with redirect_stdout(output_target): parse(str(self.tmp_file_path), "Make me two cups of coffee") output = output_target.getvalue() # Then expected_output = """{ "input": "Make me two cups of coffee", "intent": { "intentName": "MakeCoffee", "probability": 1.0 }, "slots": [ { "entity": "snips/number", "range": { "end": 11, "start": 8 }, "rawValue": "two", "slotName": "number_of_cups", "value": { "kind": "Number", "value": 2.0 } } ] } """ self.assertEqual(expected_output, output)