Section 6.2.3 “How does pattern matching work?” explains that during pattern-matching the first one listed of a given length gets precedence and that this “means in some cases the order of your rules will be important”.
When might this be relevant? If a second rule that would match is ignored, is there ever a way for it to be used? Or is it just a dead rule?
Some good questions. Let me address them one by one.
-
When might two equal pattern length rules where one has precedence of the other be relevant?
Let’s say you have rule A that matches any noun. (A category is set up to match noun, e.g. tags: ‘n’, ‘n.*’). Also let’s say you have rule B that matches plural nouns. (A category is set up to match plural nouns, e.g. tags: ‘n.pl’, ‘n.pl.*’) If you place rule B after rule A, rule B will never get executed. Both rules are of equal pattern length in the categories being matched (1 pattern item), so the order of the rules comes into play. A word with category ‘n’ and suffix ‘pl’ will always be caught first by rule A. So in this situation you would want to put rule B before rule A. This way plural nouns get caught by rule B and other kinds of nouns fall through to rule A for handling. -
If a second rule that would match is ignored, is there ever a way for it to be used? I think the above answers that yes it can be used depending on the category.
-
Is a rule dead if it is in 2nd position of two equal pattern length rules? As we look at the situation described above, if rule A is before rule B, rule B it is essentially dead because rule A catches all words that you would want to be caught by rule B. However, if rule B is before rule A, rule A is not dead even though it is 2nd because rule B catches only a limited amount of possible words (in this case plural nouns). The rest fall through to rule A.
A general principle is to put more specific rules before more general rules when the rule pattern length is the same.
Thanks, that is helpful! So, the patterns (tags) for matching words by word class can be more specific by including affix patterns, too.
Yes. You can even match a word category + an exact lemma. Here’s an example:
In this case, presumably the lemma is unique, so you wouldn’t need to specify the tag; or would you?
You still have to specify the first tag, i.e. the grammatical category. That’s the way Apertium works.