Beispiel #1
0
 def add_user_messages(self, messages, line_num):
     if not self.current_step_builder:
         raise StoryParseError("User message '{}' at invalid location. "
                               "Expected story start.".format(messages))
     parsed_messages = []
     for m in messages:
         parse_data = self.interpreter.parse(m)
         # a user uttered event's format is a bit different to the one of
         # other events, so we need to take a shortcut here
         parameters = {"text": m, "parse_data": parse_data}
         utterance = Event.from_story_string(UserUttered.type_name,
                                             parameters)
         if m.startswith("_"):
             c = utterance.as_story_string()
             logger.warning("Stating user intents with a leading '_' is "
                            "deprecated. The new format is "
                            "'* {}'. Please update "
                            "your example '{}' to the new format."
                            "".format(c, m))
         intent_name = utterance.intent.get("name")
         if intent_name not in self.domain.intents:
             logger.warning("Found unknown intent '{}' on line {}. "
                            "Please, make sure that all intents are "
                            "listed in your domain yaml."
                            "".format(intent_name, line_num))
         parsed_messages.append(utterance)
     self.current_step_builder.add_user_messages(parsed_messages)
Beispiel #2
0
    def add_user_messages(self, messages, line_num):
        if not self.current_step_builder:
            raise StoryParseError("User message '{}' at invalid location. "
                                  "Expected story start.".format(messages))
        parsed_messages = []
        for m in messages:
            parse_data = self.interpreter.parse(m)
            utterance = UserUttered(m,
                                    parse_data.get("intent"),
                                    parse_data.get("entities"),
                                    parse_data)

            if m.startswith("_"):
                c = utterance.as_story_string()
                logger.warning("Stating user intents with a leading '_' is "
                               "deprecated. The new format is "
                               "'* {}'. Please update "
                               "your example '{}' to the new format."
                               "".format(c, m))
            intent_name = utterance.intent.get("name")
            if intent_name not in self.domain.intents:
                logger.warning("Found unknown intent '{}' on line {}. "
                               "Please, make sure that all intents are "
                               "listed in your domain yaml."
                               "".format(intent_name, line_num))
            parsed_messages.append(utterance)
        self.current_step_builder.add_user_messages(parsed_messages)
Beispiel #3
0
 async def add_user_messages(self, messages, line_num):
     if not self.current_step_builder:
         raise StoryParseError("User message '{}' at invalid location. "
                               "Expected story start.".format(messages))
     parsed_messages = await asyncio.gather(
         *[self._parse_message(m, line_num) for m in messages])
     self.current_step_builder.add_user_messages(parsed_messages)
Beispiel #4
0
    def add_checkpoint(self, name, conditions):
        # type: (Text, Optional[Dict[Text, Any]]) -> None

        # Ensure story part already has a name
        if not self.current_step_builder:
            raise StoryParseError("Checkpoint '{}' is at an invalid location. "
                                  "Expected a story start.".format(name))

        self.current_step_builder.add_checkpoint(name, conditions)
Beispiel #5
0
    def add_event(self, event_name, parameters):

        # add 'name' only if event is not a SlotSet,
        # because there might be a slot with slot_key='name'
        if "name" not in parameters and event_name != SlotSet.type_name:
            parameters["name"] = event_name

        parsed_events = Event.from_story_string(event_name, parameters,
                                                default=ActionExecuted)
        if parsed_events is None:
            raise StoryParseError("Unknown event '{}'. It is Neither an event "
                                  "nor an action).".format(event_name))
        if self.current_step_builder is None:
            raise StoryParseError("Failed to handle event '{}'. There is no "
                                  "started story block available. "
                                  "".format(event_name))

        for p in parsed_events:
            self.current_step_builder.add_event(p)
Beispiel #6
0
    def add_e2e_messages(self, e2e_messages, line_num):
        if not self.current_step_builder:
            raise StoryParseError("End-to-end message '{}' at invalid "
                                  "location. Expected story start."
                                  "".format(e2e_messages))
        e2e_reader = EndToEndReader()
        parsed_messages = []
        for m in e2e_messages:
            message = e2e_reader._parse_item(m)
            parsed = self._parse_message(message.text, line_num)

            parsed.parse_data["true_intent"] = message.data["true_intent"]
            parsed.parse_data["true_entities"] = \
                message.data.get("entities") or []
            parsed_messages.append(parsed)
        self.current_step_builder.add_user_messages(parsed_messages)