-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
31 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from .task_2 import regex_to_min_dfa, create_nfa | ||
from .task2 import regex_to_dfa, graph_to_nfa | ||
from .task_1 import graph_info, create_labeled_two_cycle_graph | ||
|
||
__all__ = [ | ||
"graph_info", | ||
"create_labeled_two_cycle_graph", | ||
"regex_to_min_dfa", | ||
"create_nfa", | ||
"regex_to_dfa", | ||
"graph_to_nfa", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pyformlang.regular_expression import * | ||
from pyformlang.finite_automaton import * | ||
from networkx import MultiDiGraph | ||
from typing import Set | ||
|
||
|
||
def regex_to_dfa(regex: str) -> DeterministicFiniteAutomaton: | ||
return Regex(regex).to_epsilon_nfa().minimize() | ||
|
||
|
||
def graph_to_nfa( | ||
graph: MultiDiGraph, start_states: Set[int], final_states: Set[int] | ||
) -> NondeterministicFiniteAutomaton: | ||
nfa = NondeterministicFiniteAutomaton() | ||
|
||
if not start_states: | ||
start_states = set(graph.nodes()) | ||
if not final_states: | ||
final_states = set(graph.nodes()) | ||
|
||
for state in start_states: | ||
nfa.add_start_state(State(state)) | ||
for state in final_states: | ||
nfa.add_final_state(State(state)) | ||
for s, e, label in graph.edges(data="label"): | ||
nfa.add_transition(s, label, e) | ||
|
||
return nfa |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.