Regular Expression and preview

Regular Expression and preview

by Mike Mazurkiewicz -
Number of replies: 12
Hello,

I am starting to use the Regular Expression for Short Answers plug-in for quizzes and also trying to get a handle on regex itself.

My first question is, the -- and &&. I cannot find any online reference to either of these notations except in relation to moodle. Are they specific to this plug-in's engine?

I have been trying various examples from sites, that seem to work but I get warning messages in previewing the question about various issues. Below is one example. But yet the system responds, kind of, that it is correct. It puts a red line through my response after I click submit, but gives it a green check mark and gives me the correct point value.

Will these warnings appear in the published quiz if I do not "fix" the problems?

When I preview, I get:
----------------------------------------
SORRY! Cannot generate sentences from a regExp containing one of these metacharacters: + * . { }

If you need to use one of them in your regExp as a LITERAL character, you must 'escape' it.
EXAMPLE: The [bc]at sat on the ma[pt]\.

Error in regular expression:--bsulcus lobe.{1,50}parientalb

Answer:
We are looking for frontal sulcus pariental lobe
(has green check to the right of box)

this is the sulcus lobe and the pariental
(red and strike though entire phrase)

Correct
Marks for this submission: 1/1.
-----------------------------------------
The question is configured as:
-----------------------------------------
Answer 1
Answer: There is no right answer here
Grade: 100%
Feedback:

Answer 2
Answer: --\bsulcus lobe\b
Grade: 100%
Feedback

Answer 3
Answer: --\bsulcus lobe.{1,50}pariental\b
Grade: 100%
Feedback
-----------------------------------------

Answer 3 was taken from a sample at http://www.seasite.niu.edu/trans/Regular_Expression_Tutorial.htm

This is on 1.8.4 on a SLES 10.2 server, if it matters.

Any help would be greatly appreciated.

Mike
Average of ratings: -
In reply to Mike Mazurkiewicz

Re: Regular Expression and preview

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hello Mike. Here are some answers to your questions (and some questions asking for clarification). Things would be more clear if you could write out in order a) the question text of your question; b) each answer c) each grade and d) each feedback. From your post I can reconstruct the following:
Question text ???
Answer 1
Answer: There is no right answer here
Grade: 100%
Feedback: ???
Answer 2
Answer: --\bsulcus lobe\b
Feedback: ???
Answer 3
Answer: --\bsulcus lobe.{1,50}pariental\b
Grade: 100%
Feedback ???
I'm afraid you have not understood the way the Short Answer Regular Expression question type works.
The only "correct" answer you are accepting for this question is Answer 1, "There is no right answer here". This is a rather strange wording. How can you be certain that the student will use exactly those words?
Answer 2 and Answer 3 are looking for the absence of some words in the student's response. If those words are absent, then the response will be incorrect, and grade should be 0%, not 100%.
But the contents of Answers 2 and 3 contradict the contents of the only correct answer, Answer 1, which should contain those words and doesn't! What do you expect to test by using the {1,50} condition in Answer 3?
The -- coding is indeed not standard Regular Expression syntax but is proper to the Moolde Regular Expression question type (as clearly stated in the online help).
I am quite willing to help you use this question type but I would need more clear statements of your objective with this question. What question are you asking? Which responses will you accept as correct? which responses will you treat as incorrect? etc.
Joseph

In reply to Joseph Rézeau

Re: Regular Expression and preview

by Mike Mazurkiewicz -
Hello Joseph,

Thank you for your reply. Sorry, this is not a true question any student would every get. I was trying to create a question with answers that would search for words/phrases in different orders. In this example, I am trying to test some examples of word searches I have found in online tutorials and examples. For this test, I am ignoring Answer 1. I understand the reason it is there, but I don't want to confuse myself while experimenting.

My wife, who teaches a neuroanatomy course is trying to search for words and phrases in the student answers. The four words that I am using are sulcus, lobe, pariental, and frontal.

The -- confused me because the only mention of its purpose is the statement: "This means that you must not enter as an answer with a grade higher than 0% a regular expression beginning with a double hyphen "--", used for detecting missing character strings." (online help file from the installation). I don't see any other explanation other than it being in the example questions in the document.

Right now I am trying to test the regex and nothing else. My biggest concern is that the regex syntax error message showing up in the question on preview and when I preview a quiz. This has been happening through most of my experimentation.

I need to know what is wrong with the syntax, or what I am missing in my very basic understanding of regex. I cannot find an issue based on my reading of regex, and the fact that the question responds with my choice being correct makes the error message even more puzzling.

The test question states: "We are looking for frontal sulcus pariental lobe" and what I would like to test are answers like:
1) The sulcus lobe is a part of the pariental ........
2) The answer is the pariental and the sulcus lobe......
where the answers "sulcus lobe" with "pariental" are one answer and the opposite order "pariental" and "sulcus lobe" is the other order.

Also, my wife was using the regex questions in a quiz and the item analysis page after the quiz was blank. Is Item Analysis not available with this question type?

Sorry for the confusing post.

PS: I wish I would have listened to my teacher for French-Canadian so I could read your site. Although just before finalizing my post I did find your page on Regular Expressions.

Mike
In reply to Mike Mazurkiewicz

Re: Regular Expression and preview

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Mike > The test question states: "We are looking for frontal sulcus pariental lobe" and what I would like to test are answers like:
1) The sulcus lobe is a part of the pariental ........
2) The answer is the pariental and the sulcus lobe......
where the answers "sulcus lobe" with "pariental" are one answer and the opposite order "pariental" and "sulcus lobe" is the other order.

I'm afraid I have no idea whatsoever what a "frontal sulcus pariental lobe" is. Anyway, could you clarify further by providing a real question and a number of potential student responses, stating which words or groups of words would make those responses correct and which words or groups of words would make the responses incorrect.

The reason you are getting the the regex syntax error message showing up in the question preview mode is that my regexp question engine is trying to construct valid alternative answers and cannot do it because it encounters "forbidden" regexp reserved characters in Answers with a score other than 0%. Have you visited my Demo course on my moodle test site and looked at all the detailed explanations and examples? (login as student1, password student1 or teacher1, password teacher1).

Joseph

In reply to Joseph Rézeau

Re: Regular Expression and preview

by Mike Mazurkiewicz -
Hello Joseph,

I have visited your site, but all the documents come up with, "Sorry, the requested file could not be found" message.

Below is a sample question from one of my wife's current short answer questions:

The included PNG file is the question.

Question text:

Name the specific area or region of cortex marked in purple.



Answer 1: auditory cortex
Grade:100%
Feedback: Good

Answer 2: * auditory cortex
Grade: 100%
Feedback: Good

Answer 3: auditory
Grade: 100%
Feedback: Good

Answer 4: Heschel's gyrus
Grade: 100%
Feedback: Good

Answer 5: auditory cortex (heschel's gyrus)
Grade: 100%
Feedback: Good

Answer 6: * auditory
Grade: 100%
Feedback: Good

Using the item analysis these were the responses she wanted to mark as correct. She is not looking for any incorrect responses.

I don't understand how standard regex syntax can be forbidden. I have numerous sites that use the \b for word boundary in their expressions and i have tested them using at least 3 different testing applications.

Mike
In reply to Joseph Rézeau

Re: Regular Expression and preview

by Mike Mazurkiewicz -
Ok, I played a little more with your site and experimenting with the questions on my site and this is my understanding.

1) I think I have figured out the -- notation. When using it with a None grade, it does not display the feedback after Submit.

2) Any Anchor or Character Class cannot be used in a question with a grade greater than zero. If I do, the errors start appearing on preview. I would assume that would include the Special Character, but have not tried them as they are not being used in the questions.

If my observations are correct, I guess I don't understand the limitation of regex with the grade assigned to the answer. I thought that no matter the grade assign to any particular answer the full complement of regex functionality would be available.

What I am trying to accomplish that I cannot do with the standard Short Answer is the search for phrases and sometimes, the correct order of the phrases (the * is very weak in my opinion). She needs to streamline and get more automated grading of these quizzes, and the use of regex seemed to be the answer. For some reason 2nd year optometry students (professionals supposedly!) cannot read or understand that short answers are a phrase or a sentence at most, not a full paragraph. And my wife has to repeat this over and over and over to them before and during the quiz (quizzes are only available onsite and in person in a computer/biology lab).

I hope this better explains what I am looking for and the reasoning.

Mike

In reply to Mike Mazurkiewicz

Re: Regular Expression and preview

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

Hi Mike,

I have visited your site, but all the documents come up with, "Sorry, the requested file could not be found" message.

Which site? I do not understand what you mean by "requested file could not be found" message. Could you be more specific?

Thanks for the complete list of "expected correct answers" to the "auditory cortex" question. I'm afraid that you have got the wrong idea of what the REGEXP question type can achieve, or rather that you have set your expectations too high. Let's have a look at the correct expectd answers first.

Answer 2: * auditory cortex

Correct syntax should be .*auditory cortex (note the dot, meaning any character).

But this would accept as correct any of the following student responses:

  • auditory cortex
  • it's the auditory cortex
  • it can't be the auditory cortex
  • not the auditory cortex
  • etc. etc.
"I don't understand how standard regex syntax can be forbidden."

The logic of my REGEXP question type is that any regular expression syntax used in an answer accepted as correct (score > 0%) should enable the system to generate a finite number of alternative correct answers. Finite means any number from 1 to n. Your Answer 2 (even with the correct .* syntax) will be rejected by the system because it would yield an infinite number of acceptable answers... including wrong ones, which is of course illogical. These are the cases where, to answer your query "standard regex syntax is forbidden".

Answer 3: auditory Grade: 100%

I'm surprised that you would give this incomplete answer a 100% grade?!

" Using the item analysis these were the responses [my wife] wanted to mark as correct. She is not looking for any incorrect responses."
"[my wife] needs to streamline and get more automated grading of these quizzes, and the use of regex seemed to be the answer."

Oops! Again, if this is what you want to achieve you are way off the mark. My REGEXP question type was intended from the start for quizzes made for learning, not for testing/exams. I am primarily interested in providing adequate feedback for incorrect responses, I am not interested in automated grading of quizzes.

Here are the details of the question I have put in Mike's quiz in the Demo Course on my moodle test site, where you can experiment with it.

  • Answer | Grade | Feedback message
  • auditory cortex 100% ok
  • Heschl's gyrus/i 100% Yes, that's another name for the <em>auditory cortex</em>.
  • *\bcortex\b.* 0% Yes, it's a cortex, but which one? motor? premotor? visual? etc.
  • .*(Heschel|Hechel|Heshel|eschel|eshel|Hescel).*/i 0% You misspelt Heschl's name. Try again.
  • --.*\bgyrus\b.* 0% How about a gyrus (a ridge on the cerebral cortex)?
  • .* 0% Try again.

All the best,

Joseph

In reply to Joseph Rézeau

Re: Regular Expression and preview

by Peter Allen -

Hi Joseph

I am having trouble getting the regexp to work properly.

I am using moodle 1.9 and when I ad a question to a quiz I choose Cloze question.

I make a txt file (notepad) with your example question "What colours are the French flag?" and import that. Where is Answer 1 box that I type the regular expression into?

I type the expression into where I think it goes and import to moodle. It shows as this in question 1:

What colour is the French flag? {1:SHORTANSWER:=blue, white and red#Correct!~=it's blue, white(,| and) red#Correct!}

When I decode and verify it I get this:

Question {#1} Short Answer

In reply to Peter Allen

Re: Regular Expression and preview

by Jeff Forssell -

When you write like that you are just using the ordinary CLOZE short answer type. It should be REGEXP not SHORTANSWER!

See: http://joseph.rezeau.pagesperso-orange.fr/moodle/regexp.html

Average of ratings: Useful (1)
In reply to Jeff Forssell

Re: Regular Expression and preview

by Peter Allen -

Thanks Jeff

I withdraw my question. I have my regular expression modules and plug ins mixed up.

 

Sorry to have disrupted this forum.

 

Peter

In reply to Peter Allen

Re: Regular Expression and preview

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers

Peter, you may miss Preg module for some time, and that's exactly because I added installation instructions as you requested - it go on moderation and vanish from sight of other people. Now it should be accessible once more.

P.S. If you have any questions about using preg, the best way to get answer quickly is to send me a personal message on the moodle.org. I (sadly) receive no notifications about commentaries on module entry.

In reply to Oleg Sychev

Re: Regular Expression and preview

by Peter Allen -

Thanks Oleg I have now found the installation instructions.

Thanks again.

In reply to Mike Mazurkiewicz

Re: Regular Expression and preview

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers

Hi, Mike.

Did you try Preg question type ( http://moodle.org/mod/data/view.php?d=13&rid=1901&filter=1 )? It's an alternative plugin, fully compatible with regex-syntax. You could use character classes, anchoring, assertions etc.

Sadly, it doesn't have Hint facility for now (I hope to release it for 2.0), but it could in stable give you anything regular expression could (in the docs page I even placed a way to achieve "--" effect with usual regular expressions). There are extensive docs on the regular expression syntax, iI could post you links from them if you need them.

Just remember, if you want stable version, you should use "for 1.9" link for downloading, if you want to play with new "hint" features under Moodle 2.0, than you should download "latest" version, but it is alpha quality still.