Beispiel #1
0
    def export_stories(self):
        # type: () -> Text
        """Dump the tracker as a story in the Rasa Core story format.

        Returns the dumped tracker as a string."""
        from rasa_core.training.structures import Story

        story = Story.from_events(self.applied_events())
        return story.as_story_string(flat=True)
Beispiel #2
0
def test_persist_and_read_test_story(tmpdir, default_domain):
    graph = extract_story_graph_from_file("data/test_stories/stories.md",
                                          default_domain)
    out_path = tmpdir.join("persisted_story.md")
    Story(graph.story_steps).dump_to_file(out_path.strpath)

    recovered_trackers = extract_trackers_from_file(out_path.strpath,
                                                    default_domain,
                                                    BinaryFeaturizer())
    existing_trackers = extract_trackers_from_file(
        "data/test_stories/stories.md", default_domain, BinaryFeaturizer())
    existing_stories = {t.export_stories() for t in existing_trackers}
    for t in recovered_trackers:
        story_str = t.export_stories()
        assert story_str in existing_stories
        existing_stories.discard(story_str)
Beispiel #3
0
def _export_stories(tracker):
    # export current stories and quit
    file_prompt = ("File to export to (if file exists, this "
                   "will append the stories) "
                   "[{}]: ").format(DEFAULT_FILE_EXPORT_PATH)
    export_file_path = utils.request_input(prompt=file_prompt)

    if not export_file_path:
        export_file_path = DEFAULT_FILE_EXPORT_PATH

    parsed_events = events.deserialise_events(tracker.get("events", []))

    s = Story.from_events(parsed_events)

    with io.open(export_file_path, 'a') as f:
        f.write(s.as_story_string(flat=True) + "\n")
Beispiel #4
0
def test_persist_and_read_test_story(tmpdir, default_domain):
    graph = training.extract_story_graph("data/test_stories/stories.md",
                                         default_domain)
    out_path = tmpdir.join("persisted_story.md")
    Story(graph.story_steps).dump_to_file(out_path.strpath)

    recovered_trackers = training.load_data(out_path.strpath,
                                            default_domain,
                                            use_story_concatenation=False,
                                            tracker_limit=1000,
                                            remove_duplicates=False)
    existing_trackers = training.load_data("data/test_stories/stories.md",
                                           default_domain,
                                           use_story_concatenation=False,
                                           tracker_limit=1000,
                                           remove_duplicates=False)
    existing_stories = {t.export_stories() for t in existing_trackers}
    for t in recovered_trackers:
        story_str = t.export_stories()
        assert story_str in existing_stories
        existing_stories.discard(story_str)