|
| 1 | +(* ::Package:: *) |
| 2 | + |
1 | 3 | (* Wolfram Language Package *) |
2 | 4 | (* Created by the Wolfram Language Plugin for IntelliJ, see http://wlplugin.halirutan.de/ *) |
3 | 5 |
|
|
64 | 66 |
|
65 | 67 | Options[PatternizeSymbol] = {Atomic -> False}; |
66 | 68 |
|
67 | | -PatternizeSymbol[a_Symbol, namedVariables_, OptionsPattern[]] /; |
| 69 | +PatternizeSymbol[a_Symbol, namedVariables_, OptionsPattern[]] /; |
68 | 70 | Not[MemberQ[namedVariables, a]] := \!\(\* |
69 | 71 | TagBox[ |
70 | 72 | StyleBox[ |
71 | | -RowBox[{"If", "[", |
| 73 | +RowBox[{"If", "[", |
72 | 74 | 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", "[", |
77 | 79 | 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", ",", |
85 | 87 | RowBox[{"Blank", "[", "]"}]}], "]"}], "]"}], ")"}]}], "]"}], |
86 | 88 | ShowSpecialCharacters->False, |
87 | 89 | ShowStringCharacters->True, |
|
90 | 92 |
|
91 | 93 | PatternizeSymbol[a_, namedVariables_, OptionsPattern[]] := a |
92 | 94 |
|
93 | | -ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] := |
| 95 | +ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] := |
94 | 96 | Complex[a, b] |
95 | 97 |
|
96 | 98 | ComplexResolve[I Optional[b_Symbol]*Pi] := Complex[0, b]*Pi |
|
104 | 106 |
|
105 | 107 | DepatternizePattern[pattern_] := pattern |
106 | 108 |
|
107 | | -ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] := |
| 109 | +ComplexResolve[Optional[a_Symbol] + I Optional[b_Symbol]] := |
108 | 110 | Complex[a, b] |
109 | 111 |
|
110 | 112 | ComplexResolve[I Optional[b_Symbol]*Pi] := Complex[0, b]*Pi |
|
116 | 118 |
|
117 | 119 | Options[Patternize] = {Atomic -> False}; |
118 | 120 |
|
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]] &, |
122 | 124 | MapAll[ComplexResolve, expression], {-1}] |
123 | 125 |
|
124 | 126 | Depatternize[pattern_] := MapAll[DepatternizePattern, pattern] |
|
127 | 129 | has the same structure as a given answer template, given a set of \ |
128 | 130 | named variables.*) |
129 | 131 |
|
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 | + |
139 | 140 | Options[StructureMatchQ] = {Atomic -> False}; |
140 | 141 |
|
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, |
148 | 149 | Atomic -> OptionValue[Atomic]]]] |
149 | 150 |
|
150 | 151 | equalQStructure[answer_, response_, params_] := Module[{namedVariables,correctQ}, |
|
173 | 174 | equalQOther[answer, response, params] |
174 | 175 | ] |
175 | 176 | ]; |
| 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 | +]; |
176 | 212 | End[] |
177 | 213 | EndPackage[] |
0 commit comments