Skip to content

Commit 38f31f3

Browse files
committed
written doc for dev and re-wrto how params are processed for evaluation_function
1 parent 88f9171 commit 38f31f3

3 files changed

Lines changed: 116 additions & 31 deletions

File tree

docs/dev.md

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
11
# YourFunctionName
2-
*Brief description of what this evaluation function does, from the developer perspective*
32

4-
## Inputs
5-
*Specific input parameters which can be supplied when the `eval` command is supplied to this function.*
3+
This evaluation function checks if the inputted respons is a valid formula within Propositional Logic.
64

7-
## Outputs
8-
*Output schema/values for this function*
5+
Select the sort of evlauation you want to using the check box. Make sure to only select 1.
96

10-
## Examples
11-
*List of example inputs and outputs for this function, each under a different sub-heading*
127

13-
### Simple Evaluation
8+
## Inputs
149

15-
```python
10+
```json
1611
{
17-
"example": {
18-
"Something": "something"
12+
"response":"<str>",
13+
"answer":"<str>",
14+
"params": {
15+
"equivalence": "<bool>",
16+
"tautology": "<bool>",
17+
"satisfiability": "<bool>",
1918
}
2019
}
2120
```
2221

23-
```python
22+
### `equivalence`
23+
24+
checks if response formula and answer formula are equivalent
25+
26+
### `tautology`
27+
28+
checks if response formula is a tautology
29+
30+
### `satisfiability`
31+
32+
checks if response formula is satisfiabiable
33+
34+
## Outputs
35+
36+
```json
2437
{
25-
"example": {
26-
"Something": "something"
27-
}
38+
"is_correct": "<bool>",
39+
"feedback_items": "<str>"
2840
}
29-
```
41+
```
42+
43+
### `is_correct`
44+
45+
boolean of the correctness of response
46+
47+
### `feedback_items`
48+
49+
the list of errors that occurred in the evaluation process

evaluation_function/evaluation.py

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,28 @@ def evaluation_function(
143143
)
144144

145145

146-
# this can be "equivilance", "tautology", "satisfiability"
147-
#potnetially can be switched with classes
148-
action = params.get("action", None)
146+
# check only one of "equivilance", "tautology", "satisfiability" is selected
147+
148+
equivalence = params.get("equivalence", False)
149+
tautology = params.get("tautology", False)
150+
satisfiability = params.get("satisfiability", False)
151+
152+
#check that 1 and only 1 param is selected
153+
if not (equivalence ^ tautology ^ satisfiability):
154+
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
163+
return Result(
164+
is_correct=False,
165+
feedback_items=[("invalid param", "please only select 1 param")]
166+
)
167+
149168

150169
feedback = None
151170
is_correct = False
@@ -179,15 +198,43 @@ def evaluation_function(
179198
feedback_items=[(BuildError, str(e))]
180199
)
181200

182-
#swtich on action
183-
184-
match action:
185-
case "tautology":
186-
is_correct = TautologyEvaluator(formula).evaluate()
201+
202+
if equivalence:
203+
204+
answer_tokenizer = Tokenizer(answer)
205+
answer_tokens = []
206+
207+
# tokenise answer
208+
try:
209+
while True:
210+
answer_token = answer_tokenizer.next_token()
211+
answer_tokens.append(answer_token)
212+
if answer_token.type == TokenType.EOF:
213+
break
214+
215+
except ValueError as e:
216+
return Result(
217+
is_correct=False,
218+
feedback_items=[(ValueError, str(e))]
219+
)
220+
221+
# parse answer tokens into Formula
222+
try:
223+
answer_builder = TreeBuilder(answer_tokens)
224+
answer_formula = answer_builder.build()
225+
226+
except BuildError as e:
227+
return Result(
228+
is_correct=False,
229+
feedback_items=[(BuildError, str(e))]
230+
)
231+
232+
is_correct = EquivalenceEvaluator(formula, answer_formula).evaluate()
187233

188-
case "satisfiability":
189-
is_correct = SatisfiabilityEvaluator(formula).evaluate()
190234

191-
# equivalence
235+
elif tautology:
236+
is_correct = TautologyEvaluator(formula).evaluate()
237+
elif satisfiability:
238+
is_correct = SatisfiabilityEvaluator(formula).evaluate()
192239

193240
return Result(is_correct=is_correct)

evaluation_function/evaluation_test.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def test_evaluation_default(self):
3131

3232
def test_check_tautology(self):
3333

34-
response, answer, params = "p ∨ ¬p", "", {"action": "tautology"}
34+
response, answer, params = "p ∨ ¬p", "", {"tautology": True}
3535

3636
result = evaluation_function(response, answer, params).to_dict()
3737

3838
self.assertTrue(result.get("is_correct"))
3939

4040
def test_check_tautology_fail(self):
4141

42-
response, answer, params = "p ∧ ¬p", "", {"action": "tautology"}
42+
response, answer, params = "p ∧ ¬p", "", {"tautology": True}
4343

4444
result = evaluation_function(response, answer, params).to_dict()
4545

@@ -48,16 +48,34 @@ def test_check_tautology_fail(self):
4848

4949
def test_check_satisfiability(self):
5050

51-
response, answer, params = "p ∧ q", "", {"action": "satisfiability"}
51+
response, answer, params = "p ∧ q", "", {"satisfiability": True}
5252

5353
result = evaluation_function(response, answer, params).to_dict()
5454

5555
self.assertTrue(result.get("is_correct"))
5656

5757
def test_check_satisfiability_fail(self):
5858

59-
response, answer, params = "p ∧ ¬p", "", {"action": "satisfiability"}
59+
response, answer, params = "p ∧ ¬p", "", {"satisfiability": True}
6060

6161
result = evaluation_function(response, answer, params).to_dict()
6262

6363
self.assertFalse(result.get("is_correct"))
64+
65+
66+
def test_check_equivalence(self):
67+
68+
response, answer, params = "p ∧ q", "p ∧ (q ∨ q)", {"equivalence": True}
69+
70+
result = evaluation_function(response, answer, params).to_dict()
71+
72+
self.assertTrue(result.get("is_correct"))
73+
74+
def test_check_equivalence_fail(self):
75+
76+
response, answer, params = "p ∧ q", "p", {"equivalence": True}
77+
78+
result = evaluation_function(response, answer, params).to_dict()
79+
80+
self.assertFalse(result.get("is_correct"))
81+

0 commit comments

Comments
 (0)