def from_networkx(cls, graph): """ Import a networkx graph into an finite state automaton. \ The imported graph requires to have the good format, i.e. to come \ from the function to_networkx Parameters ---------- graph : The graph representation of the automaton Returns ------- enfa : A epsilon nondeterministic finite automaton read from the graph TODO ------- * We lose the type of the node value if going through a dot file * Explain the format """ enfa = finite_automaton.EpsilonNFA() for s_from in graph: for s_to in graph[s_from]: for transition in graph[s_from][s_to].values(): if "label" in transition: enfa.add_transition(s_from, transition["label"], s_to) for node in graph.nodes: if graph.nodes[node].get("is_start", False): enfa.add_start_state(node) if graph.nodes[node].get("is_final", False): enfa.add_final_state(node) return enfa
def _initialize_enfa(self): self._enfa = finite_automaton.EpsilonNFA()