|
112 | 112 |
|
113 | 113 | Depatternize[pattern_] := MapAll[DepatternizePattern, pattern] |
114 | 114 |
|
| 115 | +(*StandardizeEquation: a function that automatically converts all instances |
| 116 | +of the equals sign to the repeated equals sign, so that anything WL would |
| 117 | +parse as an assignment gets parsed instead as an equu |
| 118 | +ation*) |
| 119 | + |
| 120 | +StandardizeEquation[str_]:=FixedPoint[StringReplace["==="->"=="],StringReplace[str,"="->"=="]] |
| 121 | + |
115 | 122 | (*StructureMatchQ: a function that checks whether a user's response \ |
116 | 123 | has the same structure as a given answer template, given a set of \ |
117 | 124 | named variables.*) |
|
158 | 165 | Print["Evaluating Structure"]; |
159 | 166 | namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
160 | 167 | correctQ = StructureMatchQ[ |
161 | | - ToExpression[ToString[response],TraditionalForm], |
162 | | - ToExpression[ToString[answer],TraditionalForm], |
| 168 | + ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
| 169 | + ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm], |
163 | 170 | namedVariables]; |
164 | 171 |
|
165 | 172 | <| |
|
186 | 193 |
|
187 | 194 | SemanticMatchQ[response_,answer_] := Simplify[(response-answer)/.activeFunctionRules] == 0 |
188 | 195 |
|
| 196 | +SemanticMatchQ[response_Equal, answer_Equal] := |
| 197 | + SemanticMatchQ[response[[1]]-response[[2]], answer[[1]]-answer[[2]]]|| |
| 198 | + SemanticMatchQ[response[[1]]-response[[2]], answer[[2]]-answer[[1]]] |
| 199 | + |
189 | 200 | SemanticAndStructureMatchQ[response_,answer_,answerTemplate_,namedVariables_] := |
190 | 201 | TrueQ[SemanticMatchQ[response,answer]&&StructureMatchQ[response,answerTemplate,namedVariables]] |
191 | 202 |
|
192 | 203 | equalQSemantic[answer_, response_, params_] := Module[{correctQ}, |
193 | 204 | Print["Evaluating Semantic"]; |
194 | 205 | correctQ = SemanticMatchQ[ |
195 | | - ToExpression[ToString[response],TraditionalForm], |
196 | | - ToExpression[ToString[answer],TraditionalForm]]; |
| 206 | + ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
| 207 | + ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm]]; |
197 | 208 |
|
198 | 209 | <| |
199 | 210 | "error" -> Null, |
|
206 | 217 | namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
207 | 218 | answerTemplate = ToExpression[Lookup[params,"answer_template",{}],TraditionalForm]; |
208 | 219 | correctQ = SemanticAndStructureMatchQ[ |
209 | | - ToExpression[ToString[response],TraditionalForm], |
210 | | - ToExpression[ToString[answer],TraditionalForm], |
211 | | - ToExpression[ToString[answerTemplate],TraditionalForm], |
| 220 | + ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
| 221 | + ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm], |
| 222 | + ToExpression[StandardizeEquation[ToString[answerTemplate]],TraditionalForm], |
212 | 223 | namedVariables |
213 | 224 | ]; |
214 | 225 |
|
|
247 | 258 | Print["Evaluating Structure"]; |
248 | 259 | namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
249 | 260 | correctQ = StrictStructureMatchQ[ |
250 | | - ToExpression[ToString[response],TraditionalForm], |
251 | | - ToExpression[ToString[answer],TraditionalForm], |
| 261 | + ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
| 262 | + ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm], |
252 | 263 | namedVariables]; |
253 | 264 |
|
254 | 265 | <| |
|
0 commit comments