Correct processing of regular expressions in short answer questions

Correct processing of regular expressions in short answer questions

by Johnathan Kemp -
Number of replies: 10

I am about to develop a series of lessons based on the use of short answer questions that will be processed using regular expressions.

I believe I have identified a bug in the current code that is resulting in answers that are designed to trap incorrect responses by using -- and ++ not being processed correctly.

I have figured out how to modify the coding so that the correct processing can take place and have posted this in the issue tracker as MDL-17125

Part of the issue is that I am assuming that incorrect responses should be able to provide their own feedback and jump to any page, not just to "this page".

Is anyone able to confirm that my understanding of how the lesson module is intended to function and should be functioning is correct?

I can wait until the bug is fixed as I can develop my lessons using my modification to the code, but I cannot afford to develop a lesson based on logic that is inconsistent with the intended functioning of the lesson module.

 Kind regards

Johnathan

Average of ratings: -
In reply to Johnathan Kemp

Re: Correct processing of regular expressions in short answer questions

by Chris Collman -
Picture of Documentation writers
Hi Johnathan,
I would bow to Joseph, who knows short expressions backwards and forwards and I believe wrote the book. I have played with it but do not use it in a production setting, thus I have not discovered 1,000 ways it might or might not work big grin

However, I just reviewed you comment in Tracker MDL 17125. You are correct if custom scoring is turned off (the default setting). Any answer is marked correct when it advances in what I am now calling the Edit order (formerly the logical order). You are not correct if custom scoring is turned on. See Lesson_module#Answer for a brief description of the two methods. This is a common misconception. Lesson is adaptive and therefore can be complicated and that setting can be overlooked .

In review: the way I understand it is that each analysis of a student's answer has it's own response and jump assigned to it by the teacher. "This page" is the usual standard default for all answers after the first one (which is usually "next page") in most lesson questions. Any jump associated with any analysis line (answer) can send the student to any page in the lesson. Seems to me that you should turn custom scoring on, change the jumps to what ever you want and that should solve your problem.

Just to double check that in addition to the above links, you have visited:
Hope this helps.

Best Chris

In reply to Chris Collman

Re: Correct processing of regular expressions in short answer questions

by Johnathan Kemp -

Hello Chris,

Thanks for your help.

I appreciate the distinction you made between Custom scoring settings and have paid particular attention to this during further tests I have conducted.

I have reviewed the links you suggested and I continue to believe there is an error in the code. I have included below details of my lesson configuration and structure so that my results can be duplicated by others.

The key issue for me is whether those responsible for maintaining the lesson agree with my assessment, or can identify what I need to do to change my lesson to get it to work correctly. Otherwise I cannot proceed.

I tried to post full details of my lesson configuration and structure and details of my test results, so that others could duplicate them, but for some reason the posting once posted broke in two and the second part displayed before the first part.

To resolve this I have attached a file with my original complete posting.

Kind regards

Johnathan

In reply to Johnathan Kemp

Here is my read but code experts need to chime in

by Chris Collman -
Picture of Documentation writers
Hi Johnathan,
I looked at the RTF file which has great details!

I can only speak to the Lesson settings. The Practice Lesson "yes" setting is one way from pushing the grades to Gradebook. Max attempts probably should be set to 1 or 2 (is "no" an option in 1.8.3?). I am always very cautious of checking anything as a teacher. I like to create a test student and use that login for checking stuff (I do not trust the "change role" setting). Sometimes things don't work right for teachers but do for students, and of course the reverse is true.

The following warning indicates a code issue and that is not something I know about. See below.

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in C:\Apache2\htdocs\moodle\mod\lesson\action\continue.php on line 131


I think Joseph understands code in Lesson and Quiz, plus more such as the logic in the Short Answer question regular expressions. Michael and Mark watch over Lesson from the code side and seem to check this forum every week or so. If a Tracker issue involves Lesson, then Mark gets an email. Everyone is a volunteer smile

Best Chris
In reply to Johnathan Kemp

Re: Correct processing of regular expressions in short answer questions

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hello Johnathan, I am looking at your problem and bug report.

Just one remark about the (very detailed, thank you) _test_results you attached to your post. You write that you set "maximum number of attempts = no". But, at least on my moodle 1.9 version there is no "no" option in the dropdown list. How did you really set this parameter?

Joseph

Attachment image00.jpg
In reply to Joseph Rézeau

Re: Correct processing of regular expressions in short answer questions

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Johnathan, further to my previous post I have followed the exact steps described in your attached "script". I must report that the lesson flow works exactly as expected and I am not getting error messages.
Which version of Moodle are you currently using? I did my tests on moodle 1.9.3. Have you hacked the Lesson code in any way?
In summary, I cannot reproduce the bug you mention. Chris, can you try it?
Joseph
In reply to Joseph Rézeau

Re: Correct processing of regular expressions in short answer questions

by Chris Collman -
Picture of Documentation writers
Hi Joseph,
I will give it a try but will not be able to get to it until Friday (out of town tomorrow from 5:30 AM to 10:30 PM) smile I may even fire up one of my 1.8 local hosts and upgrade it to the latest 1.8 version.

Both you and Jonathan are way over my head in regular expression logic but Jonathan's details should give me enough to go on for a test.

Best Chris


In reply to Chris Collman

Re: Correct processing of regular expressions in short answer questions

by Johnathan Kemp -

Hello Joseph and Chris,

First can I say thank you for your help in seeking to resolve this.

Joseph, sorry about the boo boo re the Maximum attempts - this is set to 10.

So that you can get a clear understanding of what is happening I have produced a Wink demonstration that will take you through the server environment, the lesson configuration and structure, the results I am getting with the latest Moodle files downloaded this morning, and also shows the effect of changing the "or" to "and" on line 125 of continue.php. Unfortunately due to its size I cannot upload it here, so I have attached it to my original entry in the error tracker.

Chris, with respect to the use of regular expressions, I think this is in some ways a red-herring as the preg_match() errors are failing, not because of errors in the regular expressions I am using, but because my incorrect answers are being processed as correct answers. The correct answer processing in continue.php does not attempt to strip out "--" or "++" from the regular expression string as this would not be used in a correct answer. However "--" and "++" are Moodle lesson module flags and are not part of the regular expression, so when preg_match() attempts to process them it complains. 

I hope this helps to identify whether I am doing something stupid sad or whether there is an opportunity to enhance the current performance of the lesson module smile

Kind regards

Johnathan 

In reply to Johnathan Kemp

Re: Correct processing of regular expressions in short answer questions

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Johnathan,
Thanks for the wink detailed report in the bug tracker. I will be away from my base for the coming two days, but will try to solve this intriguing problem this w-end.
ATB
Joseph
In reply to Joseph Rézeau

Re: Correct processing of regular expressions in short answer questions

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Johnathan,
I have tested the issue you reported and I agree with your diagnostic and fix. See my comment in the bug tracker at MDL-17125.
ATB
Joseph
In reply to Johnathan Kemp

Re: Correct processing of regular expressions in short answer questions

by Chris Collman -
Picture of Documentation writers
Hi,
I just back from some travel. I will check the Wink and then try to see if my local host creates an error. Probably tomorrow.

Best Chris