예제 #1
0
 def _next_story_steps(self):
     start_checkpoints = self._prev_end_checkpoints()
     if not start_checkpoints:
         start_checkpoints = [Checkpoint(STORY_START)]
     current_turns = [StoryStep(block_name=self.name, start_checkpoint=s)
                      for s in start_checkpoints]
     return current_turns
예제 #2
0
파일: dsl.py 프로젝트: yohahn8/rasa_core
 def _prev_end_checkpoints(self):
     if not self.current_steps:
         return self.start_checkpoints
     else:
         # makes sure we got each end name only once
         end_names = {e.name
                      for s in self.current_steps
                      for e in s.end_checkpoints}
         return [Checkpoint(name) for name in end_names]
예제 #3
0
 def add_checkpoint(self, name, conditions):
     # Depending on the state of the story part this
     # is either a start or an end check point
     if not self.current_steps:
         self.start_checkpoints.append(Checkpoint(name, conditions))
     else:
         if conditions:
             logger.warn("End or intermediate checkpoints "
                         "do not support conditions! "
                         "(checkpoint: {})".format(name))
         additional_steps = []
         for t in self.current_steps:
             if t.end_checkpoint != STORY_END:
                 tcp = t.create_copy(use_new_id=True)
                 tcp.end_checkpoint = Checkpoint(name)
                 additional_steps.append(tcp)
             else:
                 t.end_checkpoint = Checkpoint(name)
         self.current_steps.extend(additional_steps)
예제 #4
0
    def add_checkpoint(self, name, conditions):
        # type: (Text, Optional[Dict[Text, Any]]) -> None

        # Depending on the state of the story part this
        # is either a start or an end check point
        if not self.current_steps:
            self.start_checkpoints.append(Checkpoint(name, conditions))
        else:
            if conditions:
                logger.warning("End or intermediate checkpoints "
                               "do not support conditions! "
                               "(checkpoint: {})".format(name))
            additional_steps = []
            for t in self.current_steps:
                if t.end_checkpoints:
                    tcp = t.create_copy(use_new_id=True)
                    tcp.end_checkpoints = [Checkpoint(name)]
                    additional_steps.append(tcp)
                else:
                    t.end_checkpoints = [Checkpoint(name)]
            self.current_steps.extend(additional_steps)
예제 #5
0
    def add_user_messages(self, messages):
        self.ensure_current_steps()

        if len(messages) == 1:
            # If there is only one possible intent, we'll keep things simple
            for t in self.current_steps:
                t.add_user_message(messages[0])
        else:
            # If there are multiple different intents the
            # user can use the express the same thing
            # we need to copy the blocks and create one
            # copy for each possible message
            generated_checkpoint = utils.generate_id("GENERATED_M_")
            updated_steps = []
            for t in self.current_steps:
                for m in messages:
                    copied = t.create_copy(use_new_id=True)
                    copied.add_user_message(m)
                    copied.end_checkpoint = Checkpoint(generated_checkpoint)
                    updated_steps.append(copied)
            self.current_steps = updated_steps
예제 #6
0
 def _prev_end_checkpoints(self):
     if not self.current_steps:
         return self.start_checkpoints
     else:
         end_names = {s.end_checkpoint_name() for s in self.current_steps}
         return [Checkpoint(name) for name in end_names]