Regular Expression Help Needed

Regular Expression Help Needed

by ben reynolds -
Number of replies: 13
We're using 1.8.2+
Lesson is set to 1 attempt

It may be my weak programming skills or my newbie attempt at reg exp, but no matter what error I introduce to the correct answer, I get Response #2.

Example, "as Stephanie S scholar SC she S problem DO solution S her OP"
results in Response #2, which is incorrect, given that all the nouns have been entered and "as" is the error.

I hope someone can tell me what I'm doing wrong. I expect to have many reg exp answers like this coming up as we build exercises in the next week or so.

Thanks for any advice!

Here's a jpg of the question
picture of regular expression question
Average of ratings: -
In reply to ben reynolds

Re: Regular Expression Help Needed

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Ben,
So I can investigate this problem, could you please re-post the above as plain text rather than screen shot? Thanks,
Josepy
In reply to Joseph Rézeau

Re: Regular Expression Help Needed

by ben reynolds -
Hi Joseph,
I created it in the lesson, so no easy way to export. Can you please point me to where I can learn to format in plain text?
Thank you!


In reply to ben reynolds

Re: Regular Expression Help Needed

by Chris Collman -
Picture of Documentation writers
Hi Ben,
Don't out think yourself big grin. Joseph want to see exactly which characters you put in. I suggest going into the offending question in edit mode. Don't worry about the content of the question, start blocking with the first answer downward and then copy it, then paste it in this forum as a reply. Or just do each answer individually.

For example I went to demo.moodle and the short answer in the Lesson there. A simple copy and a paste here which shows:

Answer 1:
Thomas Gray
Response 1: [Use editor: Help with Use editor (new window)]
<br />
Jump 1: Help with Jump (new window)
Answer 2:
Gray
Response 2: [Use editor: Help with Use editor (new window)]
Yes, it was Thomas Gray.
Jump 2: Help with Jump (new window)

The import stuff for Joseph will be what follows the ":" in the answer (ie Thomas Gray and Gray). Does not show the actual jump, I don't know why but since that is not the issue....

Hope that helps. Chris
In reply to Chris Collman

Re: Regular Expression Help Needed

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Thanks Chris, that's just what I need from Ben.
All the best,
Joseph
In reply to Joseph Rézeau

Re: Regular Expression Help Needed

by Chris Collman -
Picture of Documentation writers
Have fun with those "regular" expressions. Figured I would jump in to save you some typing so you could continue with the hard stuff.

I often start off with the complicated method of doing something, then sort of stumble into the "easier" way. My first thought was for Ben to create a lesson with just that question in it and backit up just that lesson and post the backup here (should be under 100k). Which is not a bad idea, but the basic copy and paste is so much more direct. big grin


In reply to Joseph Rézeau

Re: Regular Expression Help Needed

by ben reynolds -
Hi Joseph and Chris,
Thanks for your good advice. Below is plain text copied from the question. I was indeed thinking myself into a complex situation instead of just copy & paste.

The lesson is set to Maximum Number of Attempts 1.

Page contents:
Find and label ALL the nouns and pronouns in the sentence that function as subjects, direct objects, indirect objects, objects of prepositions, and subject complements. There will be several types in each sentence.

Please write the answers in all lower case letters with no commas, starting with the first noun you see. Capitalize the first letter of proper nouns. After each noun write S for subject, DO for direct object, IO for indirect objects, OP for objects of prepositions, or SC for subject complements.



Stephanie is a scholar, and as she pondered the problem, the solution suddenly occurred to her.


Answer 1: Stephanie S scholar SC she S problem DO solution S her OP
Response1: Excellent work. This is a tricky sentence because it contains three clauses. You correctly identified all six nouns / pronouns. Stephanie (S) scholar (SC) she (S) problem (DO) solution (S) her (OP)
Jump 1: Next Page
Score 1: 1
Answer 2: --(Stephanie|scholar|she|problem|solution|her)
Response 2: Sorry, you left out at least one noun or didn't capitalize the proper noun.

Stephanie scholar she problem solution her

This is a tricky sentence because it has three clauses. First clause: Stephanie (S) is a scholar (SC); second clause: as she (S) pondered the problem (DO); third clause: the solution (S) suddenly occurred to her (OP)

Click here to try again.[link back to this question] Or, click the continue button to go to the next question.
Jump to: This Page
Score 2: 0

Answer 3:
--(S|SC|DO|OP)
Response 3: Sorry, you left out at least one label.

Stephanie S scholar SC she S problem DO solution S her OP

This is a tricky sentence because it has three clauses. First clause: Stephanie (S) is a scholar (SC); second clause: as she (S) pondered the problem (DO); third clause: the solution (S) suddenly occurred to her (OP)

Click here to try again. Or, click the continue button to go to the next question.
Jumpe 3: This Page
Score 3: 0

Answer 4: ++(is| a |and| as | pondered | the | suddenly | occurred | to )
Response 4:
Sorry, not correct. You included a word that isn't a noun.

Not a noun: is a and as pondered the suddenly occurred to

This is a tricky sentence because it has three clauses. First clause: Stephanie (S) is a scholar (SC); second clause: as she (S) pondered the problem (DO); third clause: the solution (S) suddenly occurred to her (OP)
Jump 4: This Page
Score 4: 0
In reply to ben reynolds

Re: Regular Expression Help Needed

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

Hi Ben,

The Regular Expression option for short answer questions is powerful but very tricky to manage. First let's start with one expression you got wrong because it does not work as expected:

  • Answer 2: --(Stephanie|scholar|she|problem|solution|her)
  • Feedback 2: Sorry, you left out at least one noun or didn't capitalize the proper noun.
How one would expect it to work:

If any of those words is missing from the student's response, then the response is wrong.

How it actually works:

If none of those words is present, then the response is wrong. But if any of those words is present, then this is OK, continue analysis.

This is really a bug in the way the regular expressions option works in the Lesson module, but I'm afraid it will stay as is for the moment. Please see my note about the Quiz option below.

The only way to test whether obligatory words are present in the student's response is e.g. as follows:

--Stephanie.*scholar.*problem.*solution.*

The .* regular expression means "any character repeated any number of times including none". This tests not only the presence of those four words (nouns) in the student's response, but also their respective order in the response. Which explains that you have te be careful with the wording of your feedback message upon detecting an error.

There is another hitch. It is possible to type a list of "unwanted" words, which will be displayed with an "incorrect" CSS style, by starting an expression with ++ (as you tried out). Unfortunately there is a bug in current versions of Lesson in Moodle which I reported (with a fix) as MDL-12860 (You can vote for it). Even when this bug is fixed you still need to provide an .incorrect{} rule in your current Moodle theme, because it does not exist in standard distributed themes.

Anyway, here is what I suggest for your analysis:

Short Answer - Use Regular Expressions

Answer 1: Stephanie S scholar SC she S problem DO solution S her OP

Response 1: Excellent work. This is a tricky sentence because it contains three clauses. You correctly identified all six nouns / pronouns. Stephanie (S) scholar (SC) she (S) problem (DO) solution (S) her (OP)

Jump 1: Next page

Answer 2: ++( a |is|and|as|pondered|the|suddenly|occurred|to)

Response 2: Sorry, not correct. You probably included a word from the original sentence that isn't a noun or a pronoun.

Jump 2: This page

Answer 3: stephanie.*

Response 3: Sorry, you didn't capitalize the proper noun.

Jump 3: This page

Answer 4: --Stephanie.*scholar.*problem.*solution.*

Response 4: Sorry, you either missed or wrongly placed at least one noun.

Jump 4: This page

Answer 5: --.*she.*her.*

Response 5: Sorry, you either left out or wrongly placed at least one pronoun.

Jump 5: This page

Answer 6: --.* S .* S .* S .*

Response 6: There are 3 subjects in this sentence (S)!

Jump 6: This page

Answer 7: --.*DO.*

Response 7: Sorry you left out one direct object (DO).

Jump 7: This page

Answer 8: --.*SC.*

Response 8: Sorry you left out one subject complement (SC).

Jump 8: This page

Answer 9: --.*OP.*

Response 9: Sorry, you left out an object of preposition (OP).

Jump 9: This page

Answer 10: .*

Response 10: Try again.

Jump 10: This page

You can see it in action on my moodle test site here. Log in as moodler, password moodler.

NOTE.- For a much better implementation of the regular expression answer analysis, you should use my regexp plugin for the Quiz module. This is still a 3rd party plugin, not part of the regular Moodle distribution, but if you plan to create lots of questions of this type then that plugin is a must.

All the best,

Joseph

PS.- I see you are working in a "Center for Talented Youth". With bright students, you might even propose that the students themselves use the regexp plugin to create their own questions.


In reply to Joseph Rézeau

Re: Regular Expression Help Needed

by ben reynolds -
Hi Joseph,
I very much appreciate your work on this problem. It's a great help to know where the bugs are, including the CSS problem (which I voted for just now). It's more help to see how to workaround the bugs and to break the problem down into workable pieces. I can use that method to construct the rest of the regexp questions.

Thank you very much for putting together that demo on your moodle test site. Seeing it in operation gives me a few questions.

  1. MDL-12860 Can you be more specific about how & where to apply the patch you've got there?
  2. I want to incorporate these reg exp questions into lessons.To use your plugin, would I create the questions in Quiz module and then export to moodle xml and then import into the lesson?
  3. I am working with very bright students (down to grade 2 and up to pre-college) and would love to have students use the plugin to create their own questions. Can you outline how that might work? Is this mostly a matter of creating/adjusting a role? Note also Lesley Beasant's question today asking how students can add questions to the quiz bank. http://moodle.org/mod/forum/discuss.php?d=87711#p387593 She might be interested in this reply.

Once again, Joseph, thank you very much for your help with this. Now, off to hand code a few more reg ex questions and see if they work as well smile
In reply to ben reynolds

Re: Regular Expression Help Needed

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Ben,
Some answers to your questions...

1- Applying the patch is dead easy. In your moodle installation, locate and open with a text editor file moodle/mod/lesson/action/continue.php. Around line 184, in the context below replace the line in red with the line in blue:
break; // quit answer analysis immediately after a match has been found
}
}
$studentanswer = s($useranswer);
$studentanswer = $useranswer;
break;
case LESSON_TRUEFALSE :

Note that if you want the 'extra wrong words' to appear in the feedback you'll have to add this CSS declaration: .incorrect {color:red!important;} (or something similar) to the end of one of your current theme's CSS files.

2- No, you can't author REGEXP questions as Quiz questions and import them to the Lesson module because they are totally different implementations.

3- Yes you can override roles to allow students to create their own questions in the Lesson module, maybe in a special moodle course set up for this purpose.
Yes you can allow students to create their own questions in the Quiz questions bank. This is especially easy in Moodle 1.9. See the documentation.

4- There are a number of advantages to using the REGEXP question plugin in the Quiz module rather than the short answer, regular expressions option question type in the Lesson module:
a- the teacher can view all the alternate acceptable answers
b- students can have a Hint option
c- all the students' responses are logged (saved) and can be reviewed individually by the teacher, which provides invaluable data on a) learning strategies b) is useful to improve the error analysis and provide relevant feedback.
If you seriously envisage creating (or having the students) create a number of regular expressions questions, I would advise doing it in the Quiz module, not the Lesson module. You can test it on my test site (e-mail me for teacher access if you want).

All the best,

Joseph
In reply to Joseph Rézeau

Re: Regular Expression Help Needed

by ben reynolds -
I'm returning to this thread because I have a problem with another regular expression question in Lesson. I found http://tracker.moodle.org/browse/MDL-17125, which seems to say that the bug in Lesson's regex logic is fixed as of 1.9.4

If I'm wrong, somebody correct me, please.
In reply to ben reynolds

Re: Regular Expression Help Needed

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Ben,
What is your problem exactly?
Joseph
In reply to Joseph Rézeau

Re: Regular Expression Help Needed

by ben reynolds -
Hi Joseph,
I'll call on your kind and good nature to tell me whether I have fixed my problem. The question below was designed to follow your advice about the Stephanie question, above. Here's what I did, originally. The hitch was that getting the IO or the DO wrong always caused Answer 3 to show up, which is obviously not wanted.

This is the last question in Exercise 2.

Find and label ALL the nouns and pronouns in the sentence that function as subjects, direct objects,

indirect objects, objects of prepositions, and subject complements. There will be several types in each sentence.

Please write the answers in all lower case letters with no commas, starting with the first noun you see. Capitalize the first letter of proper nouns. After each noun write S for subject, DO for direct object, IO for indirect objects, OP for objects of prepositions, or SC for subject complements.


Mr. Stone will feed his cat tuna in the morning.

Answer 1: .*Stone S cat IO tuna DO morning OP
Correct. You have labeled correctly the function of all nouns in this sentence: Mr. Stone (S) cat (IO) tuna (DO) morning (OP)
Jump: Next page

Answer 2: ++(will|feed|his| in |the)
Sorry, you seem to have included one or more words that are not nouns.
Jump: This page

Answer 3: --Mr\. stone.*
Remember to capitalize the first letter of a proper noun.
Jump: This page

Answer 4: --(Mr\. Stone.*cat.*tuna.*morning.*)
No, I'm sorry. You may have omitted one, some, or all of the nouns. Also, they may be out of sequence.
Jump: This page

Answer 5: --.*S.*
Every sentence has a subject.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 6: --.*IO.*
This sentence has an indirect object.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 7: --.*DO.*
This sentence has a direct object.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 8: --.*OP.*
Sorry. You didn't seem to notice that morning is the object of a preposition.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.

After a couple of terms, it became clear to us that the most frequent errors were "cat DO &/or tuna IO" (a mistake I make myself). Here's the revised version. I haven't been able to break it yet.

Answer 1: .*Stone S cat IO tuna DO morning OP
Correct. You have labeled correctly the function of all nouns in this sentence: Mr. Stone (S) cat (IO) tuna (DO) morning (OP)
Jump: Next page

Answer 2: ++(will|feed|his| in |the)
Sorry, you seem to have included one or more words that are not nouns. These words are not nouns: <em>will, feed, his, in, the</em>.
Jump: This page

Answer 3: --(.*[sS]tone.*cat.*tuna.*morning.*)
No, I'm sorry. You may have omitted one, some, or all of the nouns. Also, they may be out of sequence.
Jump: This page

Answer 4: --.*S.*
Every sentence has a subject.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 5: --.*IO.*
This sentence has an indirect object.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 6: --.*DO.*
This sentence has a direct object.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 7: --.*OP.*
Sorry. You didn't seem to notice that morning is the object of a preposition.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 8: ++.*stone.*
Remember to capitalize the first letter of a proper noun.
Jump: This page

Answer 9: ++.*cat DO.*
I'm sorry, but <em>cat</em> is not a direct object.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
Jump: This page

Answer 10: ++.*tuna IO.*
No. <em>Tuna</em> is not an indirect object.

<em>Mr.Stone</em> is the subject. <em>Tuna</em> is the direct object because it receives the action of the verb <em>will feed</em>. <em>Cat</em> is the indirect object because it receives the object, <em>tuna</em>. <em>Morning</em> is the object of the preposition <em>on</em>.
In reply to ben reynolds

Re: Regular Expression Help Needed

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Ben,
I am willing to help but ... I don't understand what your problem is. Please specify.
Joseph