def export_stories(self): from rasa_core.training_utils.dsl import StoryStep, Story story_step = StoryStep() for event in self._applied_events(): story_step.add_event(event) story = Story([story_step]) return story.as_story_string(flat=True)
def build_stories(self, domain, max_number_of_trackers=2000): # type: (Domain, NaturalLanguageInterpreter, bool, int) -> List[Story] """Build the stories of a graph.""" from rasa_core.training_utils.dsl import STORY_START, Story active_trackers = {STORY_START: [Story()]} rand = random.Random(42) for step in self.ordered_steps(): if step.start_checkpoint_name() in active_trackers: # these are the trackers that reached this story step # and that need to handle all events of the step incoming_trackers = active_trackers[ step.start_checkpoint_name()] # TODO: we can't use tracker filter here to filter for # checkpoint conditions since we don't have trackers. # this code should rather use the code from the dsl. if max_number_of_trackers is not None: incoming_trackers = utils.subsample_array( incoming_trackers, max_number_of_trackers, rand) events = step.explicit_events(domain) # need to copy the tracker as multiple story steps might # start with the same checkpoint and all of them # will use the same set of incoming trackers if events: trackers = [ Story(tracker.story_steps + [step]) for tracker in incoming_trackers ] else: trackers = [] # small optimization # update our tracker dictionary with the trackers that handled # the events of the step and that can now be used for further # story steps that start with the checkpoint this step ended on if step.end_checkpoint_name() not in active_trackers: active_trackers[step.end_checkpoint_name()] = [] active_trackers[step.end_checkpoint_name()].extend(trackers) return active_trackers[None]
def test_persist_and_read_test_story(tmpdir, default_domain): graph = extract_story_graph_from_file("data/dsl_stories/stories.md", default_domain) out_path = tmpdir.join("persisted_story.md") Story(graph.story_steps).dump_to_file(out_path.strpath) recovered_stories = extract_stories_from_file(out_path.strpath, default_domain) existing_stories = { s.as_story_string() for s in graph.build_stories(default_domain) } for r in recovered_stories: story_str = r.as_story_string() assert story_str in existing_stories existing_stories.discard(story_str)