Skip to main content

Answer matching

Most question types use answer matching sections in the XML to define which
feedback to give on an answer. An example of a matching section is:

<mapping correct="1" stop="0">
  <match inlineChoice="A" inlineOption="2" />
  <match inlineChoice="B" inlineOption="4" />
  <and>
    <match inlineChoice="C" inlineOption="1" />
    <match inlineChoice="D" inlineOption="3" />
  </and>
  <not>
    <match inlineChoice="E" pattern="/^inhibitor$/i" />
  </not>
  <range inlineChoice="speed" minval="119.999" maxval="120.001" />
  <feedback>Very good.</feedback>
</mapping>

A answer mating section always starts with a <mapping>
tag. The correct="1" indicates whether the answer is correct
or not if this mapping matches the current answer. The (optional)
stop="0" means that if this mapping matches, further mappings
should still be checked. stop="1" means that matching should
stop if this mapping matches.

Inside the <mapping> tag there are two types of tags allowed, tags that
do answer-matching, and <feedback> tags. If
all tags that do answer-matching return a positive result,
the <feedback> tags are shown to the user. The different answer-matching
tags are: match, range, and, or, not.

Tag: <match />

Match tags are used to match answers that contain text. This includes Select
& Order and Multiple Answer questions, as the "answer" to those questions
is a (text) list of the selected options. The <match> tag takes several
attributes:

  • pattern="..." If only pattern is present,
    the full answer given by the user is matched using the regular expression
    given. See Regular expressions for information on regular expressions.
  • inlineChoice="A" inlineOption="B" Used in Fillblanks
    questions. If inlineChoice and inlineOption are present, it checks whether
    the user selected option B for the given dropdown box A.
  • inlineChoice="C" pattern="..." Used in Fillblanks
    questions, for freeform choices where the user can enter any text. It checks
    if the value entered by the user in text box C matches the given regular
    expression.
  • hotspot="D" Checks if a draggable is on the given
    hotspot(s). hotspot can be a regular expression that compares all
    hotspotId's on the given regular expression and selects those that match.
    All draggables are checked if no draggables are selected with draggable. If
    any of the given hotspots in one <match> tag have a draggable the
    result is true, unless matchAll is h or b,
    then all of the given hotspots have to have a draggable for the result to be
    true.
  • draggable="E" Checks if the given draggable(s) are on a
    hotspot. draggable matches all draggableId's with the given regular
    expression and selects those that match. If matchAll is d
    or b, then all selected draggables have to be on a
    (selected) hotspot for the match to be true.
  • matchAll="F" Selects whether only one or all of the items
    needs to match, depending on what it's combined with:
    • inlineChoice="C" pattern="..." If C is a regular expression, a
      non-zero value for matchAll will make that the values of all
      inlineChoices with an ID that matches C will have to match the pattern.
      If any value of an inlineChoice with an ID that matches C does not match
      the pattern, the match return false.
    • hotspot="D" draggable="E" If D and/or E are regular expressions, F can
      have three values:
      • (h)otspots: All selected hotspots should have one of the selected
        draggable.
      • (d)raggable: All selected draggables should be on one of the
        selected hotspots.
      • (b)oth: All selected hotspots should have one of the selected
        draggables and all selected draggables should be on one of the
        selected hotspots.

Examples:

<match pattern="A" />

Used in Select&Order and Multiple answer questions. Match true if the
answer matches the pattern.

<match inlineChoice="A" inlineOption="B" />

Used in FillBlanks questions. Match true if dropdown-style inlineChoice with
id A contains the option with id B.

<match inlineChoice="A" pattern="B" />

Used in FillBlanks questions. Selects all (freeform-style) inlineChoice with
an id that matches pattern A. If the value of any of these inlineChoices
matches pattern B the match is successfull.

<match inlineChoice="A" pattern="B" matchAll="1" />

Used in FillBlanks questions. Selects all (freeform-style) inlineChoice with
an id that matches pattern A. If the value of all of these inlineChoices
matches pattern B the match is successfull. If any choice does not match the
match fails.

<match hotspot="A" />

Used in Hotspot questions. Selects all hotspots with an id that matches
pattern A. If any of these hotspots has a draggable, the match is successfull.

<match hotspot="A" matchAll="h" />

Used in Hotspot questions. Selects all hotspots with an id that matches
pattern A. If all of these hotspots have a draggable, the match is
successful.

<match hotspot="A" draggable="B" />

Used in Drag&Drop questions. Selects all hotspots with an id that matches
pattern A. Selects all draggables with an id that matches pattern B. If any of
the selected hotspots contains any of the selected draggables the match is
successful.

<match hotspot="A" draggable="B" matchAll="d" />

Used in Drag&Drop questions. Selects all hotspots with an id that matches
pattern A. Selects all draggables with an id that matches pattern B. If
all of the selected draggables are on a selected hotspot the match is
successful.

<match hotspot="A" draggable="B" matchAll="h" />

Used in Drag&Drop questions. Selects all hotspots with an id that matches
pattern A. Selects all draggables with an id that matches pattern B. If
all of the selected hotspots contain at least one of the selected
draggable the match is successfull. If any hotspot does not contain one of the
selected draggables, the match fails. This is thus only possble if there are
at least as many selected draggables as there are selected hotspots.

<match hotspot="A" draggable="B" matchAll="b" />

Used in Drag&Drop questions. Selects all hotspots with an id that matches
pattern A. Selects all draggables with an id that matches pattern B. If
all of the selected draggables are on a selected hotspot AND all
selected hotspots contain at least one of the selected draggables then the
match is successfull.

Tag: <range />

Range checks numeric values against a range. Numeric values come from Value
questions, from Fillblanks questions with freeform inlineChoices, or from
mathematical expressions (Math in questions). Allowed attributes in range tags
are:

  • value="..." If value is present, the value given here is
    checked against the range instead of the user's answer. If a number is given,
    this number is used. If text is given, the math variable with the given name
    is used.
  • inlineChoice="X" Checks the value of the inlineChoice with
    id X. X can be a regular expression to check multiple inlineChoices with the
    same range.
  • minval="..." The minimum value the checked number has to
    have to match. If text is given, the math variable with the given name is
    used.
  • maxval="..." The maximum value the checked number has to
    have to match. If text is given, the math variable with the given name is
    used.
  • matchAll="1" If X is a regular expression, then all values
    for the choices with an ID that matches the pattern will have to match the
    range. Normally only one choice with a matching ID has to fall in the range.

Tag: <and>...</and>

And can contain multiple other answer-matching tags. The result of and is true
only if all of the contained answer-matching tags are true.

Tag: <or>...</or>

Or can contain multiple other answer-matching tags. The result of and is true
if any of the contained answer-matching tags are true.

Tag: <not>...</not>

Not can contain one other answer-matching tags. Not returns true if the
containing matching tag returns false.