From my experience, the responseProcessing section of a QTI XML file is the most complicated. It is the place where you check whether the user has given the correct response, deal with incorrect responses, and display the appropriate feedback. In theory it could be very simple, if you are just checking whether an answer is correct, showing the ‘correct’ feedback if it is and showing ‘incorrect’ feedback if it is not. However, it is possible to give much more tailored feedback than this, pointing users in the right direction if they have made a common mistake.
Another common use of the responseProcessing is to show a hint and/or a solution if the user requests it. For a generic structure for doing this, please see the Solution and Hint post.
responseProcessing Start and End
<responseProcessing>
<!-- Response processing goes here -->
</responseProcessing>
responseConditions
General Structure
This is the general structure for if…else if…else statements for dealing with responses. responseCondition statements can be nested within each other to create complex hierarchies of conditions.
<responseCondition>
<responseIf>
</responseIf>
<responseElseIf>
</responseElseIf>
<responseElse>
</responseElse>
</responseCondition>
Simple Example
In this example, the RESPONSE is tested for being NULL, in which case a score of 0 is given, and no feedback shown, so the user can just have another go. Next, RESPONSE is tested for being equal to ANSWER (i.e. the response is correct), in which case the CORRECT feedback is shown and the score is set to 1. Otherwise, the INCORRECT feedback is shown and the score set to 0.
<responseCondition>
<!-- Is the response NULL? -->
<responseIf>
<isNull>
<variable identifier="RESPONSE"/>
</isNull>
<setOutcomeValue identifier="SCORE">
<baseValue baseType="float">0.0</baseValue>
</setOutcomeValue>
</responseIf>
<responseElseIf>
<!-- Is the response Correct? -->
<equal toleranceMode="exact">
<variable identifier="iAnswer"/>
<variable identifier="RESPONSE"/>
</equal>
<setOutcomeValue identifier="FEEDBACK">
<multiple>
<baseValue baseType="identifier">CORRECT</baseValue>
</multiple>
<setOutcomeValue identifier="SCORE">
<baseValue baseType="float">1.0</baseValue>
</setOutcomeValue>
</responseElseIf>
<responseElse>
<!-- Otherwise the response must be incorrect -->
<setOutcomeValue identifier="FEEDBACK">
<multiple>
<baseValue baseType="identifier">INCORRECT</baseValue>
</multiple>
</setOutcomeValue>
<setOutcomeValue identifier="SCORE">
<baseValue baseType="float">0.0</baseValue>
</setOutcomeValue>
</responseElse>
</setOutcomeValue>
Feedback
Empty the Feedback Variable
This empties the feedback ‘multiple’ variable, so any previously shown feedback (from previous response) is removed before we process the current response. The EMPTY variable must have been declared in the Variable Declarations.
<setOutcomeValue identifier="FEEDBACK">
<multiple>
<variable identifier="EMPTY"/>
</multiple>
</setOutcomeValue>
Add Feedback to the Feedback Variable
This defines the feedback sections that will be shown to the user. Multiple feedback sections can be shown by adding multiple identifiers.
<setOutcomeValue identifier="FEEDBACK">
<multiple>
<baseValue baseType="identifier">INCORRECT</baseValue>
<baseValue baseType="identifier">NOTSIMP</baseValue>
</multiple>
</setOutcomeValue>
Append Feedback to the Feedback Variable
If some feedback has already been defined and you want to add further feedback, you can append another feedback identifier as shown.
<setOutcomeValue identifier="FEEDBACK">
<multiple>
<variable identifier="FEEDBACK"/>
<baseValue baseType="identifier">SEEN-HINT</baseValue>
</multiple>
</setOutcomeValue>
Comparisons
Equal
This simply compares whether two numerical values are equal. If ‘toleranceMode’ is set to exact, the values must be exactly equal. toleranceMode can also be set to absolute or relative, in which case the ‘tolerance’ must be specified. See the specification for more information.
<equal toleranceMode="exact">
<variable identifier="iAnswer"/>
<variable identifier="RESPONSE"/>
</equal>
EqualRounded
This compares whether two values are equal, to a specified level of rounding. The roundingMode can either be decimalPlaces or significantFigures.
<equalRounded roundingMode="decimalPlaces" figures="0">
<variable identifier="RESPONSE"/>
<variable identifier="iAnswer"/>
</equalRounded>
Substring contains
<substring caseSensitive="false">
<baseValue baseType="string">+</baseValue>
<variable identifier="printMath"/>
</substring>
isNull
This tests whether a value is null.
<isNull>
<variable identifier="RESPONSE"/>
</isNull>
Custom Operator
Custom operators can be used to carry out more complicated tests, e.g. comparing mathematical responses using the MathAssess engine. The ‘action’ can take one of three values:
- equal: algebraic equivalence (e.g. factorised and expanded forms are equivalent)
- syntequal: syntactical equality (e.g. factorised and expanded forms are not syntactically equal)
- code: allows custom comparison code to be provided
As an example of the difference between equal and syntequal, 1/2 and 2/4 are equal, but not syntequal. 2(x+1) and 2x+2 are equal, but not syntequal.
<customOperator class="org.qtitools.mathassess.CasCompare" ma:action="equal" ma:syntax="text/x-maxima">
<variable identifier="mAnswer"/>
<variable identifier="RESPONSE"/>
</customOperator>
The following example of a ‘code’ action tests whether the sum of the two response and answer is 0, i.e. the response is correct, but has the wrong sign.
<customOperator class="org.qtitools.mathassess.CasCompare" ma:action="code" ma:code="is(equal($1+$2,0));" ma:syntax="text/x-maxima">
<variable identifier="RESPONSE"/>
<variable identifier="mAnswer"/>
</customOperator>
Operators
And Or
As you would expected, placing two comparisons within an ‘and’ operator gives a true result only if both comparisons evaluate to true. Placing two comparisons within an ‘or’ gives a true result if either (or both) of the comparisons evaluate to true. For or, just use the following snippet and change the <and>/</and> tags to <or>/</or>
<and>
<equal toleranceMode="exact">
<variable identifier="iAnswer1"/>
<variable identifier="RESPONSE1"/>
</equal>
<equal toleranceMode="exact">
<variable identifier="iAnswer2"/>
<variable identifier="RESPONSE2"/>
</equal>
</and>
Not
The ‘not’ operators gives the ‘logical negative’ (i.e. opposite, e.g. true => false) of the subexpression. The following snippet will return true if the value of RESPONSE is not null.
<not>
<isNull>
<variable identifier="RESPONSE"/>
</isNull>
</not>