@@ -533,6 +533,16 @@ def to_networkx(self) -> MultiDiGraph:
533533 graph .add_edge (s_from .value , s_to .value , label = label_ )
534534 return graph
535535
536+ @classmethod
537+ @abstractmethod
538+ def from_networkx (cls , graph : MultiDiGraph ) -> "FiniteAutomaton" :
539+ """
540+ Import a networkx graph into an finite state automaton. \
541+ The imported graph requires to have the good format, i.e. to come \
542+ from the function to_networkx
543+ """
544+ raise NotImplementedError
545+
536546 def write_as_dot (self , filename : str ) -> None :
537547 """
538548 Write the automaton in dot format into a file
@@ -573,8 +583,7 @@ def get_accepted_words(self, max_length: Optional[int] = None) \
573583 word_to_add = tuple (current_word )
574584 if not self .__try_add (words_by_state [current_state ], word_to_add ):
575585 continue
576- transitions = self ._transition_function .get_transitions_from (
577- current_state )
586+ transitions = self .get_transitions_from (current_state )
578587 for symbol , next_state in transitions :
579588 if next_state in states_leading_to_final :
580589 temp_word = current_word .copy ()
@@ -593,7 +602,7 @@ def _get_states_leading_to_final(self) -> Set[State]:
593602 leading_to_final = self .final_states .copy ()
594603 visited = set ()
595604 states_to_process : deque [Any ] = \
596- deque ((None , start_state ) for start_state in self .start_states )
605+ deque ((None , start_state ) for start_state in self .start_states )
597606 delayed_states = deque ()
598607 while states_to_process :
599608 previous_state , current_state = states_to_process .pop ()
0 commit comments