Issue Details (XML | Word | Printable)

Key: CONTRIB-869
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anthony Borrow
Reporter: Oleg Sychev
Votes: 0
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Non-core contributed modules

A new perl-compatible regular expression question type

Created: 12/Nov/08 01:11 AM   Updated: 14/Nov/08 06:00 AM
Component/s: QuestionType: Preg
Affects Version/s: 1.9.3
Fix Version/s: None

File Attachments: 1. Zip Archive preg.zip (11 kB)


Participants: Anthony Borrow, Joseph Rézeau, Oleg Sychev and Tim Hunt
Security Level: None
Resolved date: 12/Nov/08
Affected Branches: MOODLE_19_STABLE


 Description  « Hide
Moodle Community already have Josephs Rezeau question type; this type was developed out of frustration by work with it and is sowewhat contrary:
it doesn't have any HINT functionality, just regular expression matching check, but it also doesn't have any issues associated with it: it's supports full syntax of php perl-compatible regular expressions (any complexity and with any number of possible matches).

It's also somewhat stable - it is used in Volgograd State Technical University for almost a year, on several courses with several hundreds of quite complex regular expressions.



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Joseph Rézeau added a comment - 12/Nov/08 03:17 AM
Hi Oleg,
Thank your for making your new "preg" question type available to the Moodle community. I hope you get a CONTRIB access soon so that it will be easier to upgrade to your updated versions of this plugin.
I have installed it on my moodle 1.9 development site. No install problems at all.
The Help files are minimal, but this does not matter for the moment. Unfortunately the Help files are not accessible from the question editing interface (there must be a path problem).
1- I like the way you put the (best) "Correct answer" in a field of its own, just before the list of options.
2- I do not understand the "exact matching parameter". Could you provide some examples (in "normal everyday language" please)?
3- One didactically important feature of my own regexp plugin is that it can catch "missing" words from the student's response. Example question: Name an animal's name in 3 letters. Expected answers: the cat / the bat / the rat OR a cat / a bat / a rat. How does your preg question detect the absence of either "the" or "a" ?
I tried this: ([^a]|[^t][^h][^e]).* which does not work. Any idea?
All the best,
Joseph

Oleg Sychev added a comment - 12/Nov/08 05:16 AM
Well, help files is accessible on my sites. I don't know, what's wrong with them, you can copy qtype_preg catalog to the en_uf8/help thought. I'm not native English, so I don't dare to write a complex help in English without someone to edit it. There are many well known sites about regex thought.

1 - You way with using first subanswer was somewhat confusing for our teachers, so I try to find better solution. You may implement it too. Do you notice regex validation using this correct answer? Just try to save question without 100% grade regex matcing it.

2 - Let's consider you example with animals. The regex for correct answer would be something like (the|a)\s+[cbr]at . If you set Exact Matching to Yes, the answer must be strictly as you describe it, for example 'a rat' with nothing else in it (the way the ordinary teacher would expect it to work). If you set it to No, the regex will match any string which contains correct answer, for example 'this is a rat maybe'. In No mode you still can specify exact matching for some options using regexp syntax, that is enclosing it in ^$ i.e. ^(the|a)\s+[cbr]at$ (Exact Match Yes just do it to every regex). You may want to catch correct answers with exact matches and parts of incorrect as partial, for example ^an\s+ would catch wrong article at the start of the string, and you can tell the student whats wrong. In that case it is easy to use an\s+[cbr]at with Exact Matching, but in more complicated cases this isn't so easy.
Can you think how I should to clarify it in help? I'm so familiar with regexes that may omit something important to newbies.

3 - A dog maybe I can't properly understand you needs. Do you want to catch partially wrong answer such as 'bat' without either 'a' or 'the'? I would set Exact Matching to No, create first regex (the|a)\s+[cbr]at$ for 100% and something like [cbr]at for a lesser grade on the second, than you catch any phrase containig cat, bat or rat except the correct ones (the questions in Moodle now thought that first matching response gives grade). This, hovewer, will catch 'catalogue' as it contains 'cat'. You can upgrade it to (|\s+)[cbr]at(\s+|$) to catch a word cat/bat/rat, enclosed in spaces or start/end of the string. If you want to catch phrase that must end with cat, bat or rat with at least one space before the word (except correct) then you can write \s+[cbr]at$ instead. To create a more specific regex I must know exactly what you want - i.e. which cases must be caught and which must not.

Also, you (as, I think, many contributors there) may like to vote for MDLSITE-551. Please see MDL-14899 too, you may like the block.


Joseph Rézeau added a comment - 12/Nov/08 07:30 AM
Oleg,

1- I said I agreed that yours was a good idea. Yes, I noticed how regex validation used that correct answer. And I will see if I can incorporate this idea into my REGEXP question type. Thanks.

2- OK, now I understand better what you want to achieve with the "Exact Matching Yes/No" setting. Thanks for the examples.

3- "I can't properly understand you needs. Do you want to catch partially wrong answer such as 'bat' without either 'a' or 'the'?"
Not exactly. I want to catch the ABSENCE of mandatory words in the student's answer. Here are some examples of the way I do it in my REGEXP plugin.
a) regular expression --(the|a)\s.*
student's response "cat" or "dog" or "tulip" or ... any character string not beginning with "the " or "a "
feedback message : "You are missing an article at the beginning of your answer"
b) question what are the colors of the French flag?
regular expression to catch ABSENT "blue" color : --(^|.\b)blue\b.
student's response: "red and white" or "it's red, yellow and white" or ... any response not beginning with "blue" or containing the word "blue"
feedback message: "You are missing the color BLUE"
I don't think you can catch these "missing mandatory" words just by using regular expressions, this is why I added the – syntax to my REGEXP plugin. But maybe you can suggest something. Of course, I agree that the problem is that I am introducing a special syntax which is not part of the standard regular expressions syntax; but I do it because I need it for my didactic purposes...

Joseph


Oleg Sychev added a comment - 12/Nov/08 08:18 AM
Joseph

3 Well, you can catch abscence of something using the way regexes are compared in Moodle in two steps:
a) first regex must catch any correct answer
b) second regex must contains .* instead of missing fragment - it will catch what you want

for the articles if you don't interested in anything except the article:
a) (the|a)\b.*
b).*
Let's recall you cat/bat/rat example. then
a) (the|a)\s+[cbr]at
b) .*\s+[cbr]at catching missing article
you can write also
c) (the|a)\s+.* to catch anything wrong about an animal

Actually, you'll need more options that Tim mentioned in his last comment to MDL-16344 (go see this Bugzilla page) than regexes. Can we work on implementing it together? You'll get quite pains trying to catch with regexes blue, red and yellow in any possible order.


Tim Hunt added a comment - 12/Nov/08 11:37 AM
Anthony, it would be great to get this into contrib when you have a moment, but I know you are busy.

Oleg, I recently realised that you can do blue, red and yellow in any possible order using regexes, and without listing all six possible orders, but you have to use assertions Something like

^(?=.\bblue\b)(?=.\bred\b).\byellow\b.$

but that is hardly intuitive! (And I don't know what sort of performance you get out of the preg engine with expressions like that.)


Anthony Borrow added a comment - 12/Nov/08 03:38 PM
moving to newly created QuestionType: Preg component

Anthony Borrow added a comment - 12/Nov/08 03:43 PM
Oleg - Thanks for your work on this code and for sharing it with the community. I am marking this as resolved as I have added the code to contrib/plugins/question/type/preg. If you could please apply for CVS write access at http://moodle.org/cvs I will get that approved so that you can continue to maintain the code. I have also created a component in the tracker called QuestionType: Preg. I have bumped your privileges in the tracker so that you can manage issues related to the preg question type. Any new issues (bugs, feature requests, etc.) for the preg question type component will automatically be assigned to you. Please do not hesitate to let me know if there is anything I can do to be of assistance or if you have any questions. Peace - Anthony

Joseph Rézeau added a comment - 13/Nov/08 07:05 PM
Tim > I recently realised that you can do blue, red and yellow in any possible order using regexes, and without listing all six possible orders, but you have to use assertions Something like
^(?=.\bblue\b)(?=.\bred\b).\byellow\b.$
Tim, this is excellent! Just what I needed. I will test it when I get the time and energy to give my REGEXP plugin a much-needed overhaul.
Joseph

Joseph Rézeau added a comment - 13/Nov/08 07:31 PM
Further to my recent comment, I am now realizing that I can do a lot of conditions such as:
if student's answer matches
^(?=[A-Z]).*[^.]$
then I can send feedback message "You began with a capital letter, you must end with a full stop" with this expression:
or, on the contrary:
if student's answer matches
^(?=[a-z]).*\.$
feedback message:
"You began your answer with a lowercase letter, you must NOT end with a full stop
Really, these assertions open up a whole set of possibilities, but however they'll have to be tested for performance, as Tim warns out.
Joseph

Oleg Sychev added a comment - 14/Nov/08 01:14 AM
Joseph, would you like to join discussion on http://docs.moodle.org/en/Development:Shortanswer_question_development ? It may well be that you can achieve you didactical features with good perfomance without explicitely written regexes at all.

Please, add description of features you need in ' initial types of the rules' list. Keep in mind that you can place negation before any rule, so you "absence some words" is already there.


Oleg Sychev added a comment - 14/Nov/08 04:42 AM
Anthony - I'd applied for cvs write access. Will I recieve any notification about it getting approved? Also, could you please link me to some description how I can maintain archive in Modules and Plugins database automatically from cvs if this possible?

"Please do not hesitate to let me know if there is anything I can do to be of assistance or if you have any questions. " - actually I would like you assistance (if you can) in another contrib matter. Some time later I write for our university block that just display a link for MyMoodle page. Our students found it very useful (forcing everyony to MyMoodle on login irritates experienced users, especially staff), so I release it there. The block is so simple and generally useful, that it probably would be better in the core, than there. I created MDL-14899 for this (we even get some votes). Eloy add +1 and reassigned to Martin for final consideration, but Martin appears to be quite busy. Could you please ensure that this matter wouldn't be forgetted and would be resolved somehow: either inclusion in the core or, failing that, move it there?

Best regards, - Oleg.


Anthony Borrow added a comment - 14/Nov/08 06:00 AM
Oleg - I've approved your CVS request. I think you do get a message indicating that it has been approved. You may want to check out http://docs.moodle.org/en/CVS_(developer) for learning how to manage the files in CVS. Let me know if you have any questions. Also, if you are using Eclipse check out http://docs.moodle.org/en/Eclipse. Let me know if you run into a particular question or have problems. You may want to experiment changing some whitespace or adding a comment in a file and use that to test your access.

I'll add myself as a watcher to MDL-14899. If you feel that the issue has stalled, just add a comment. My experience is that we do pretty well at keeping things moving along and resolving issues. From what you say, it sounds like a good idea that there is a way to access their My Moodle page. I'll review the issue and comment there.

Peace - Anthony