Esempio n. 1
0
def test_merge_nodes(domain: Domain, tmp_path: Path):
    from os.path import isfile
    import rasa.shared.core.training_data.loading as core_loading

    story_steps = core_loading.load_data_from_resource(
        "data/test_yaml_stories/stories.yml", domain)
    out_file = str(tmp_path / "graph.html")
    visualization.visualize_stories(
        story_steps,
        domain,
        output_file=out_file,
        max_history=3,
        should_merge_nodes=True,
    )
    assert isfile(out_file)
Esempio n. 2
0
def test_story_visualization_with_training_data(domain: Domain, tmp_path: Path,
                                                nlu_data_path: Text):
    import rasa.shared.core.training_data.loading as core_loading

    story_steps = core_loading.load_data_from_resource(
        "data/test_yaml_stories/stories.yml", domain)
    out_file = tmp_path / "graph.html"
    test_text = "test text"
    test_intent = "affirm"
    generated_graph = visualization.visualize_stories(
        story_steps,
        domain,
        output_file=str(out_file),
        max_history=3,
        should_merge_nodes=False,
        nlu_training_data=TrainingData(
            [Message({
                TEXT: test_text,
                INTENT: test_intent
            })]),
    )

    assert test_text in out_file.read_text()
    assert test_intent not in out_file.read_text()

    assert len(generated_graph.nodes()) == 51
    assert len(generated_graph.edges()) == 56
Esempio n. 3
0
def test_story_visualization_with_merging(domain: Domain):
    import rasa.shared.core.training_data.loading as core_loading

    story_steps = core_loading.load_data_from_resource(
        "data/test_yaml_stories/stories.yml", domain)
    generated_graph = visualization.visualize_stories(story_steps,
                                                      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(domain: Domain, tmp_path: Path):
    import rasa.shared.core.training_data.loading as core_loading

    story_steps = core_loading.load_data_from_resource(
        "data/test_yaml_stories/stories.yml", domain)
    out_file = tmp_path / "graph.html"
    generated_graph = visualization.visualize_stories(
        story_steps,
        domain,
        output_file=str(out_file),
        max_history=3,
        should_merge_nodes=False,
    )

    assert str(None) not in out_file.read_text()
    assert "/affirm" in out_file.read_text()
    assert len(generated_graph.nodes()) == 51
    assert len(generated_graph.edges()) == 56
Esempio n. 5
0
def test_graph_persistence(domain: Domain, tmp_path: Path):
    from os.path import isfile
    from networkx.drawing import nx_pydot
    import rasa.shared.core.training_data.loading as core_loading

    story_steps = core_loading.load_data_from_resource(
        "data/test_yaml_stories/stories.yml", domain)
    out_file = str(tmp_path / "graph.html")
    generated_graph = visualization.visualize_stories(
        story_steps,
        domain,
        output_file=out_file,
        max_history=3,
        should_merge_nodes=False,
    )

    generated_graph = nx_pydot.to_pydot(generated_graph)

    assert isfile(out_file)

    content = rasa.shared.utils.io.read_file(out_file)

    assert "isClient = true" in content
    assert "graph = `{}`".format(generated_graph.to_string()) in content