rasa/core/training/structures.py
def topological_sort(
        graph: Dict[Text, Set[Text]]
    ) -> Tuple[deque, Set[Tuple[Text, Text]]]:
        """Creates a top sort of a directed graph. This is an unstable sorting!

        The function returns the sorted nodes as well as the edges that need
        to be removed from the graph to make it acyclic (and hence, sortable).

        The graph should be represented as a dictionary, e.g.:

        >>> example_graph = {
        ...         "a": set("b", "c", "d"),
        ...         "b": set(),
        ...         "c": set("d"),
        ...         "d": set(),
        ...         "e": set("f"),
        ...         "f": set()}
        >>> StoryGraph.topological_sort(example_graph)
        (deque([u'e', u'f', u'a', u'c', u'd', u'b']), [])
        """

        # noinspection PyPep8Naming
        GRAY, BLACK = 0, 1

        ordered = deque()
        unprocessed = sorted(set(graph))
        visited_nodes = {}

        removed_edges = set()

        def dfs(node):
            visited_nodes[node] = GRAY
            for k in graph.get(node, set()):
                sk = visited_nodes.get(k, None)
                if sk == GRAY:
                    removed_edges.add((node, k))
                    continue
                if sk == BLACK:
                    continue
                unprocessed.remove(k)
                dfs(k)
            ordered.appendleft(node)
            visited_nodes[node] = BLACK

        while unprocessed:
            dfs(unprocessed.pop())
        return ordered, removed_edges
Creates a top sort of a directed graph. This is an unstable sorting!

        The function returns the sorted nodes as well as the edges that need
        to be removed from the graph to make it acyclic (and hence, sortable).

        The graph should be represented as a dictionary, e.g.:

        >>> example_graph = {
        ...         "a": set("b", "c", "d"),
        ...         "b": set(),
        ...         "c": set("d"),
        ...         "d": set(),
        ...         "e": set("f"),
        ...         "f": set()}
        >>> StoryGraph.topological_sort(example_graph)
        (deque([u'e', u'f', u'a', u'c', u'd', u'b']), [])
        
Creates a top sort of a directed graph. This is an unstable sorting.
The function returns the sorted nodes as well as the edges that need
to be removed from the graph to make it acyclic (and hence, sortable).

The graph should be represented as a dictionary, e.g..


Creates a top sort of a directed graph . This is an unstable sorting . The function returns the sorted nodes as well as the edges that need to be removed from the graph to make it acyclic ( and hence sortable ) . The graph should be represented as a dictionary e . g ..
def topological_sort(
        graph: Dict[Text, Set[Text]]
    ) -> Tuple[deque, Set[Tuple[Text, Text]]]:
        GRAY, BLACK = 0, 1
        ordered = deque()
        unprocessed = sorted(set(graph))
        visited_nodes = {}
        removed_edges = set()
        def dfs(node):
            visited_nodes[node] = GRAY
            for k in graph.get(node, set()):
                sk = visited_nodes.get(k, None)
                if sk == GRAY:
                    removed_edges.add((node, k))
                    continue
                if sk == BLACK:
                    continue
                unprocessed.remove(k)
                dfs(k)
            ordered.appendleft(node)
            visited_nodes[node] = BLACK
        while unprocessed:
            dfs(unprocessed.pop())
        return ordered, removed_edges
def topological_sort ( graph : Dict [ Text , Set [ Text ] ] ) -> Tuple [ deque , Set [ Tuple [ Text , Text ] ] ] : GRAY , BLACK = 0 , 1 ordered = deque ( ) unprocessed = sorted ( set ( graph ) ) visited_nodes = { } removed_edges = set ( ) def dfs ( node ) : visited_nodes [ node ] = GRAY for k in graph . get ( node , set ( ) ) : sk = visited_nodes . get ( k , None ) if sk == GRAY : removed_edges . add ( ( node , k ) ) continue if sk == BLACK : continue unprocessed . remove ( k ) dfs ( k ) ordered . appendleft ( node ) visited_nodes [ node ] = BLACK while unprocessed : dfs ( unprocessed . pop ( ) ) return ordered , removed_edges
Creates a top sort of a directed graph.
Creates a top sort of a directed graph .
"""Creates a top sort of a directed graph. This is an unstable sorting!

        The function returns the sorted nodes as well as the edges that need
        to be removed from the graph to make it acyclic (and hence, sortable).

        The graph should be represented as a dictionary, e.g.:

        >>> example_graph = {
        ...         "a": set("b", "c", "d"),
        ...         "b": set(),
        ...         "c": set("d"),
        ...         "d": set(),
        ...         "e": set("f"),
        ...         "f": set()}
        >>> StoryGraph.topological_sort(example_graph)
        (deque([u'e', u'f', u'a', u'c', u'd', u'b']), [])
        """ # noinspection PyPep8Naming
graph
Dict[Text, Set[Text]]