Loading demo.py +6 −2 Original line number Diff line number Diff line Loading @@ -128,8 +128,12 @@ def web_eq(str1, type1, str2, type2): web.compare(str2, type2) if web.ok: print("ok") else: print(web.eq.left_counterexample, web.eq.right_counterexample, web.eq.inf) elif web.eq: if web.eq.left_counterexample is not None: print(web.eq.left_counterexample) if web.eq.right_counterexample is not None: print(web.eq.right_counterexample) print(web.eq.inf) except RecognitionException as re: print(re) Loading evalweb/evalweb.py +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ def compare(): checker = WebChecker(student_string=student_string, task=student_type) task_solved = checker.compare(teacher_string=teacher_string, teacher_type=teacher_type) if not checker.ok and (checker.eq.left_counterexample or checker.eq.right_counterexample): # TODO don't know wtf was bad if not checker.ok and checker.eq is not None: # TODO don't know wtf was bad extra_word_ce = checker.eq.left_counterexample missing_word_ce = checker.eq.right_counterexample inf = checker.eq.inf Loading evalweb/templates/result.html +7 −6 Original line number Diff line number Diff line Loading @@ -26,14 +26,13 @@ <br><br> {% if compare %} {% if task_solved %} {{ task_solved }}<br> Špatné řešení. {% endif %} {% if ok %} Správné řešení, jazyky popisované oběma formalismy jsou ekvivalentní. {% elif extra_word_ce or missing_word_ce %} Špatné řešení, jazyky popisované oběma formalismy nejsou ekvivalentní.<br> {% else %} Špatné řešení. {{ task_solved }}<br> {% if extra_word_ce or missing_word_ce %} Jazyky popisované oběma formalismy nejsou ekvivalentní.<br> {% if extra_word_ce %} Příklad slova, které je ve studentově řešení a není v zadaném jazyce: {{ extra_word_ce }} Loading @@ -52,6 +51,8 @@ {% else %} Rozdíl porovnávaných jazyků je konečný. {% endif %} {% endif %} {% endif %} {% else %} Loading evalweb/web_checker.py +24 −21 Original line number Diff line number Diff line import lib.reg as reg from lib.parsing.parser import Parser, ParsingError import signal from lib.checker import dfa_transform, nfa_transform, check_task, check_alphabets, check_empty from lib.checker import transform, dfa_transform, nfa_transform, check_task, check_alphabets, check_empty class WebChecker(): Loading @@ -13,21 +13,22 @@ class WebChecker(): def dfa_task(self, teacher_type, teacher_string, task, student_string): try: student_solution = dfa_transform(student_string, task) teacher_solution = dfa_transform(teacher_string, teacher_type) student_solution = transform(student_string, task) student_dfa = dfa_transform(student_string, task) teacher_dfa = dfa_transform(teacher_string, teacher_type) except ParsingError as ex: #print(ex.args) return("Chyba při parsování.") check_empty(student_solution=student_solution, teacher_solution=teacher_solution) task_solved = check_task(student_solution, task) check_empty(student_solution=student_dfa, teacher_solution=teacher_dfa) alphabets = check_alphabets(student_alpha=student_solution.characters, teacher_alpha=teacher_solution.characters, task=task) # TODO print also alphabets (TODO manage prints for all checkers better alphabets = check_alphabets(student_alpha=student_dfa.characters, teacher_alpha=teacher_dfa.characters, task=task) # TODO return alphabets self.eq = reg.DFA.is_equivalent(student_solution, teacher_solution) task_solved = check_task(student_solution, task) self.eq = reg.DFA.is_equivalent(student_dfa, teacher_dfa) if task_solved == "" and self.eq: self.ok = True Loading Loading @@ -62,20 +63,22 @@ class WebChecker(): # return parser.dfa_to_str(automaton.canonize()) automaton = nfa_transform(self.student_string, student_type) if self.task in {"NFA", "EFA"}: if self.task == "EFA": return parser.nfa_to_str(automaton) automaton = automaton.eliminate_epsilon() if self.task == "NFA": return parser.nfa_to_str(automaton.eliminate_epsilon()) else: return parser.nfa_to_str(automaton) if self.task == "GRA": print(parser.nfa_to_str(automaton)) print(type(automaton)) return parser.reggrammar_to_str(automaton.nfa_to_reggrammar()) return parser.reggrammar_to_str(automaton.nfa_to_reggrammar().eliminate_useless()) if self.task == "REG": if self.task == "REG" and student_type != "REG": return "Tohle není pěkný typ převodu. Nechcete si místo regulárního výrazu vybrat něco jiného?" #return parser.reggrammar_to_str(automaton.nfa_to_regex()) #return parser.regex_to_str(automaton.nfa_to_regex()) except ParsingError as ex: return("Chyba při parsování.") except Exception as ex: print("Error inside of web checker:", ex.args) No newline at end of file lib/checker.py +34 −12 Original line number Diff line number Diff line from typing import Tuple from typing import Tuple, Union from lib import reg from lib.parsing.parser import Parser, ParsingError Loading Loading @@ -30,10 +30,8 @@ def nfa_transform(string: str, automaton_type: str) -> reg.NFA: try: parser = Parser() if automaton_type == "EFA": if automaton_type in {"EFA", "NFA"}: automaton = parser.str_to_nfa(string) elif automaton_type == "NFA": automaton = parser.str_to_nfa(string).eliminate_epsilon() elif automaton_type == "GRA": automaton = parser.str_to_reggrammar(string).reggrammar_to_nfa() elif automaton_type == "REG": Loading @@ -46,31 +44,55 @@ def nfa_transform(string: str, automaton_type: str) -> reg.NFA: except ParsingError as ex: raise ParsingError(ex.args) def transform(string: str, automaton_type: str): try: parser = Parser() if automaton_type in {"DFA", "TOT", "MIN", "TOC", "MIC"}: formalism = parser.str_to_dfa(string) elif automaton_type in {"EFA", "NFA"}: formalism = parser.str_to_nfa(string) elif automaton_type == "GRA": formalism = parser.str_to_reggrammar(string) elif automaton_type == "REG": formalism = parser.str_to_regex(string) def check_task(dfa: reg.DFA, task: str) -> str: return formalism except ParsingError as ex: raise ParsingError(ex.args) def check_task(automaton: Union[reg.DFA, reg.NFA], task: str) -> str: parser = Parser() output = "" if task == "NFA" and isinstance(automaton, reg.NFA) and automaton.has_epsilon(): return "NFA obsahuje ε-kroky." if task not in {"TOT", "MIN", "TOC", "MIC"}: return output if task == "TOT" and not dfa.is_total(): if task == "TOT" and not automaton.is_total(): output = "DFA není totální." if task == "MIN" and not dfa.is_minimal(): if task == "MIN" and not automaton.is_minimal(): output = "DFA není minimální." canonical = dfa.is_canonical() canonical = automaton.is_canonical() if task == "CAN" and not canonical: output = "DFA není kanonický." if task == "TOC" and (not dfa.is_total() or not canonical): if not dfa.is_total(): if task == "TOC" and (not automaton.is_total() or not canonical): if not automaton.is_total(): output = "DFA není totální. " if not canonical: output += "DFA není kanonický." if task == "MIC" and (not dfa.is_minimal() or not canonical): if not dfa.is_minimal(): if task == "MIC" and (not automaton.is_minimal() or not canonical): if not automaton.is_minimal(): output = "DFA není minimální. " if not canonical: output += "DFA není kanonický." Loading Loading
demo.py +6 −2 Original line number Diff line number Diff line Loading @@ -128,8 +128,12 @@ def web_eq(str1, type1, str2, type2): web.compare(str2, type2) if web.ok: print("ok") else: print(web.eq.left_counterexample, web.eq.right_counterexample, web.eq.inf) elif web.eq: if web.eq.left_counterexample is not None: print(web.eq.left_counterexample) if web.eq.right_counterexample is not None: print(web.eq.right_counterexample) print(web.eq.inf) except RecognitionException as re: print(re) Loading
evalweb/evalweb.py +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ def compare(): checker = WebChecker(student_string=student_string, task=student_type) task_solved = checker.compare(teacher_string=teacher_string, teacher_type=teacher_type) if not checker.ok and (checker.eq.left_counterexample or checker.eq.right_counterexample): # TODO don't know wtf was bad if not checker.ok and checker.eq is not None: # TODO don't know wtf was bad extra_word_ce = checker.eq.left_counterexample missing_word_ce = checker.eq.right_counterexample inf = checker.eq.inf Loading
evalweb/templates/result.html +7 −6 Original line number Diff line number Diff line Loading @@ -26,14 +26,13 @@ <br><br> {% if compare %} {% if task_solved %} {{ task_solved }}<br> Špatné řešení. {% endif %} {% if ok %} Správné řešení, jazyky popisované oběma formalismy jsou ekvivalentní. {% elif extra_word_ce or missing_word_ce %} Špatné řešení, jazyky popisované oběma formalismy nejsou ekvivalentní.<br> {% else %} Špatné řešení. {{ task_solved }}<br> {% if extra_word_ce or missing_word_ce %} Jazyky popisované oběma formalismy nejsou ekvivalentní.<br> {% if extra_word_ce %} Příklad slova, které je ve studentově řešení a není v zadaném jazyce: {{ extra_word_ce }} Loading @@ -52,6 +51,8 @@ {% else %} Rozdíl porovnávaných jazyků je konečný. {% endif %} {% endif %} {% endif %} {% else %} Loading
evalweb/web_checker.py +24 −21 Original line number Diff line number Diff line import lib.reg as reg from lib.parsing.parser import Parser, ParsingError import signal from lib.checker import dfa_transform, nfa_transform, check_task, check_alphabets, check_empty from lib.checker import transform, dfa_transform, nfa_transform, check_task, check_alphabets, check_empty class WebChecker(): Loading @@ -13,21 +13,22 @@ class WebChecker(): def dfa_task(self, teacher_type, teacher_string, task, student_string): try: student_solution = dfa_transform(student_string, task) teacher_solution = dfa_transform(teacher_string, teacher_type) student_solution = transform(student_string, task) student_dfa = dfa_transform(student_string, task) teacher_dfa = dfa_transform(teacher_string, teacher_type) except ParsingError as ex: #print(ex.args) return("Chyba při parsování.") check_empty(student_solution=student_solution, teacher_solution=teacher_solution) task_solved = check_task(student_solution, task) check_empty(student_solution=student_dfa, teacher_solution=teacher_dfa) alphabets = check_alphabets(student_alpha=student_solution.characters, teacher_alpha=teacher_solution.characters, task=task) # TODO print also alphabets (TODO manage prints for all checkers better alphabets = check_alphabets(student_alpha=student_dfa.characters, teacher_alpha=teacher_dfa.characters, task=task) # TODO return alphabets self.eq = reg.DFA.is_equivalent(student_solution, teacher_solution) task_solved = check_task(student_solution, task) self.eq = reg.DFA.is_equivalent(student_dfa, teacher_dfa) if task_solved == "" and self.eq: self.ok = True Loading Loading @@ -62,20 +63,22 @@ class WebChecker(): # return parser.dfa_to_str(automaton.canonize()) automaton = nfa_transform(self.student_string, student_type) if self.task in {"NFA", "EFA"}: if self.task == "EFA": return parser.nfa_to_str(automaton) automaton = automaton.eliminate_epsilon() if self.task == "NFA": return parser.nfa_to_str(automaton.eliminate_epsilon()) else: return parser.nfa_to_str(automaton) if self.task == "GRA": print(parser.nfa_to_str(automaton)) print(type(automaton)) return parser.reggrammar_to_str(automaton.nfa_to_reggrammar()) return parser.reggrammar_to_str(automaton.nfa_to_reggrammar().eliminate_useless()) if self.task == "REG": if self.task == "REG" and student_type != "REG": return "Tohle není pěkný typ převodu. Nechcete si místo regulárního výrazu vybrat něco jiného?" #return parser.reggrammar_to_str(automaton.nfa_to_regex()) #return parser.regex_to_str(automaton.nfa_to_regex()) except ParsingError as ex: return("Chyba při parsování.") except Exception as ex: print("Error inside of web checker:", ex.args) No newline at end of file
lib/checker.py +34 −12 Original line number Diff line number Diff line from typing import Tuple from typing import Tuple, Union from lib import reg from lib.parsing.parser import Parser, ParsingError Loading Loading @@ -30,10 +30,8 @@ def nfa_transform(string: str, automaton_type: str) -> reg.NFA: try: parser = Parser() if automaton_type == "EFA": if automaton_type in {"EFA", "NFA"}: automaton = parser.str_to_nfa(string) elif automaton_type == "NFA": automaton = parser.str_to_nfa(string).eliminate_epsilon() elif automaton_type == "GRA": automaton = parser.str_to_reggrammar(string).reggrammar_to_nfa() elif automaton_type == "REG": Loading @@ -46,31 +44,55 @@ def nfa_transform(string: str, automaton_type: str) -> reg.NFA: except ParsingError as ex: raise ParsingError(ex.args) def transform(string: str, automaton_type: str): try: parser = Parser() if automaton_type in {"DFA", "TOT", "MIN", "TOC", "MIC"}: formalism = parser.str_to_dfa(string) elif automaton_type in {"EFA", "NFA"}: formalism = parser.str_to_nfa(string) elif automaton_type == "GRA": formalism = parser.str_to_reggrammar(string) elif automaton_type == "REG": formalism = parser.str_to_regex(string) def check_task(dfa: reg.DFA, task: str) -> str: return formalism except ParsingError as ex: raise ParsingError(ex.args) def check_task(automaton: Union[reg.DFA, reg.NFA], task: str) -> str: parser = Parser() output = "" if task == "NFA" and isinstance(automaton, reg.NFA) and automaton.has_epsilon(): return "NFA obsahuje ε-kroky." if task not in {"TOT", "MIN", "TOC", "MIC"}: return output if task == "TOT" and not dfa.is_total(): if task == "TOT" and not automaton.is_total(): output = "DFA není totální." if task == "MIN" and not dfa.is_minimal(): if task == "MIN" and not automaton.is_minimal(): output = "DFA není minimální." canonical = dfa.is_canonical() canonical = automaton.is_canonical() if task == "CAN" and not canonical: output = "DFA není kanonický." if task == "TOC" and (not dfa.is_total() or not canonical): if not dfa.is_total(): if task == "TOC" and (not automaton.is_total() or not canonical): if not automaton.is_total(): output = "DFA není totální. " if not canonical: output += "DFA není kanonický." if task == "MIC" and (not dfa.is_minimal() or not canonical): if not dfa.is_minimal(): if task == "MIC" and (not automaton.is_minimal() or not canonical): if not automaton.is_minimal(): output = "DFA není minimální. " if not canonical: output += "DFA není kanonický." Loading