This repository has been archived by the owner on Dec 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL2_Int1_8_main.py
88 lines (70 loc) · 2.15 KB
/
L2_Int1_8_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
import os
import re
from L2_Int1_8_automaton import Automaton
from L2_Int1_8_determinization import determinize
from L2_Int1_8_completion import complete
from L2_Int1_8_minimization import minimize
from L2_Int1_8_complementation import complement
from L2_Int1_8_standardization import standardize
from L2_Int1_8_recognition import recognize
FILE_FORMAT = "Int1-8-%d.txt"
def main():
automatas = set()
for file in os.listdir("."):
match = re.match(FILE_FORMAT.replace(r"%d", r"(\d+)"), file)
if match:
automatas.add(int(match.group(1)))
automaton_list = ", ".join(map(str, sorted(automatas)))
try:
while True:
automaton_id = None
while automaton_id is None or automaton_id not in automatas:
if automaton_id is not None:
automaton_id = input("Invalid ID, use one amongst %s: " % automaton_list)
else:
automaton_id = input("Enter the ID of the automaton to use amongst %s: " % automaton_list)
try:
automaton_id = int(automaton_id)
except ValueError:
if automaton_id.lower() in ["quit", "exit", "end", "q"]:
break
if not automaton_id in automatas:
break
print()
print("1. Reading automaton...")
file_path = FILE_FORMAT % automaton_id
automaton = Automaton.read_from_file(file_path)
automaton.display()
print()
print("2. Determinizing and completing automaton...")
automaton = determinize(automaton)
automaton = complete(automaton)
automaton.display()
print()
print("3. Minimizing automaton...")
automaton = minimize(automaton)
automaton.display()
print()
print("4. Starting word recognition...")
recognize(automaton)
print()
print("5. Creating an automaton which recognizes the complementary language...")
automaton = complement(automaton)
automaton.display()
print()
print("6. Starting word recognition...")
recognize(automaton)
print()
print("7. Standardizing automaton...")
automaton = standardize(automaton)
automaton.display()
print()
print("8. Starting word recognition...")
recognize(automaton)
except KeyboardInterrupt:
print()
pass
print("Quitting...")
if __name__ == "__main__":
main()