def parse(self, text): tokens = self.tokenizer.tokenize(text) intent, probability = self.get_intent(tokens) entities = get_entities(text, tokens, self.extractor) if self.ent_synonyms: Interpreter.replace_synonyms(entities, self.ent_synonyms) return { 'text': text, 'intent': intent, 'entities': entities, 'confidence': probability }
def parse(self, text): """Parse the input text, classify it and return an object containing its intent and entities.""" intent, probability = self.get_intent(text) entities = self.get_entities(text) if self.ent_synonyms: Interpreter.replace_synonyms(entities, self.ent_synonyms) return { 'text': text, 'intent': intent, 'entities': entities, 'confidence': probability }
def test_entity_synonyms(): entities = [{ "entity": "test", "value": "chines", "start": 0, "end": 6 }, { "entity": "test", "value": "chinese", "start": 0, "end": 6 }, { "entity": "test", "value": "china", "start": 0, "end": 6 }] ent_synonyms = {"chines": "chinese", "NYC": "New York City"} Interpreter.replace_synonyms(entities, ent_synonyms) assert len(entities) == 3 assert entities[0]["value"] == "chinese" assert entities[1]["value"] == "chinese" assert entities[2]["value"] == "china"