Skip to content

Commit e24cd0c

Browse files
committed
Comparing structures implemented
1 parent c18690a commit e24cd0c

File tree

1 file changed

+70
-34
lines changed

1 file changed

+70
-34
lines changed

evaluate.m

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(* ::Package:: *)
2+
13
(* Wolfram Language Package *)
24
(* Created by the Wolfram Language Plugin for IntelliJ, see http://wlplugin.halirutan.de/ *)
35

@@ -64,24 +66,24 @@
6466

6567
Options[PatternizeSymbol] = {Atomic -> False};
6668

67-
PatternizeSymbol[a_Symbol, namedVariables_, OptionsPattern[]] /;
69+
PatternizeSymbol[a_Symbol, namedVariables_, OptionsPattern[]] /;
6870
Not[MemberQ[namedVariables, a]] := \!\(\*
6971
TagBox[
7072
StyleBox[
71-
RowBox[{"If", "[",
73+
RowBox[{"If", "[",
7274
RowBox[{
73-
RowBox[{"OptionValue", "[", "Atomic", "]"}], ",",
74-
RowBox[{"(",
75-
RowBox[{"Optional", "[",
76-
RowBox[{"PatternTest", "[",
75+
RowBox[{"OptionValue", "[", "Atomic", "]"}], ",",
76+
RowBox[{"(",
77+
RowBox[{"Optional", "[",
78+
RowBox[{"PatternTest", "[",
7779
RowBox[{
78-
RowBox[{"pattern", "[",
79-
RowBox[{"a", ",",
80-
RowBox[{"Blank", "[", "]"}]}], "]"}], ",", "AtomQ"}], "]"}], "]"}], ")"}], ",",
81-
RowBox[{"(",
82-
RowBox[{"Optional", "[",
83-
RowBox[{"pattern", "[",
84-
RowBox[{"a", ",",
80+
RowBox[{"pattern", "[",
81+
RowBox[{"a", ",",
82+
RowBox[{"Blank", "[", "]"}]}], "]"}], ",", "AtomQ"}], "]"}], "]"}], ")"}], ",",
83+
RowBox[{"(",
84+
RowBox[{"Optional", "[",
85+
RowBox[{"pattern", "[",
86+
RowBox[{"a", ",",
8587
RowBox[{"Blank", "[", "]"}]}], "]"}], "]"}], ")"}]}], "]"}],
8688
ShowSpecialCharacters->False,
8789
ShowStringCharacters->True,
@@ -90,7 +92,7 @@
9092

9193
PatternizeSymbol[a_, namedVariables_, OptionsPattern[]] := a
9294

93-
ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] :=
95+
ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] :=
9496
Complex[a, b]
9597

9698
ComplexResolve[I Optional[b_Symbol]*Pi] := Complex[0, b]*Pi
@@ -104,7 +106,7 @@
104106

105107
DepatternizePattern[pattern_] := pattern
106108

107-
ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] :=
109+
ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] :=
108110
Complex[a, b]
109111

110112
ComplexResolve[I Optional[b_Symbol]*Pi] := Complex[0, b]*Pi
@@ -116,9 +118,9 @@
116118

117119
Options[Patternize] = {Atomic -> False};
118120

119-
Patternize[expression_, namedVariables_, OptionsPattern[]] :=
120-
Map[PatternizeSymbol[#, namedVariables,
121-
Atomic -> OptionValue[Atomic]] &,
121+
Patternize[expression_, namedVariables_, OptionsPattern[]] :=
122+
Map[PatternizeSymbol[#, namedVariables,
123+
Atomic -> OptionValue[Atomic]] &,
122124
MapAll[ComplexResolve, expression], {-1}]
123125

124126
Depatternize[pattern_] := MapAll[DepatternizePattern, pattern]
@@ -127,24 +129,23 @@
127129
has the same structure as a given answer template, given a set of \
128130
named variables.*)
129131

130-
inertFunctionRules = {Sin -> fSin, Cos -> fCos, Tan -> fTan,
131-
Sec -> fSec, Csc -> fCsc, Cot -> fCot, ArcSin -> fArcSin,
132-
ArcCos -> fArcCos, ArcTan -> fArcTan, ArcSec -> fArcSec,
133-
ArcCsc -> fArcCsc, ArcCot -> fArcCot, Sinh -> fSinh, Cosh -> fCosh,
134-
Tanh -> fTanh, Sech -> fSech, Csch -> fCsch, Coth -> fCoth,
135-
ArcSinh -> fArcSinh, ArcCosh -> fArcCosh, ArcTanh -> fArcTanh,
136-
ArcSech -> fArcSech, ArcCsch -> fArcCsch, ArcCoth -> fArcCoth,
137-
Exp -> fExp, Log -> fLog};
138-
132+
inertFunctionRules = {Sin -> fSin,sin->fSin, Cos -> fCos,cos->fCos, Tan -> fTan, tan->fTan,
133+
Sec -> fSec,sec->fSec, Csc -> fCsc,Cosec->fCsc,csc->fCsc,cosec->fCsc, Cot -> fCot, cot->fCot,ArcSin -> fArcSin, arcsin->fArcSin,asin->fArcSin,
134+
ArcCos -> fArcCos,arccos->fArcCos,acos->fArcCos, ArcTan -> fArcTan,arctan->fArcTan,atan->fArcTan, ArcSec -> fArcSec, arcsec->fArcSec,asec->fArcSec,
135+
ArcCsc -> fArcCsc,ArcCosec->fArcCsc,arccsc->fArcCsc,acsc->fArcCsc,acosec->fArcCsc, ArcCot -> fArcCot,arccot->fArcCot,acot->fArcCot, Sinh -> fSinh,sinh->fSinh, Cosh -> fCosh,cosh->fCosh,anh -> fTanh,tanh->fTanh, Sech -> fSech,sech->fSech, Csch -> fCsch,Cosech->fCsch,csch->fCsch,cosech->fCsch, Coth -> fCoth, coth->fCoth,
136+
ArcSinh -> fArcSinh, arcsinh->fArcSinh,asinh->fArcSinh, ArcCosh -> fArcCosh,arccosh->fArcCosh,acosh->fArcCosh, ArcTanh -> fArcTanh,arctanh->fArcTanh,atanh->fArcTanh,
137+
ArcSech -> fArcSech, arcsech->fArcSech,asech->fArcSech, ArcCsch -> fArcCsch,ArcCosech->fArcCsch,arccsch->fArcCsch,acsch->fArcCsch,acosech->fArcCsch, ArcCoth -> fArcCoth,arccoth->fArcCoth,acoth->fArcCoth,
138+
Exp -> fExp,exp->fExp, Log -> fLog,log->fLog};
139+
139140
Options[StructureMatchQ] = {Atomic -> False};
140141

141-
StructureMatchQ[response_, answerTemplate_, namedVariables_,
142-
OptionsPattern[]] :=
143-
Module[{response2, answerTemplate2},
144-
response2 = ReplaceAll[response, inertFunctionRules];
145-
answerTemplate2 = ReplaceAll[answerTemplate, inertFunctionRules];
146-
MatchQ[response2,
147-
Patternize[answerTemplate2, namedVariables,
142+
StructureMatchQ[response_, answerTemplate_, namedVariables_,
143+
OptionsPattern[]] :=
144+
Module[{response2, answerTemplate2},
145+
response2 = ReplaceAll[response, inertFunctionRules];
146+
answerTemplate2 = ReplaceAll[answerTemplate, inertFunctionRules];
147+
MatchQ[response2,
148+
Patternize[answerTemplate2, namedVariables,
148149
Atomic -> OptionValue[Atomic]]]]
149150

150151
equalQStructure[answer_, response_, params_] := Module[{namedVariables,correctQ},
@@ -173,5 +174,40 @@
173174
equalQOther[answer, response, params]
174175
]
175176
];
177+
178+
EvaluationFunction[type_, answer_, response_, params_] := Module[{result,feedback},
179+
Print["Running Evaluation Function"];
180+
result = evalQ[type, answer, response, params];
181+
Print["Results"];
182+
Print[result];
183+
feedback = If[result["is_correct"],
184+
Lookup[params, "correct_response_feedback", "Correct!"],
185+
Lookup[params, "incorrect_response_feedback", "Incorrect!"]
186+
];
187+
<|
188+
"command" -> "eval",
189+
"result" -> <|
190+
"is_correct" -> result["is_correct"],
191+
"feedback" -> feedback,
192+
"error" -> result["error"]
193+
|>
194+
|>
195+
];
196+
197+
evalQuestionIO = Function[
198+
Module[{jsonData, result,requestData,answer,response,params,type},
199+
jsonData = Import[#1, "JSON"] //. List :> Association;
200+
requestData = jsonData["params"];
201+
answer = requestData["answer"];
202+
response = requestData["response"];
203+
params = requestData["params"];
204+
type = params["comparisonType"];
205+
Print["Evaluating Response Against Answer"];
206+
result = EvaluationFunction[type, answer, response, params];
207+
Print["Response"];
208+
Print[result];
209+
Export[#2, result, "JSON", "Compact" -> True]
210+
]
211+
];
176212
End[]
177213
EndPackage[]

0 commit comments

Comments
 (0)