コード例 #1
0
        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))
コード例 #2
0
    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
コード例 #3
0
def test_cap_length_with_short_string():
    assert utils.cap_length("my", 3) == "my"
コード例 #4
0
def test_cap_length_without_ellipsis():
    assert utils.cap_length("mystring", 3, append_ellipsis=False) == "mys"
コード例 #5
0
def test_cap_length():
    assert utils.cap_length("mystring", 6) == "mys..."