Esempio n. 1
0
def test_graph_persistence(default_domain, tmpdir):
    from os.path import isfile
    from networkx.drawing import nx_pydot
    import io

    from rasa_core.training.dsl import StoryFileReader
    from rasa_core.interpreter import RegexInterpreter
    story_steps = StoryFileReader.read_from_file(
        "data/test_stories/stories.md",
        default_domain,
        interpreter=RegexInterpreter())
    out_file = tmpdir.join("graph.html").strpath
    generated_graph = visualization.visualize_stories(story_steps,
                                                      default_domain,
                                                      output_file=out_file,
                                                      max_history=3,
                                                      should_merge_nodes=False)

    generated_graph = nx_pydot.to_pydot(generated_graph)

    assert isfile(out_file)

    with io.open(out_file, 'r') as graph_file:
        content = graph_file.read()

    assert 'isClient = true' in content
    assert "graph = `{}`".format(generated_graph.to_string()) in content
Esempio n. 2
0
def extract_story_graph_from_file(
        filename,  # type: Text
        domain,  # type: Domain
        interpreter=RegexInterpreter()  # type: NaturalLanguageInterpreter
):
    # type: (...) -> StoryGraph

    story_steps = StoryFileReader.read_from_file(filename, domain, interpreter)
    return StoryGraph(story_steps)
Esempio n. 3
0
def test_story_visualization_with_merging(default_domain):
    story_steps = StoryFileReader.read_from_file(
            "data/test_stories/stories.md", default_domain,
            interpreter=RegexInterpreter())
    generated_graph = visualize_stories(story_steps, default_domain,
                                        output_file=None,
                                        max_history=3,
                                        should_merge_nodes=True)
    assert 15 < len(generated_graph.nodes()) < 33

    assert 20 < len(generated_graph.edges()) < 33
Esempio n. 4
0
def test_story_visualization_with_merging(default_domain):
    story_steps = StoryFileReader.read_from_file(
            "data/test_stories/stories.md", default_domain,
            interpreter=RegexInterpreter())
    generated_graph = visualize_stories(story_steps, default_domain,
                                        output_file=None,
                                        max_history=3,
                                        should_merge_nodes=True)
    assert 15 < len(generated_graph.nodes()) < 33

    assert 20 < len(generated_graph.edges()) < 33
Esempio n. 5
0
def test_story_visualization(default_domain, tmpdir):
    story_steps = StoryFileReader.read_from_file(
            "data/test_stories/stories.md", default_domain,
            interpreter=RegexInterpreter())
    out_file = tmpdir.join("graph.html").strpath
    generated_graph = visualize_stories(story_steps, default_domain,
                                        output_file=out_file,
                                        max_history=3,
                                        should_merge_nodes=False)

    assert len(generated_graph.nodes()) == 51

    assert len(generated_graph.edges()) == 56
Esempio n. 6
0
def test_story_visualization(default_domain, tmpdir):
    story_steps = StoryFileReader.read_from_file(
            "data/test_stories/stories.md", default_domain,
            interpreter=RegexInterpreter())
    out_file = tmpdir.join("graph.png").strpath
    generated_graph = visualize_stories(story_steps, default_domain,
                                        output_file=out_file,
                                        max_history=3,
                                        should_merge_nodes=False)

    assert len(generated_graph.nodes()) == 51

    assert len(generated_graph.edges()) == 56
Esempio n. 7
0
def extract_story_graph(
    resource_name,  # type: Text
    domain,  # type: Domain
    interpreter=None  # type: Optional[NaturalLanguageInterpreter]
):
    # type: (...) -> StoryGraph
    from rasa_core.interpreter import RegexInterpreter
    from rasa_core.training.dsl import StoryFileReader
    from rasa_core.training.structures import StoryGraph

    if not interpreter:
        interpreter = RegexInterpreter()
    story_steps = StoryFileReader.read_from_folder(resource_name, domain,
                                                   interpreter)
    return StoryGraph(story_steps)
Esempio n. 8
0
def extract_story_graph(
        resource_name,  # type: Text
        domain,  # type: Domain
        interpreter=None  # type: Optional[NaturalLanguageInterpreter]
):
    # type: (...) -> StoryGraph
    from rasa_core.interpreter import RegexInterpreter
    from rasa_core.training.dsl import StoryFileReader
    from rasa_core.training.structures import StoryGraph

    if not interpreter:
        interpreter = RegexInterpreter()
    story_steps = StoryFileReader.read_from_folder(resource_name,
                                                   domain, interpreter)
    return StoryGraph(story_steps)
Esempio n. 9
0
    def visualize(self,
                  resource_name,  # type: Text
                  output_file,  # type: Text
                  max_history,  # type: int
                  nlu_training_data=None,  # type: Optional[Text]
                  should_merge_nodes=True,  # type: bool
                  fontsize=12  # type: int
                  ):
        # type: (...) -> None
        from rasa_core.training.visualization import visualize_stories
        from rasa_core.training.dsl import StoryFileReader
        """Visualize the loaded training data from the resource."""

        story_steps = StoryFileReader.read_from_folder(resource_name,
                                                       self.domain)
        visualize_stories(story_steps, self.domain, output_file, max_history,
                          self.interpreter, nlu_training_data,
                          should_merge_nodes, fontsize)
Esempio n. 10
0
    def visualize(self,
                  resource_name,  # type: Text
                  output_file,  # type: Text
                  max_history,  # type: int
                  nlu_training_data=None,  # type: Optional[Text]
                  should_merge_nodes=True,  # type: bool
                  fontsize=12  # type: int
                  ):
        # type: (...) -> None
        from rasa_core.training.visualization import visualize_stories
        from rasa_core.training.dsl import StoryFileReader
        """Visualize the loaded training data from the resource."""

        story_steps = StoryFileReader.read_from_folder(resource_name,
                                                       self.domain)
        visualize_stories(story_steps, self.domain, output_file, max_history,
                          self.interpreter, nlu_training_data,
                          should_merge_nodes, fontsize)
Esempio n. 11
0
def extract_story_graph(
    resource_name: Text,
    domain: 'Domain',
    interpreter: Optional['NaturalLanguageInterpreter'] = None,
    use_e2e: bool = False,
    exclusion_percentage: int = None
) -> 'StoryGraph':
    from rasa_core.interpreter import RegexInterpreter
    from rasa_core.training.dsl import StoryFileReader
    from rasa_core.training.structures import StoryGraph

    if not interpreter:
        interpreter = RegexInterpreter()
    story_steps = StoryFileReader.read_from_folder(
        resource_name,
        domain, interpreter,
        use_e2e=use_e2e,
        exclusion_percentage=exclusion_percentage)
    return StoryGraph(story_steps)
Esempio n. 12
0
    def visualize(self,
                  resource_name: Text,
                  output_file: Text,
                  max_history: Optional[int] = None,
                  nlu_training_data: Optional[Text] = None,
                  should_merge_nodes: bool = True,
                  fontsize: int = 12) -> None:
        from rasa_core.training.visualization import visualize_stories
        from rasa_core.training.dsl import StoryFileReader
        """Visualize the loaded training data from the resource."""

        # if the user doesn't provide a max history, we will use the
        # largest value from any policy
        max_history = max_history or self._max_history()

        story_steps = StoryFileReader.read_from_folder(resource_name,
                                                       self.domain)
        visualize_stories(story_steps, self.domain, output_file, max_history,
                          self.interpreter, nlu_training_data,
                          should_merge_nodes, fontsize)
Esempio n. 13
0
def extract_story_graph(
        resource_name,  # type: Text
        domain,  # type: Domain
        interpreter=None,  # type: Optional[NaturalLanguageInterpreter]
        use_e2e=False,  # type: bool
        exclusion_percentage=None  # type: int
):
    # type: (...) -> StoryGraph
    from rasa_core.interpreter import RegexInterpreter
    from rasa_core.training.dsl import StoryFileReader
    from rasa_core.training.structures import StoryGraph

    if not interpreter:
        interpreter = RegexInterpreter()
    story_steps = StoryFileReader.read_from_folder(
        resource_name,
        domain,
        interpreter,
        use_e2e=use_e2e,
        exclusion_percentage=exclusion_percentage)
    return StoryGraph(story_steps)
Esempio n. 14
0
def get_no_of_stories(stories, domain):
    """Get number of stories in a file."""

    no_stories = len(
        StoryFileReader.read_from_folder(stories, TemplateDomain.load(domain)))
    return no_stories