regular expressions question

regular expressions question

por Jeroen Hollander -
Número de respostas: 9

Hello,

I'm using the gap fill question type (fill in the blanc) to have students give the Spanish translation for some words.

I want to use regular expressions to check 2 things:
a. the article (el / la) is optional, but when entered it must be correct.
b. student can type the word with or without accents.

The first question works okay: the horse --> el cabello ==> (el )?caballo
I can type the answer with or without the article, and using "la" marks the answer as wrong.

The next question doesn't work okay: the bird --> el pájaro ==> (el )?p[á|a]jaro
The answers "pajaro" and "pájaro" are marked correct. That is okay.
Also "el pajaro" and "el pájaro" are marked correct. That is okay too.
But repacing "el" with ANY other wordt marks to answer as correct too. That is not okay.

So I assume the problem is in using both ()? and [|] expression in one question. 
How can I fix this?

Thank you in advance.

Best regards,

Jeroen




Média das avaliações:  -
Em resposta à Jeroen Hollander

Re: regular expressions question

por Joseph Rézeau -
Imagem de Core developers Imagem de Particularly helpful Moodlers Imagem de Plugin developers Imagem de Testers Imagem de Translators

Hi Jeroen,

Here's the solution:

1.- In your gapfill question go to More Options -> Delimit characters and select a delimiter that is different from the default [ ], e.g. { }

2.- The following coding works:

the horse --> el cabello ==> {(el )?caballo}

the bird --> el pájaro ==> {(el )?p[á|a]jaro}

That is explained in the excellentpiscando documentation here: https://docs.moodle.org/38/en/Gapfill_question_type#Regular_Expressions

Média das avaliações: Useful (2)
Em resposta à Joseph Rézeau

Re: regular expressions question

por Jeroen Hollander -

Thank you for your reply.

I was already using different delimiters sorriso

#(el )?caballo#
#(el )?p[á|a]jaro#

The main problem is that "el" can be replaced with any other word in the second question (although the syntax is quite similair like in the first question).

Hope you can help me.


Jeroen

Em resposta à Jeroen Hollander

Re: regular expressions question

por Joseph Rézeau -
Imagem de Core developers Imagem de Particularly helpful Moodlers Imagem de Plugin developers Imagem de Testers Imagem de Translators
Sorry, Jeroen,
I had not tested my solution well enough. I will have another look as soon as possible.
Em resposta à Joseph Rézeau

Re: regular expressions question

por Joseph Rézeau -
Imagem de Core developers Imagem de Particularly helpful Moodlers Imagem de Plugin developers Imagem de Testers Imagem de Translators

There is definitely something wrong with that regular expression analysis. I seems to be the space in the first optional element that causes the problem.

I leave it to the plugin author, Marcus, to fix this bug.

Média das avaliações: Useful (1)
Em resposta à Joseph Rézeau

Re: regular expressions question

por Marcus Green -
Imagem de Core developers Imagem de Particularly helpful Moodlers Imagem de Plugin developers Imagem de Testers
It is a bug caused by a repurposing of the | operator.
The clue comes from this line of code
$answerparts = explode("|", $answer);
There is a bit of a work around like this
#(el )?p[áa]jaro#
But it means the | operator cannot be used as you would expect in regex triste
Not sure I can fix this without breaking a large number of existing questions.
Média das avaliações: Useful (2)
Em resposta à Marcus Green

Re: regular expressions question

por Jeroen Hollander -

Hello Marcus,


Thank you for looking into this.

Your suggested solution is a okay for the moment.


Thanks again.


Jeroen

Em resposta à Jeroen Hollander

Re: regular expressions question

por Marcus Green -
Imagem de Core developers Imagem de Particularly helpful Moodlers Imagem de Plugin developers Imagem de Testers
My apologies that this issue has taken up your time. Not many people use the regex capability so it doesn't get tested as much as it should. I will add a unit test that docments the effect of the way I repurpose the | operator and also add a note to the documentation of this issue.
In the documentation I mention two other question types that use regular expressions you might be interested in, see
https://docs.moodle.org/38/en/Gapfill_question_type#Regular_Expressions
One of which is maintained by Joseph
Em resposta à Marcus Green

Re: regular expressions question

por Jeroen Hollander -
Hallo Marcus,

I'm back again with another "problem".
We'd like our students to translate a sentence into Spanish.
The current answer is: #Veis [el|la] m[aá]s grande#
But it doesn't work. Both "mas" and "más" are accepted, but I can't get a check on "el" or "la" to work.
Do you have any suggestions?