Pattern match

Question types ::: qtype_pmatch
Maintained by Tim at Lone Pine Koala SanctuaryTim Hunt, Phil Butcher
Allows a short response of one or a few sentences that is graded by comparing against various model answers, which are described using the OU's pattern match syntax.
Latest release:
1689 sites
42 fans
Current versions available: 11

There are working examples in eAssessment with Moodle on our OpenLearn site.

The documentation is in How to create questions in Moodle on that site.


This plugin is part of set Open University.


Screenshot #0


Tim at Lone Pine Koala Sanctuary
Tim Hunt (Lead maintainer)
Phil Butcher: Question type designer
Jamie Pratt: Developer
Colin Chambers: Developer
John Beedell: Developer
Chris Nelson: Product owner
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Tim at Lone Pine Koala Sanctuary
    Tue, Sep 10, 2019, 8:15 PM
    See This error only happens in you are using PHP 7.0. I carelessly added a PHP 7.1-style construct to the code. Sorry.
  • Wed, Sep 11, 2019, 8:46 PM
    Thank you for replying Tim. I'm going to keep my current version until I could afford to upgrade PHP. smile
  • Thu, Dec 5, 2019, 11:00 PM
    Hi Tim and others maintaining, We love the Pattern Match question! In fact, I had someone build a combination of Pattern Match and Essay, to incorporate a larger textfield and answertemplate. We call it 'Pattern Essay and will make it available soon. However, I also encountered a bug. When using a large string of keywords (eg. 1|2|3 and so on until over 21) and then choosing answer 2 (eg. 17 keywords), 3 (eg. 14 keywords) and 4 (eg. 10 keywords) as options for 90%, 60% and 50% scores, students scoring less than 100% received a time-out error during the quiz and re-attempting it later. It took us some time to figure out the problem smile. Does this ring a bell with any of you?
  • Tim at Lone Pine Koala Sanctuary
    Thu, Dec 5, 2019, 11:22 PM
    That sounds like it is probably a performance problem. The pattern match library is quite complex, and not necessarily fast, particuarly as the patterns and the student response both get longer. (There is a reason the standard question type limits the response to 20 wrods at most.)

    It probably could be improved if anyone was brave enough to dive into the code. Initially our priority was to get it to implement the matching correctly, and that was hard enough. Optimising performance is not something we have done much work on.
  • Sun, Jan 19, 2020, 6:00 AM
    The PMatch question type is both awesomely useful and deeply frustrating at the same time. Thanks for all the support on it Tim. A couple of bug reports / feature requests:
    - A bug: Proper nouns fall foul of the spell checking logic. For example, if you include the word Greek in your typed answer, the code converts it to greek before sending it to the spell checker. Aspell then chucks it out as a spelling error, even though aspell has a case insensitive option and Greek is in its dictionary.
    - Optional words / phrases: I could vastly simplify the rules for many of my more exact questions just by being able to add an empty alternative using the or symbol, either by | on its own or perhaps |[]. Sometimes I can achieve the same effect if there is a simple anchor word before or after but often the words before or after are alternatives too and things get ugly fast.
    - More selective match_w option: often I want to allow extra words only before or after the match but not _in_ the match clause - making it possible to pick out one particular phrase or ignore extra detail or examples without rewriting the answer rules. You can do this with _ and p control, but it can get very fiddly.
    - Support for multiple possible pmatch answers in the combined question.
    - This is a kicker, and might be better handled via some option in the combined question. Often I want the student to include multiple answers. E.g. "State three reasons for the fall of the Weimar Republic" or "Describe three features of a contemporary CPU that improve performance". What I don't want is the student to be able to give the same (or same meaning) answer multiple times, and I want to give them credit for fewer than 3. The number of permutations becomes ridiculous very fast. For four requested out of four in the main pmatch, it's Answer 1 (100%): match all of 4 x match 1 possibilities + Answer 2 (75%): match any of 4 x match all of 3 x match 1 possibilities + Answer 3 (50%): match any of 2 x match all of 2 x match any of 2 x match 1 possibilities Answer 4 (25%): match any of 4 x match 1 possibilities. That is 28 items, the same four matches repeated seven times. This could perhaps either be handled by having a match_n operator in the pmatch question type and/or allowing the combined question type to give tags to any answer that can only be used once across the whole question.
  • Mon, Jan 20, 2020, 4:33 PM
    @Stephen Parry.
    Thanks very much for the feedback, Stephen. Given the amount of feedback, it might be easier for Tim and/or I to discuss if you posted each separately in the forums.
    1) We'll check this as that does sound wrong (but just to check, has case sensitivity been switched on, and has 'Greek' been added to the question settings dictionary?).
    2) In a forum post, could you expand on this, including an example question or two, please? It really helps us understand PMatch limitations when we see how others are trying to use it..
    3) In a forum post, could you expand on this, including an example question or two, please? In general, aye, that's also on our improvement list for PMatch, although quite far down.
    4) The Combined PMatch sub-question was designed as a lightweight implementation, and we did that to try to keep the Question Editing Form as short and clean as could. We're currently making a few other changes to Combined though (adding single choice and shuffling/list options for single choice and multiple response - hopefully this will be available within the next few weeks), so we'll review.
    5) We wouldn't want to promise anything specific at this stage, but we've been thinking for a while now about a new form of PMatch (tentatively called the "PMatch Sets" question type) that would allow educators to ask that sort of question. If we're lucky, we might start formal development in our next dev quarter. Once we release it, we'll bundle it with normal PMatch as a plug-in set. And then we'll make it available as a Combined sub-question type too.
  • Mon, May 18, 2020, 12:13 PM
    Hi Tim,
    Do you intend to update this for 3.9 when it's out?
  • Tim at Lone Pine Koala Sanctuary
    Mon, May 18, 2020, 4:50 PM
    Of course. Though I cannot promise exactly when. It will depend on when I can find time. But, if you check, you will find that all my plugins are up-to-date with released Moodle versions.

    (Also, it is rare for a upgrade to break a plugin. You don't have to wait, you can always test the current plugin with the latest Moodle. There are good chances it will work. If you share you results here, that is a useful contribution to make.)
  • Wed, Aug 26, 2020, 6:44 PM
    Hi guys - I've been spear-heading this amazing question type at our institution since last year. I do not know where to report bugs, but something weird is happening. I have a question that needs superscripts for correct input (i.e. a formula). Last year we used it in the exam with 100% success (really truly amazing as there were over 800 unique answers). Now the same question is broken? I have tracked the issue to the following. The text I am looking for is programmed in as follows:

    match_w (2n)

    this will not work, but if I tell pmatch to remove '<' and '>' and convert to space, then the following

    match_w (2 sup n /sup)

    now works. It is a very bizarre thing. Note also that the subscript version does work, so ... weird. Is there any reason for this?

  • Tim at Lone Pine Koala Sanctuary
    Wed, Aug 26, 2020, 6:46 PM
    Best place to report bugs is the 'Bug tracker' link above.

    If possible, please attach an example question exported in Moodle XML format. (In the past, github did not like XML attachments. If that is still an issue just rename to .txt.)
  • Tue, Nov 17, 2020, 7:52 PM
    Hi guys - I apologize if this is the wrong place to post this, but I was thinking that it could be nice to have a way to manually grade answers that were not picked up by the pattern-match algorithm. I fine with some answers, I can get the pattern-match to find 90% of the answers, but the last few have a few that are right, but difficult to code in due to arbitrary things like spelling or not putting a space in. I know you can manually grade already, but then you have to wade through all the answers - having some sort of filter would be great.

    kind regards - Gareth
  • Tue, Nov 17, 2020, 8:16 PM

    Well... we'd kinda expect admins to go to the Quiz grading for manual corrections. But really, you should be able to cope with spelling (e.g. enable dictionary), synonyms, and ignoring spaces in the question settings. I appreciate that I'm inferring on very little data, but it suggests that the issue lies with the question wording or pattern-matching logic, although it could point to an oversight with what we've made available. I guess some examples of the specific problem would help us see if we need to add/tweak things. But don't forget about the 'Test this question' link that lets you import/review and check answers, to spot any holes in the pattern-matching ahead of 'live' student use.
  • Wed, Nov 18, 2020, 2:58 AM

    It is the quiz grading for manual corrections I am talking about. I have had situations where the variations in the answers (I am in chemistry) were just too many to properly catch in the pattern-match algorithm. I know we should aim for 97% and one or two mistakes can creep in, but when you go to manual grading there is no option to just grade the ones that were never matched. This could be a useful feature where partial pattern-matching allows, for example, removing obviously incorrect answers, minimising the amount of manual grading that needs to be done.

    I do need to say that this question type is amazing - I use it in course of close to 1000 students with two languages. My only real issue is one that IT have fobbed off, and that is the processing time that it takes every time I make a change and want to check during grading. Otherwise the thing I am mentioning above would just be a nice feature.
  • Fri, Nov 20, 2020, 4:02 PM
    Sounds interesting smile Would you mind starting a forum post and sharing a worked example (obviously feel free to alter the question a bit) highlighting the precise frustration. I will then also talk to some internal PMatch users about the same situation, and Tim and I can see what we can do. However, we're super-busy at the moment, so it will take awhile for any improvements to happen.
  • Wed, Aug 18, 2021, 2:29 PM
    How can this be integrated with a chat system? Students are typing answers on a web interface for questions asked in the chat . Is it possible to do that via an API?
1 2 3 4 5
Please login to post comments