Ejemplo n.º 1
0
    def _parse_intent(self, data: Dict[Text, Any]) -> None:
        from rasa.nlu.training_data import Message
        import rasa.nlu.training_data.entities_parser as entities_parser
        import rasa.nlu.training_data.synonyms_parser as synonyms_parser
        import rasa.nlu.constants as nlu_constants

        intent = data.get(KEY_INTENT, "")
        if not intent:
            raise_warning(
                f"Issue found while processing '{self.filename}': "
                f"The intent has an empty name. "
                f"Intents should have a name defined under the {KEY_INTENT} key. "
                f"It will be skipped.",
                docs=DOCS_URL_TRAINING_DATA_NLU,
            )
            return

        examples = data.get(KEY_INTENT_EXAMPLES, "")
        for example, entities in self._parse_training_examples(examples, intent):

            synonyms_parser.add_synonyms_from_entities(
                example, entities, self.entity_synonyms
            )

            plain_text = entities_parser.replace_entities(example)

            message = Message.build(plain_text, intent)
            if entities:
                message.set(nlu_constants.ENTITIES, entities)
            self.training_examples.append(message)
Ejemplo n.º 2
0
def test_markdown_entity_regex(
    example: Text, expected_entities: List[Dict[Text, Any]], expected_text: Text
):

    result = entities_parser.find_entities_in_training_example(example)
    assert result == expected_entities

    replaced_text = entities_parser.replace_entities(example)
    assert replaced_text == expected_text
Ejemplo n.º 3
0
    def _parse_raw_user_utterance(self, step: Dict[Text, Any]) -> Optional[UserUttered]:
        intent_name = self._user_intent_from_step(step)
        intent = {"name": intent_name, "confidence": 1.0}

        if KEY_USER_MESSAGE in step:
            user_message = step[KEY_USER_MESSAGE].strip()
            entities = entities_parser.find_entities_in_training_example(user_message)
            plain_text = entities_parser.replace_entities(user_message)
        else:
            raw_entities = step.get(KEY_ENTITIES, [])
            entities = self._parse_raw_entities(raw_entities)
            plain_text = intent_name

        return UserUttered(plain_text, intent, entities)
Ejemplo n.º 4
0
    def parse_training_example(self, example: Text) -> "Message":
        """Extract entities and synonyms, and convert to plain text."""
        from rasa.nlu.training_data import Message
        import rasa.nlu.training_data.entities_parser as entities_parser
        import rasa.nlu.training_data.synonyms_parser as synonyms_parser

        entities = entities_parser.find_entities_in_training_example(example)
        plain_text = entities_parser.replace_entities(example)
        synonyms_parser.add_synonyms_from_entities(plain_text, entities,
                                                   self.entity_synonyms)

        message = Message.build(plain_text, self.current_title)

        if len(entities) > 0:
            message.set("entities", entities)
        return message