Note: You are currently viewing documentation for Moodle 2.9. Up-to-date documentation for the latest stable version of Moodle may be available here: Short answer analysis.

Short answer analysis

From MoodleDocs

In a Lesson, the short answer question type has two methods of anaysis of a student's answer. This kind of analysis in NOT available for Quiz short answer questions. In a short answer question the student is expected to answer with one word or a few words. Short-Answer question type page give more information about this question type.

There are two different student answer analysis systems available for the Short Answer type of question: the simple system is used by default; the Regular Expressions system is used if it has been installed (it is an optional plugin) and the "Use Regular Expressions" option box has been checked on the Edit Question Page screen.

Simple analysis

In the (default) simple system of analysis, the comparisons ignore the case of the text and the asterisk (*) character can be used in answers as a "wild card" character. The evaluation process goes through the answers in the order they appear on the Edit screen. When a match is found the process stops and that becomes the student's answer.

The asterisk stands for any number of characters (including no characters at all). For example, the expected answer "Long*" will match "longer", "longest" and "long". Please note, however, that the expected answer "Long*" will also match "longing", "longer than yours" and so forth.

If a "wild card" type of student answer analysis is required, it is strongly recommended to use the regular expressions analysis system explained below.

The matching process goes through the expected answers in the order they appear on the Edit screen. Once a match is found the process stops and the corresponding result (and response message, if present) is returned. So, if for example the expected answers are "Longest", "Long*" and "*" (in that order), the student's answer "longer" will match the second expected answer and, in this case, the third expected answer, although a match, is ignored.

If one of the expected answers is just "*" (a single *) this expected answer will match anything. This is used as the last "catch-all" expected answer. You will use this "catch-all" asterisk if you want to provide the student with your own "wrong answer" feedback message instead of the default system "That's the Wrong Answer" message (or the equivalent in your own language pack).

If an asterisk (*) is actually needed in an expected answer, you'll have to use the Regular Expressions analysis system and enter the asterisk as \*, backslash asterisk.

Regular Expressions analysis

This system gives you access to a more powerful but more complicated system for analysing the student's answers. For a complete introduction to Regular Expressions, see these sites http://www.zend.com/zend/tut/tutorial-delin2.php regular-expressions or http://rezeau.org/eao/developpement/expandRegexpToString.htm.

Correct answer matching a regular expression pattern

It is not possible to give complete examples of the vast possibilities offered by this system, and the following are just some possibilities.

Example 1.

Suppose your question is "What are the colors of the French flag?".
In the Answer 1 field you type this regular expression: "it’s blue, white(,| and) red/i". This will match any of those four student answers:
  • it’s blue, white, red
  • it’s blue, white and red
  • It’s blue, white, red
  • It’s blue, white and red

Note.- By default a regular expression match is case sensitive; to make the match case insensitive you must add the /i parameter right at the end of your expression.

Example 2.

Question: "What is blue, or red, or yellow?".
Answer: "(|it's )a colou?r". This will match:
  • a colour
  • a color
  • it's a colour
  • it's a color

Note.- The beginning of this regular expression "(|it's )" will match either nothing or "it's " (i.e. "it's" followed by a space). The ? (question-mark) means: preceding character zero or one time; it is used here to match British English as well as US spelling.

Example 3.

Question: "Name an animal whose name is made of 3 letters and the middle letter is the vowel a".
Answer: "[bcr]at". This will match:
  • bat
  • cat
  • rat

Detecting missing required words or character strings

Regular expressions alone cannot detect absent character strings, so you have to add a little code in your Answer field to take care of this. Any expected answer which begins with a double hyphen will analyse the student’s answer to find out whether the following string is present or absent. If present, the analysis continues to the next question; if absent, the analysis stops and the relevant Response message is displayed.

Example 4.

Question: "What are the colors of the French flag?"
Answer 2: --.*blue.*/i
student answer: "it's red and white"
Response 2: The color of the sky is missing!
Jump 2: this page

Here, the . (dot character) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Answer 2 regular expression above means: check whether the character string “blue”, preceded by anything and followed by anything is absent from the student's answer. Please note that the use of the asterisk is different in the Simple analysis system and in the Regular Expressions system.

Example 5.

Question: "Name an animal whose name is made of 3 letters and the middle letter is the vowel a".
Answer: "--[b|c|r]". Response: "Your answer should start with one of these letters: b, c or r"

Detecting unwanted (incorrect) words or character strings

You may want to detect, in the student's answer, the presence of one or several words which should be not be there (because they are wrong) and to single them out with a specific response. To do this, just start the expected answer in the Answer field with a double plus sign (++).

Example 6.

Answer: ++(yellow|black|orange|green|black|pink)/i
student answer: "it's blue, orange and white"
Response: One or more colors are wrong!
Jump: this page

Note.- If any of these (wrong) color names is detected in the student’s answer, then the negative feedback message (Response) will be displayed and the wrong strings will be colored red (or the color of the .incorrect class will be used if it exists in a CSS stylesheet of your current theme).

Example 7.

Question: "Name an animal whose name is made of 3 letters and the middle letter is the vowel a".
Answer: "++hat".
Response: "You might wear one made of an animal's skin, but a hat can't be considered as an animal."

Escaping special characters

If you need to use characters which are part of the regular expressions set of special characters, you need to "escape" them (i.e. precede them with a backslash). E.g. if you want to accept the answer "My computer cost 1000$", you must write the regular expression as "My computer cost 1000\$".

The special characters which must be escaped are .^$*()[]+?|

Order of the expected answers

Because the program tries to match the student's answer with the teacher's expected answers in the order of the Answer fields, the order of those expected answers is of the greatest importance. The best analysis system will be achieved by a careful combination of regular expressions and order of expected answers. Of course, any question programed with the Regular expressions system will have to be thoroughly tested by the teacher before being released in a Lesson.

Tips and tricks

The teacher should make some sort of provision for the student who does not know the answer to a question. This is true for all questions and especially the short answer and numeric questions. The most common way is to prevent these students from getting stuck in a loop by making sure the "Maximum number of attempts" setting in the Lesson is less than the frustration point of the students.

Another way is to use a wildcard that will accept any answer as the last line of the analysis. The teacher can give a hint in the response for this answer.

Be aware that as teacher, the maximum number of attempts will not apply when a teacher previews the lesson. So it is possible for non-editing teacher or co-teachers to get stuck in an endless loop. And for a student to get bumped to another page after the maximum number of attempts.

See also