Tipo de pregunta respuesta corta de expresión regular

Saltar a: navegación, buscar
Tipo de pregunta respuesta corta de expresión regular
Tipo question type
Conjunto N/A
Descargas https://moodle.org/plugins/pluginversions.php?plugin=qtype_regexp
Problemas https://github.com/rezeau/moodle-qtype_regexp/issues
Discusión https://moodle.org/plugins/qtype_regexp
Mantenedor(es) user:Joseph Rézeau

Nota: Pendiente de Traducir. ¡Anímese a traducir esta página!.     ( y otras páginas pendientes)


La Pregunta de Respuesta Corta de Expresión regular

  • NOTA IMPORTANTE
    • La pregunta de Respuesta Corta de Expresión Regular descrita en esta documentación es un plugin adicional de terceros, el cual le permite crear preguntas para la actividad de Examen. Es diferente de la opción para "Usar expresiones regulares" del módulo de Lección.
    • La documentación en idioma inglés para la opción para "Usar expresiones regulares" en el módulo de Lección se encuentra en: Short answer analysis.

De forma similar a la pregunta de Respuesta Corta, la pregunta de Respuesta Corta de Expresión Regular espera que el estudiante conteste una pregunta "abierta" con una palabra o una frase corta. Sin embargo, el sistema de Expresión Regular le da acceso a un sistema más potente para analizar las respuestas del estudiante con el propósito de proporcionar retroalimentación inmediata más relevante.

Respuesta correcta que concuerda con un patrón de expresión regular

No es posible dar ejemplos completos de las vastas posibilidades ofrecidas por este sistema, y las siguientes son meramente algunas posibilidades.

Ejemplo 1.

Suppose your question was "What are the colors of the French flag?". In the Answer 1 box you would type the "best" answer, e.g. "it's blue, white and red". For more details, see First correct answer below.

  • In the Answer 2 box you would type this regular expression: "it's blue, white(,| and) red" (quotes should not be typed, of course).
  • If Case sensivity is set to "No", this will match any of those 4 responses:
   it's blue, white, red
   it's blue, white and red
   It's blue, white, red
   It's blue, white and red

Ejemplo 2.

Question: "What are blue, red and yellow?".

  • Answer 1: "they are colours".
  • Answer 2: "(|they('| a)re )colou?rs".
  • This will match any of those 6 responses:
   colours
   colors
   they're colours
   they're colors
   they are colours
   they are colors

Note.- The beginning of this regular expression "(|they('| a)re )" will match either nothing or "they're " or "they are ". In "colou?r", the question-mark means: the preceding character (or parenthesized group of characters) zero or one time; it is used here to match British English as well as US spelling.

Ejemplo 3.

Question: "Name an animal whose name consists of 3 letters and the middle letter is the vowel a".

  • Answer 1: "cat"
  • Answer 2: "[bcr]at".
  • This will match: bat, cat or rat.

Note.- In Regular Expression syntax, the inclusion of characters between square brackets means than ANY of those characters can be used. So, in the above example, the regular expression "[bcr]at" is the exact equivalent of "(b|c|r)at". Be careful NOT to include the pipe character as separator in your [...] regular expressions. For instance, "[b|c|r]at" will NOT WORK CORRECTLY.

Ejemplo 4.

The 'permutation' feature (introduced in regexp version 2012102900 for Moodle 2.3+)

Question: "What are the colours of the French flag (in any order)".

  • Answer 1: "it's blue, white and red"
  • Answer 2: "it's [[_blue_, _white_(,| and) _red_]]".

Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:

it's (blue, white(,| and) red|blue, red(,| and) white|white, red(,| and) blue|white, blue(,| and) red|red, blue(,| and) white|red, white(,| and) blue)

and it will match all the following answers:

   it's blue, white, red
   it's blue, white and red
   it's blue, red, white
   it's blue, red and white
   it's white, red, blue
   it's white, red and blue
   it's white, blue, red
   it's white, blue and red
   it's red, blue, white
   it's red, blue and white
   it's red, white, blue
   it's red, white and blue

Note.- This 'permutation feature' has been asked quite a few times by regexp users. It is definitely not possible to obtain it by using standard Regular Expressions syntax.

It is possible (but tedious) to write a regular expression including all the possible permutations - as in Answer 2b above - but the ad hoc syntax I am offering makes it easier to write... provided you strictly adhere to that syntax!

Include within double square brackets the part of the Answer which will contain 'permutable' words or phrases. You are actually allowed to have a maximum of 2 such sets of 'permutable' words or phrases. But you cannot embed one set within another!

Then, use pairs of underscores (the _ character) to delimit each 'permutable' word or phrase. You can still use any of the accepted Regular Expressions characters, as explained here, in your Answers which contain one (or two) such sets of 'permutable' words or phrases. If your Answer does not contain an even number of underscores, an Error warning will be displayed upon clicking the Show Alternate Answers button or when trying to Save your question.

Ejemplo 5.

Another 'permutation' example

Question: "Quote the English proverb that is an encouragement to hard, diligent work."

  • Answer 1: "Early to bed and early to rise makes an ma healthy, wealthy and wise"
  • Answer 2: "Early to [[_bed_ and early to _rise_]], makes a man [[_healthy_, _wealthy_ and _wise_]]"

Upon saving the question, Answer 2 will be automatically re-written as Answer 2b:

Early to (bed and early to rise|rise and early to bed) makes a man (healthy, wealthy and wise|healthy, wise and wealthy|wealthy, wise and healthy|wealthy, healthy and wise|wise, healthy and wealthy|wise, wealthy and healthy)

and it will match all the following answers:

   Early to bed and early to rise makes a man healthy, wealthy and wise
   Early to bed and early to rise makes a man healthy, wise and wealthy
   Early to bed and early to rise makes a man wealthy, wise and healthy
   Early to bed and early to rise makes a man wealthy, healthy and wise
   Early to bed and early to rise makes a man wise, healthy and wealthy
   Early to bed and early to rise makes a man wise, wealthy and healthy
   Early to rise and early to bed makes a man healthy, wealthy and wise
   Early to rise and early to bed makes a man healthy, wise and wealthy
   Early to rise and early to bed makes a man wealthy, wise and healthy
   Early to rise and early to bed makes a man wealthy, healthy and wise
   Early to rise and early to bed makes a man wise, healthy and wealthy
   Early to rise and early to bed makes a man wise, wealthy and healthy

Escapando metacaracteres

Definición

In the Regular Expressions syntax, a number of special characters or meta characters have special functions; but it is possible to force these special characters to be interpreted as normal (or literal) characters by preceding them with a so-called escape character, the backslash "\". Below is a (partial) list of those meta characters:

. ^ $ * ( ) [ ] + ? | { } \ /

En Respuestas Aceptadas

  • Accepted Answers are Answers which have a grade greater than zero, i.e. are totally (grade = 100%) or partially (grade > 0% < 100%) correct Answers.

In those Answers, if you need to use one or more meta characters for their literal value, you must escape them (i.e. precede them with a backslash).

Example 1.- If you want to accept the answer "This computer costs 1000$ in the US.", you must write the Answer as "This computer costs 1000\$ in the US\.".

Example 2.- If you want to accept the answer "Desktop computers are (usually) more powerful than laptops.", you must write the Answer as "Desktop computers are \(usually\) more powerful than laptops\.".

  • You can mix metacharacters that have a special function with others that have a literal value, within one Answer.

Example 3.- If you want to accept both answers "Computers are (usually) cheaper than cars." and "Computers are (usually) less expensive than cars.", you must write the Answer as ""Computers are \(usually\) (cheaper|less expensive) than cars."".

  • In the Accepted Answers boxes you can only enter regular expressions which can generate a finite number of sentences. That is why you will not be allowed to use some meta characters which match a potentially infinite number of sentences.
  • List of meta characters which you can use for their RegExp functions:

( ) [ ] ? |

  • List of meta characters which you cannot use for their RegExp functions, and can only be used for their literal value (and must be escaped).

. ^ $ * + { } \ /

  • The question mark (?) can be used either for its RegExp function OR, if escaped, for its literal value.

Example 4.- "Do you like Jack(ie)?\?" will accept both "Do you like Jack?" and "Do you like Jackie?".

En Respuestas Incorrectas

  • Incorrect Answers are Answers which have a grade equal to zero (or None).

When you write those Incorrect Answers, you can use the whole range of meta characters for their special function value:

. ^ $ * ( ) [ ] + ? | { } \ /

For examples of use, see Detecting missing required words or character strings below.

Validación de Respuestas

When you validate your Question, the question engine checks the validity of your expression, according to the features explained above. If an error is found, an ERROR message is displayed above the erroneous Answer(s) and you cannot save the Question until that error has been corrected.

The validation system also checks that your parentheses and square brackets are correctly balanced.

Note.- The faulty Answer text is "underlined" with the list of errors, as shown below.

Errors en.jpg

Detección de cadenas de caracteres o palabras requeridas faltantes

This is a powerful feature of the RegExp question type. It will analyse the student's answer for words that are required for the answer to be correct. There are 2 ways to do this.

  • Use what is called "negative lookahead assertion" in regular expressions syntax: ^(?!.*required.*)
  • or use an ad hoc pseudo-syntax provided in RegExp (an initial double hyphen): --.*required.*.

In the examples below, we shall be using the 'ad hoc' RegExp pseudo-syntax, and sometimes give the "negative lookahead assertion" equivalent for anyone interested.

Any Teacher Answer which begins with a double hyphen will analyse the student’s response 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 feedback message is displayed.

Example 4. Question "What are the colors of the French flag?".

  • Teacher Answer 2: --.*blue.*
  • Sample student Response: "it's red and white"
  • Feedback 2: The color of the sky is missing!

Here, the . (dot) stands for “any character” and the * (asterisk) means “preceding special character repeated any number of times”. The Teacher Answer 2 regular expression above means: check whether the character string "blue", preceded with anything and followed by anything is absent from the student's answer. Por favor tenga en cuenta que el uso de asteriscos es diferente en el tipo de pregunta "normal" de Respuesta Corta de Moodle y el tipo de pregunta de Expresión Regular.

Actually, this syntax is not sufficient to track the absence of the word "blue" in a student's answer such as "it's blueish, white and red". To make sure that we want to track the absence of "blue" as a word(and not just as part of a word), we must use the metacharacter \b which is an anchor which matches at a position that is called a "word boundary". Hence the new version of our Example 4:

Example 4b. Question "What are the colors of the French flag?".

  • Teacher Answer 2: --.*\bblue\b.*
  • Sample student Response: "it's blueish, white and red"
  • Feedback 2: The color of the sky is missing!

Note.- Using the "negative lookahead assertion" syntax mentioned at the beginning of this section, Teacher Answer 2 would look like this:

  • Teacher Answer 2: ^(?!.*\bblue\b.*)

Example 5. Question: "Name an animal whose name consists of 3 letters and the middle letter is the vowel a".

  • Teacher Answer: "--^[bcr].*". OR * Teacher Answer: "--^(b|c|r).*".
  • Sample student Response: "dog"
  • Feedback: "Your answer should start with one of these letters: b, c or r"

Note.- In regular expressions syntax, the caret ^ stands for "beginning of character string to be matched", while the dollar sign $ stands for "end of character string".

Example 6. Question "What are the colors of the French flag?".

  • Teacher Answer: "--.*(blue|red|white).*"
  • Sample student Response #1: "It's black and orange."
  • Feedback: "You have not even found one of the colors of the French flag!"
  • Sample student Response #2: "It's blue and orange."
  • Feedback: None, the analysis continues to the next Teacher Answer expression.

Explanation.- The regular expression looks for a missing word among those listed between brackets and separated by the | sign. As soon as one of those words is found, the "missing condition" is considered false, and the response analysis continues to the next Answer's regular expression.

Note.- Using the "negative lookahead assertion" syntax, Teacher Answer would look like this: ^(?!.*(blue|red|white).*)

Example 7. Question "What are the colors of the French flag?".

  • Teacher Answer: "--.*(&&blue&&red&&white).*"
  • Sample student Response #1: "It's blue and orange."
  • Feedback: "You have not found all the colors of the French flag".
  • Sample student Response #2: "white blue red".
  • Feedback: None, the analysis continues to the next Teacher Answer expression.

Explanation.- The regular expression looks for a missing word among all of those listed between brackets and separated by the && double character combination. Only if all of those words are present, will the "missing condition" be considered false, and the response analysis continue to the next Answer's regular expression. Por favor tenga en cuenta que la lista de palabras entre paréntesis debe comenzar con la secuencia de caracteres &&.

Note.- Using the "negative lookahead assertion" syntax, Teacher Answer would look like this: (^(?!.*(blue).*)|^(?!.*(white).*)|^(?!.*(red).*))

Edición de una pregunta de expresión regular

regexp settings 01.jpg

Modo de Botón de Ayuda

Selecting a mode other than None will display a button to enable the student to get the next letter or word or punctuation mark (including the very first letter or word).

The "Word or Punctuation" help mode is a new feature starting in Moodle 3.1.

In Adaptive mode the button displayed will say "Buy next letter" or "Buy next word" or "Buy next word or punctuation" according to the mode selected by the teacher. For setting the "cost" of buying a letter or word, see the Penalty for incorrect tries and Buying a letter or word settings further down the Edit form.

In Adaptive No penalty mode the button displayed will say "Get next letter" or "Get next word" or "Get next word or punctuation".


By default the Help button mode value is set at None. The Help button will only be available to quizzes that have their Question behaviour mode set to Adaptive or Adaptive (no penalties) as it does not make sense to enable the Help button for non-adaptive tests.

Mostrarle respuestas alternas a los estudiantes

Show all correct alternative answers to student when on review page? If there are a lot of automatically generated correct alternative answers, displaying them all can make the review page quite long. So, you may wish to not display all those alternative correct answers. The first correct answer will always be displayed, under the label "The best correct answer is:"

Primera respuesta correcta

For Answer 1 you must enter an answer text which a) is the "best" possible answer; b) is not a regular expression or - more exactly - will not be interpreted as a regular expression but "as is" and c) has a Grade value of 100%. You will notice that when you create a new RegExp question the Grade value for Answer 1 is already automatically set at 100% and cannot be changed.

Note.- There are two ways to enter an answer containing meta characters, according to whether this is Answer 1 or any of the subsequent Answers. Exemple question: how much did your computer cost?

Answer 1: It cost $1,000.

Answer 2: It cost (me )?\$1,000\.

In Anwer 1 you just type the expected answer "as is". The text in Answer 2 will be interpreted as a regular expression, and thus you need to escape the two meta characters (the $ sign and the end-of-sentence full stop). Note that here I have added the optional pronoun "me".

Otras respuestas

Any answers with a Grade higher than 0% must be entered as valid regular expressions which can yield acceptable alternative answers (regardless of the Grade being less than 100%).

For example, you cannot enter the following Answer with a grade greater than zero:

.*blue, white(,| and) red.*

The reason is that this expression would accept as correct (with a non-null grade) an infinity of answers, many of which would be incorrect, e.g.: "My hat it blue, white, red and orange", "The French flag is blue, white, red, black and nice" etc.

If you try to do so, validation of your question will fail and an error message will be displayed to tell you where you went wrong.

This means that some regular expressions, which are perfectly valid and would correctly analyse the student's (correct) answer are not recommended. The only case where they would work is a) if your question's Display Hint Button is set at No and b) your quiz Adaptative Mode is set at No. This means that you must not enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen "--", used for detecting missing character strings.

Mostrar/Ocultar respuestas alternas

When you are creating (or modifying) a RegExp question, you may want to make sure that all the alternative correct answers that you have created in the Answers fields will work. You can click the Show alternate answers button to calculate and display all the correct answers in the form you are editing. This may take quite some time on your server, depending on the number and complexity of the regular expressions you have entered in the Answer fields!

On the other hand, it is the recommended way to check that your "correct answers" expressions are correctly written. Here is an example.

Please remember that only Answers regular expressions with a score greater than zero will be used to calculate those alternative answers.

Por favor tenga en cuenta que al hacer click en el botón para Mostrar respuestas alternas realizará un análisis de todas las expresiones regulares que haya ingresado en el campo de respuesta. Si fuera detectado un error de sintaxis en esta etapa, las respuestas alternativas correctas no serán mostradas, y se mostrará en cambio un mensaje de error ad hoc arriba de la expresión regular incorrecta.

showhidealternateanswers.jpg


Retroalimentación extra formateada automáticamente

Por favor tenga en cuenta que la pregunta de Expresión Regular puede ser usada en cualquier modo de Comportamiento de pregunta. Sin embargo, se recomienda crear exámenes que solamente contengan preguntas de Expresión Regular, o que contengan otros tipos de preguntas, pero preferentemente' si la configuración para Comportamiento de pregunta / Como se comportan las preguntas del examen es configurada a Modo adaptivo (con o sin castigo).

When a student (or teacher in Preview Question mode) submits a response to a RegExp question, 3 types of feedback messages are displayed (in Adaptive mode).

  • (line 3) The standard correct/incorrect Quiz message (plus the colour associated with either state).
  • (line 2) The Feedback message entered by the question creator for each Teacher Answer.
  • (line 1) An extra feedback system is automatically provided, displaying the student's submitted response, with the following format codes:
    • the beginning of the student's submitted response which best matches one of the Alternate Answers is displayed in blue;
    • any words from the submitted response which are present in the potential Alternate Answers following the initial correct part submitted (correct but misplaced words) are displayed on a green background;
    • any words not present in the potential Alternate Answers following the initial correct part submitted (Wrong words) are displayed on a red background.

The meaning of those colours is explained below the feedback with the 2 labels "Wrong words" and "Misplaced words".

Por favor tenga en cuenta que el esquema de colores ha sido cambiado a partir de la versión para Moodle 3.1 de RegExp.

regexp04.jpg

Retroalimentación dada por el botón de Ayuda

Each time a student clicks the Buy/Get next letter/word/punctuation button to buy/get a letter/word/punctuation mark, that letter, word or punctuation mark is added to their response. The last line of the feedback zone shows the following information: added letter/word; penalty cost (if applicable); total penalties so far (if applicable). Note that if the total of penalties exceeds 1 (i.e. 100%), that total is displayed in red.

When the teacher views the quiz results, on the 'Review Attempt' pages, 'Response history' section, the response history shows Submit (with a request for help) with the response states before and after the letter/word/punctuation mark was added.


regexp03.jpg



Mostrar respuestas correctas

If your Quiz settings Review options are set to display the Right answer (During the attempt or Immediately after the attempt etc.), and your question's Show alternate answers to student setting is set to Yes, when the student has submitted his attempt, and is reviewing his answers, all of the possible answers will be displayed, as shown in this screenshot. Correct responses with a grade < 100% are also listed, with their grade value.

Por favor tenga en cuenta que el profesor siempre podrá ver la sección de "otras respuestas aceptadas" cuando revise las respuestas del Examen.

23 correct responses.jpg

En la App Mobile

Comenzando con la versión de Moodle 3.5, RegExp incluye código para la App Mobile. Si Usted accede a un examen con la App mobile que contiene preguntas RegExp questions, serán cargadas automáticamente como un anexo (add-on) remoto.

regexp05.jpg

Insertando sub-preguntas RegExp en preguntas tipo Cloze

Important notice

The RegExp question type is not recognized by the standard Moodle Cloze question type. If you want to use it you'll have to replace 2 files (renderer.php and questiontype.php) on your <yourmoodle>/question/type/multianswer with the hacked files available from the links below.

https://raw.githubusercontent.com/rezeau/moodle_multianswer_regexp_compatible/master/questiontype.php

https://raw.githubusercontent.com/rezeau/moodle_multianswer_regexp_compatible/master/renderer.php

Syntax for inserting RegExp sub-questions in Cloze type questions.

Use REGEXP or shorter RX coding for questions which ignore case

  • The colors of the French flag are {:REGEXP:=blue, white and red#Correct!}.
  • The colors of the French flag are {:RX:=blue, white and red#Correct!}.

Will accept "blue, white and red" as a correct answer as well as "Blue, White and Red"

use REGEXP_C or shorter RXC coding for questions in which case matters

  • The colors of the French flag are {:REGEXP_C:=blue, white and red#Correct!}.
  • The colors of the French flag are {:RXC:=blue, white and red#Correct!}.

Will not accept "Blue, White and Red" as a correct answer (wrong capital letters).

Por favor tenga en cuenta que, como se explicó arriba, la primerísima respuesta debe de ser calificada con 100% (en la sintaxis del tipo de pregunta Cloze, todo correcto es, ya sea = o 100%) y no debe ser una expresión regular.

A more complete example. If you enter the following in the text of a Cloze question: The colors of the French flag are {:REGEXP:=blue, white and red#Very correct indeed!~--.*\bblue\b.*#The color of the sky is missing!~--.*(blue|red|white).*#You have not even found one of the colors of the French flag!}. and click the Decode and verify the question text button, you will see this:

Question {#9} Regular expression short answer

Question definition
{:REGEXP:=blue, white and red#Very correct indeed!~--.*\bblue\b.*#The color of the sky is missing!~--.*(blue|red|white).*#You have not even found one of the colors of the French flag!}
Default mark 
1
Answer
blue, white and red
Grade
1
Feedback
Very correct indeed!
Answer
--.*\bblue\b.*
Grade
0
Feedback
The color of the sky is missing!
Answer
--.*(blue|red|white).*
Grade
0
Feedback
You have not even found one of the colors of the French flag! 

regexp in cloze question.jpg

Por favor tenga en cuenta que la sintaxis de la sub-pregunta adentro de una pregunta del tipo Cloze debe ser seguida exactamente y Usted nunca debe de copiar y pegar ningun texto de la pregunta desde, por ejemplo, un procesador de texto hacia dentro de una ventana de edición de una pregunta tipo Cloze. Muy a menudo, las preguntas de tipo Cloze producen errores por culpa de espacios vacíos sobrantes, líneas nuevas (ENTER) o cualquier caracter de formateo extraño que hubiera llegado al texto de la pregunta.

Tenga en cuenta que el botón para Pista no está disponible para una pregunta de Expresión regular incrustada dentro de una pregunta tipo Cloze.

Vea también

Descargas

Instalación


If you have downloaded the zip archive from the new moodle.org plugins page

1.- Unzip the zip archive to your local computer.

2.- This will give you a folder named "regexp".

3.- GO TO STEP 4 below ---

If you have downloaded the zip archive from https://github.com/rezeau/moodle-qtype_regexp (for latest developments)

1.- Unzip the zip archive to your local computer.

2.- This will give you a folder named something like "rezeau-moodle_qtype_regexp-ff8c6a1". The end of the name may vary.

3.- ***Rename*** that folder to "regexp".

---

4.- Upload the regexp folder to <yourmoodle>/question/type/ folder.

5.- Visit your Admin/Notifications page so that the new question type gets installed.

Aprenda más sobre expresiones regulares

Vea también estos otros tipos de pregunta Moodle basados en expresiones regulares