|
7 | 7 | from evaluation_function.parsing.tree_builder import * |
8 | 8 |
|
9 | 9 |
|
10 | | -# def parse_response(response: str) -> tuple[bool, Formula | str]: |
11 | | - |
12 | | -# response = response.strip() |
13 | | - |
14 | | -# # binaryOperators = ["↔","→","∨","∧"] |
15 | | -# # TODO: keep this mapping somewhere else for maintainability |
16 | | -# binaryOperators = { |
17 | | -# "↔" : Biconditional, |
18 | | -# "→" : Implication, |
19 | | -# "∨" : Disjunction, |
20 | | -# "∧" : Conjunction |
21 | | -# } |
22 | | - |
23 | | -# for binaryOperator in binaryOperators.keys(): |
24 | | - |
25 | | -# if binaryOperator in response: |
26 | | -# split_index = response.rindex(binaryOperator) |
27 | | - |
28 | | -# left = response[:split_index] |
29 | | -# right = response[split_index+1:] |
30 | | - |
31 | | -# # check left and right not empty strings |
32 | | -# if not left: |
33 | | -# return (False, f"missing text on left of {binaryOperator}") |
34 | | -# elif not right: |
35 | | -# return (False, f"missing text on right of {binaryOperator}") |
36 | | - |
37 | | -# parse_left = parse_response(left) |
38 | | -# parse_right = parse_response(right) |
39 | | - |
40 | | -# error = False |
41 | | -# err_msgs = [] |
42 | | - |
43 | | -# if not parse_left[0]: |
44 | | -# error = True |
45 | | -# err_msgs.append(parse_left[1]) |
46 | | - |
47 | | -# if not parse_right[0]: |
48 | | -# error = True |
49 | | -# err_msgs.append(parse_right[1]) |
50 | | - |
51 | | -# if error: |
52 | | -# return (False, err_msgs.join("\n")) |
53 | | - |
54 | | -# # both sides are find and valid |
55 | | -# result = binaryOperators[binaryOperator](parse_left[1], parse_right[1]) |
56 | | -# return (True, result) |
57 | | - |
58 | | - |
59 | | -# # TODO: keep this mapping somewhere else for maintainability |
60 | | -# unaryOperators = { |
61 | | -# "¬" : Negation |
62 | | -# } |
63 | | - |
64 | | -# for unaryOperator in unaryOperators.keys(): |
65 | | - |
66 | | -# #unary operator must syntactically be at the start of the string |
67 | | -# if response[0] == unaryOperator: |
68 | | - |
69 | | -# right = response[1:] |
70 | | -# #check not empty |
71 | | -# if not right: |
72 | | -# return (False, f"missing text on right of {unaryOperator}") |
73 | | - |
74 | | -# parse_right = parse_response(right) |
75 | | -# if not parse_right[0]: |
76 | | -# return parse_right |
77 | | - |
78 | | -# result = unaryOperators[unaryOperator](parse_right[1]) |
79 | | -# return (True, result) |
80 | | - |
81 | | -# # check if the formual is just True or Falsity |
82 | | - |
83 | | -# singletons = { # not sure what the official term for these symbols is |
84 | | -# "⊤" : Truth, |
85 | | -# "⊥" : Falsity |
86 | | -# } |
87 | | - |
88 | | -# for singleton in singletons: |
89 | | - |
90 | | -# if len(response) > 1 and singleton in response: |
91 | | -# return (False, f"not allowed to use {singleton} in the atom identifier") |
92 | | - |
93 | | -# elif response == singleton: |
94 | | -# result = singletons[singleton]() |
95 | | -# return (True, result) |
96 | | - |
97 | | -# # response is likely an atom identifier |
98 | | - |
99 | | -# return (True, Atom(response)) |
100 | | - |
101 | | - |
102 | | - |
103 | | - |
104 | | - |
105 | | - |
106 | 10 | def evaluation_function( |
107 | 11 | response: Any, |
108 | 12 | answer: Any, |
@@ -149,22 +53,22 @@ def evaluation_function( |
149 | 53 | tautology = params.get("tautology", False) |
150 | 54 | satisfiability = params.get("satisfiability", False) |
151 | 55 |
|
| 56 | + |
152 | 57 | #check that 1 and only 1 param is selected |
153 | | - if not (equivalence ^ tautology ^ satisfiability): |
| 58 | + num_selected = sum([equivalence, tautology, satisfiability]) |
154 | 59 |
|
155 | | - if not (equivalence or tautology or satisfiability): |
156 | | - #no params selected |
157 | | - return Result( |
158 | | - is_correct=False, |
159 | | - feedback_items=[("invalid param", "please select a param")] |
160 | | - ) |
161 | | - |
162 | | - # more than one param selected |
| 60 | + if num_selected == 0: |
| 61 | + return Result( |
| 62 | + is_correct=False, |
| 63 | + feedback_items=[("invalid param", "please select a param")] |
| 64 | + ) |
| 65 | + elif num_selected > 1: |
163 | 66 | return Result( |
164 | 67 | is_correct=False, |
165 | 68 | feedback_items=[("invalid param", "please only select 1 param")] |
166 | 69 | ) |
167 | 70 |
|
| 71 | + |
168 | 72 |
|
169 | 73 | feedback = None |
170 | 74 | is_correct = False |
|
0 commit comments