コード例 #1
0
ファイル: structures.py プロジェクト: githubclj/rasa_core
        def ensure_checkpoint_is_drawn(c):
            if c.name not in nodes:
                next_node_idx[0] += 1
                nodes[c.name] = next_node_idx[0]

                if c.name.startswith(GENERATED_CHECKPOINT_PREFIX):
                    # colors generated checkpoints based on their hash
                    color = ColorHash(c.name[-GENERATED_HASH_LENGTH:]).hex
                    G.add_node(next_node_idx[0],
                               label=utils.cap_length(c.name),
                               style="filled",
                               fillcolor=color)
                else:
                    G.add_node(next_node_idx[0], label=utils.cap_length(c.name))
コード例 #2
0
ファイル: structures.py プロジェクト: prenigma/testfou
        def ensure_checkpoint_is_drawn(cp):
            if cp.name not in nodes:
                next_node_idx[0] += 1
                nodes[cp.name] = next_node_idx[0]

                if cp.name.startswith(GENERATED_CHECKPOINT_PREFIX):
                    # colors generated checkpoints based on their hash
                    color = ColorHash(cp.name[-GENERATED_HASH_LENGTH:]).hex
                    graph.add_node(next_node_idx[0],
                                   label=utils.cap_length(cp.name),
                                   style="filled",
                                   fillcolor=color)
                else:
                    graph.add_node(next_node_idx[0],
                                   label=utils.cap_length(cp.name))
コード例 #3
0
ファイル: structures.py プロジェクト: prenigma/testfou
    def visualize(self, output_file=None):
        import networkx as nx
        from rasa_core.training import visualization
        from colorhash import ColorHash

        graph = nx.MultiDiGraph()
        next_node_idx = [0]
        nodes = {"STORY_START": 0, "STORY_END": -1}

        def ensure_checkpoint_is_drawn(cp):
            if cp.name not in nodes:
                next_node_idx[0] += 1
                nodes[cp.name] = next_node_idx[0]

                if cp.name.startswith(GENERATED_CHECKPOINT_PREFIX):
                    # colors generated checkpoints based on their hash
                    color = ColorHash(cp.name[-GENERATED_HASH_LENGTH:]).hex
                    graph.add_node(next_node_idx[0],
                                   label=utils.cap_length(cp.name),
                                   style="filled",
                                   fillcolor=color)
                else:
                    graph.add_node(next_node_idx[0],
                                   label=utils.cap_length(cp.name))

        graph.add_node(nodes["STORY_START"],
                       label="START",
                       fillcolor="green",
                       style="filled")
        graph.add_node(nodes["STORY_END"],
                       label="END",
                       fillcolor="red",
                       style="filled")

        for step in self.story_steps:
            next_node_idx[0] += 1
            step_idx = next_node_idx[0]

            graph.add_node(next_node_idx[0],
                           label=utils.cap_length(step.block_name),
                           style="filled",
                           fillcolor="lightblue",
                           shape="rect")

            for c in step.start_checkpoints:
                ensure_checkpoint_is_drawn(c)
                graph.add_edge(nodes[c.name], step_idx)
            for c in step.end_checkpoints:
                ensure_checkpoint_is_drawn(c)
                graph.add_edge(step_idx, nodes[c.name])

            if not step.end_checkpoints:
                graph.add_edge(step_idx, nodes["STORY_END"])

        if output_file:
            visualization.persist_graph(graph, output_file)

        return graph
コード例 #4
0
ファイル: structures.py プロジェクト: githubclj/rasa_core
    def visualize(self, output_file=None):
        import networkx as nx
        from rasa_core.training import visualization
        from colorhash import ColorHash

        G = nx.MultiDiGraph()
        next_node_idx = [0]
        nodes = {"STORY_START": 0, "STORY_END": -1}

        def ensure_checkpoint_is_drawn(c):
            if c.name not in nodes:
                next_node_idx[0] += 1
                nodes[c.name] = next_node_idx[0]

                if c.name.startswith(GENERATED_CHECKPOINT_PREFIX):
                    # colors generated checkpoints based on their hash
                    color = ColorHash(c.name[-GENERATED_HASH_LENGTH:]).hex
                    G.add_node(next_node_idx[0],
                               label=utils.cap_length(c.name),
                               style="filled",
                               fillcolor=color)
                else:
                    G.add_node(next_node_idx[0], label=utils.cap_length(c.name))

        G.add_node(nodes["STORY_START"],
                   label="START", fillcolor="green", style="filled")
        G.add_node(nodes["STORY_END"],
                   label="END", fillcolor="red", style="filled")

        for step in self.story_steps:
            next_node_idx[0] += 1
            step_idx = next_node_idx[0]

            G.add_node(next_node_idx[0],
                       label=utils.cap_length(step.block_name),
                       style="filled",
                       fillcolor="lightblue",
                       shape="box")

            for c in step.start_checkpoints:
                ensure_checkpoint_is_drawn(c)
                G.add_edge(nodes[c.name], step_idx)
            for c in step.end_checkpoints:
                ensure_checkpoint_is_drawn(c)
                G.add_edge(step_idx, nodes[c.name])

            if not step.end_checkpoints:
                G.add_edge(step_idx, nodes["STORY_END"])

        if output_file:
            visualization.persist_graph(G, output_file)

        return G
コード例 #5
0
def test_cap_length_with_short_string():
    assert utils.cap_length("my", 3) == "my"
コード例 #6
0
def test_cap_length_without_ellipsis():
    assert utils.cap_length("mystring", 3, append_ellipsis=False) == "mys"
コード例 #7
0
def test_cap_length():
    assert utils.cap_length("mystring", 6) == "mys..."
コード例 #8
0
ファイル: test_utils.py プロジェクト: rohitjun08/rasa_core
def test_cap_length_with_short_string():
    assert utils.cap_length("my", 3) == "my"
コード例 #9
0
ファイル: test_utils.py プロジェクト: rohitjun08/rasa_core
def test_cap_length_without_ellipsis():
    assert utils.cap_length("mystring", 3,
                            append_ellipsis=False) == "mys"
コード例 #10
0
ファイル: test_utils.py プロジェクト: rohitjun08/rasa_core
def test_cap_length():
    assert utils.cap_length("mystring", 6) == "mys..."