def test_nfa_to_json(self): """ Tests a correct export to JSON file of a nfa. """ name = 'JSON_test_nfa_1' automata_IO.nfa_to_json(self.nfa_01, name, 'tests/outputs') re_imported_nfa = automata_IO.nfa_json_importer('tests/outputs/' + name + '.json') self.assertDictEqual(self.nfa_01, re_imported_nfa)
def main(): global AFDStates global AFDTransitions global AFDAcceptingStates global AFDAlphabet global AFDInitialState automataDict = automata_IO.nfa_json_importer("./resources/AFN.json") alphabet = automataDict["alphabet"] initialState = "" for state in automataDict["initial_states"]: initialState = state break transitions = automataDict["transitions"] acceptingStates = automataDict["accepting_states"] AFDInitialState = set([initialState]) AFDAlphabet = alphabet buildTransitions(AFDInitialState, transitions, acceptingStates) mapStates() AFD = { 'alphabet': AFDAlphabet, 'states': afdStates(), 'initial_state': "s0", 'accepting_states': afdAcceptingStates(), 'transitions': afdTransitions() } automata_IO.dfa_to_json(AFD, "AFD", "./resources")
def main(): automataDict = automata_IO.nfa_json_importer("./resources/AFN.json") alphabet = automataDict["alphabet"] initialState = "" for state in automataDict["initial_states"]: initialState = state break transitions = automataDict["transitions"] acceptingStates = automataDict["accepting_states"] automata_IO.nfa_to_dot(automataDict, "AFN", "./resources") automata = AFNAutomata(alphabet, initialState, transitions, acceptingStates) AFNProcessScreen(automata)
def test_nfa_json_importer(self): """ Tests a correct nfa import from a JSON file. """ imported = automata_IO.nfa_json_importer( './tests/json/nfa/nfa_json_importer_1.json') self.assertDictEqual(imported, self.dfa_01)
if __name__ == "__main__": automata = Automata() ''' In order to run this program you must to create a file called, i.e., "RE.txt" which has to contain the Regular expresion and the alphabet, such as: 0*.1.0*.1.0*.1.0* 0 1 Where the first line is the RE and the next ones are the alphabet ''' automata.readFile("RE.txt") automata.convertREToPostfix() automata.convertREToNFA() automata.createTransitionMatrix() nfa_example = automata_IO.nfa_json_importer('quintuple_NFA.json') automata_IO.nfa_to_dot(nfa_example, 'graphic_NFA', './') automata.NFA_to_DFA() dfa_example = automata_IO.dfa_json_importer('quintuple_DFA.json') automata_IO.dfa_to_dot(dfa_example, 'graphic_DFA', './') automata.validateStrings() print( "The quintuple for the NFA is in 'quintuple_NFA.json', the graphic is in 'graphic_NFA.dot.svg'" ) print( "The quintuple for the DFA is in 'quintuple_DFA.json', the graphic is in 'graphic_DFA.dot.svg'" )
instance.read_and_store_initial_states(True) instance.read_and_store_accepting_states() instance.read_and_store_dfa_transitions() else: instance.read_and_store_initial_states() instance.read_and_store_accepting_states() instance.read_and_store_nfa_transitions() with open("Part1.json", "w") as file: json.dump(instance.getData(), file) if is_dfa: dfa = automata_IO.dfa_json_importer('Part1.json') automata_IO.dfa_to_dot(dfa, 'dfa') else: nfa = automata_IO.nfa_json_importer('Part1.json') automata_IO.nfa_to_dot(nfa, 'nfa') is_dfa_nfa_selection_exit = True is_exit = True if choice in ["2", 2]: instance = COMP5361() instance.read_and_store_alphabets() instance.read_and_store_states() instance.read_and_store_initial_states() instance.read_and_store_accepting_states() instance.read_and_store_nfa_transitions() instance.nfa_to_dfa_conversion() instance.build_Data() instance.display_nfa_to_dfa_transition_table()