regular expressions question

regular expressions question

от Jeroen Hollander -
Количество ответов: 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




В ответ на Jeroen Hollander

Re: regular expressions question

от Joseph Rézeau -
Изображение пользователя Core developers Изображение пользователя Particularly helpful Moodlers Изображение пользователя Plugin developers Изображение пользователя Testers Изображение пользователя 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 excellentподмигиваю documentation here: https://docs.moodle.org/38/en/Gapfill_question_type#Regular_Expressions

В ответ на Joseph Rézeau

Re: regular expressions question

от Jeroen Hollander -

Thank you for your reply.

I was already using different delimiters улыбаюсь

#(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

В ответ на Jeroen Hollander

Re: regular expressions question

от Joseph Rézeau -
Изображение пользователя Core developers Изображение пользователя Particularly helpful Moodlers Изображение пользователя Plugin developers Изображение пользователя Testers Изображение пользователя Translators
Sorry, Jeroen,
I had not tested my solution well enough. I will have another look as soon as possible.
В ответ на Joseph Rézeau

Re: regular expressions question

от Joseph Rézeau -
Изображение пользователя Core developers Изображение пользователя Particularly helpful Moodlers Изображение пользователя Plugin developers Изображение пользователя Testers Изображение пользователя 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.

В ответ на Joseph Rézeau

Re: regular expressions question

от Marcus Green -
Изображение пользователя Core developers Изображение пользователя Particularly helpful Moodlers Изображение пользователя Plugin developers Изображение пользователя 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 грущу
Not sure I can fix this without breaking a large number of existing questions.
В ответ на Marcus Green

Re: regular expressions question

от Jeroen Hollander -

Hello Marcus,


Thank you for looking into this.

Your suggested solution is a okay for the moment.


Thanks again.


Jeroen

В ответ на Jeroen Hollander

Re: regular expressions question

от Marcus Green -
Изображение пользователя Core developers Изображение пользователя Particularly helpful Moodlers Изображение пользователя Plugin developers Изображение пользователя 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
В ответ на Marcus Green

Re: regular expressions question

от 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?