Learning how to use it is not easy, but once you have learned, it is very powerful.
Many thanks for your prompt feedback! I will ask for the installation of the pmatch type to our admin. May I dare asking it could it be possible to have one example question in Moodle xml format that I can compare to?
Well, the best way to start is to read https://www.open.edu/openlearncreate/mod/oucontent/view.php?id=52747§ion=2.2.1 - and if you follow through creating the example there, you will end up with an example question (that is at the more complicated end of the normal range. Many questions just have a single matching rule.)
If you have the time to learn properly, this course is good https://www.open.edu/openlearncreate/course/view.php?id=1643, but it is strict, and it forces you to work through it in order.
I don't have a complete XML of a question I can share, but
match(Pb<sup>2+</sup> + 2Cl<sup>-</sup> = PbCl<sub>2</sub> )
is a match expression that will match
+ 2Cl<sup>-</sup>(aq) = PbCl<sub>2</sub>(s)
Obviously, you want to use the _o option to ignore word order, but only before and after the ->. I think that is doable, but I will need to re-remeber how.
Also, like other question types, we shoudl include some sample questions when you install it, but we keep not getting time to do that. Sorry.
Again many thanks for the feedback. I will try to work it out and let you know the result. After testing, I will share my questions, in case you will deem them of sufficient quality for other users.
I had also the subscript/superscript plugin installed. I have taken the following reaction:
PbO2 + Cl-
which should yield:
PbO2 + 2Cl- + 4H+ = Pb2+ + Cl2 + 2H2O
and coded these two matches after the example in the first link:
match_all (match_o (PbO<sub>2</sub> + 2Cl<sup>-</sup> + 4H<sup>+</sup>) match_o (Pb<sup>2+</sup> + Cl<sub>2</sub> + 2H<sub>2</sub>O))
match (PbO<sub>2</sub> + 2Cl<sup>-</sup> + 4H<sup>+</sup> = Pb<sup>2+</sup> + Cl<sub>2</sub> + 2H<sub>2</sub>O)
But only the second one is matched when I enter the correct answer. Am I missing something?
p.s.: I tried to subscribe to see the second link but I can't get through the password generation.
Could using Unicode characters simplify your work? <sup> and <sub> would not be required.
Here is your example with Unicode characters:
PbO₂ + 2Cl⁻ + 4H⁺ = Pb²⁺ + Cl₂ + 2H₂O
(However, this can be a good trick for question authors who only need super/subscripts in the question text, or multiple choice choices, etc.
Right, I think I have worked this out, but it is not obvious how to do it.
Can I start by saying that, if you have not already discovered it, you need to be using the question testing tool. Once you have created a first attempt at the question, preview it, then click the little 'Test this question' link. That opens a page where you can input various possible responses to your question, and whether you think they should be graded right, and then it will show you whether the grading rules you currently have set up give that result.
And, you will not that for simplicity, while working this out, I just used single letters like A, in place of things like PbO<sub>2</sub>, but it should work fine when you put back the full thing.
So, for my example, I was trying to match A + B = C + D, with the bits before and after the = in any order.
The trick seems to be to do one match to check we have all the right words in any order, and then say that A and B must be before the =, and C and D after it:
match_all ( match_o (A + B = C + D) match_w (A =) match_w (B =) match_w (= C) match_w (= D) )
That comes close, but does not exclude nonsense like A B + = C + D. The way to do that is to first exclude any response that matches has 2 letters (that can be on the same side of the = sign) next to each other. This uses the _p0 matching rule in combination with _
match_any ( match_wp0 (A_B) match_wp0 (B_A) match_wp0 (C_D) match_wp0 (D_C) )
You could combine this bit of expression with the one above, using not(), but rather that having really complicated match expressions, I did in another way. In the editing form I used two answer:
- Answer 1: [second match rule from above] - if this matches set grade to None, with feedback like "Your expression does not seem to be formatted correctly. Each term should be separated by a +."
- Answer 2: [first match rule from above] - if this matches, set grade to 100%, with feedback like "Well done, that seems to be a correct answer."
- Any other answer: feedback like "That does not seem to be correct."
(Note, if Answer 1 matches, that determines the grade, and Answer 2 is not considered.)
Sample question attached. Hopefully you can see how to extend it to your real example.
Also, a good tip for working on these questions is to have the "Pattern-match question testing tool" open in one browser tab, and the Edit question form open in another. Then you can change the question a bit, click 'Save changes and continue editing', switch to the other tab and reload the sample responses table and see how things are working, then switch back to the editing tab and try another change, ...
(The reason your first match expression does not match is that you said match_o(half the answer), but if you want to match only half the answer, you need to specify the _w modifier, to say other words are allowed. However, if you say that, then you cannot prevent other words appearing between the correct bits, so this approach does not seem to work for this question.)
As a side note, I had actually tried the testing tool but, at least in the version that we have installed, it cannot import subscripts and superscripts.
Tim "So, for my example, I was trying to match A + B = C + D, with the bits before and after the = in any order."
Your pmatch expression does not take into account the presence or absence of blank spaces between the various items.
I've tried your example in my REGEXP question type (example attached). The following expression accounts for permutations and accepts any combination of blank spaces. It yields 258 possibilities!
PS. Why don't we have a "code" format button in this forum toobar to insert code that won't be interpreted?