Back to LanguageTool Homepage - Privacy - Imprint

Order of rules

(Michael) #1

If a token triggers two rules, which suggestion will be shown to the user? Is it always the first one appearing in grammar.xml?

(Daniel Naber) #2

There's no defined order. If you want to force an order you can do so in e.g. German.getPriorityForId() by returning a higher number for the "better" rule.

(Lodewijk Arie van Brienen) #3

That's de jure ordering. (EG: we have no officially defined order for those POSTAG-rules)
What he's asking about is the de facto ordering. (EG: unless stated otherwise POSTAG-rules are handled based on their file position.)

(Daniel Naber) #4

I don't know that ordering, you'd need to test it. But I don't see how it matters, as the behavior can change any time. Actually, depending on the internal data structures, it might even be random.

(Lodewijk Arie van Brienen) #5

In computing nothing is truly random, but it might be a good idea to set up some default ordering-rules (to be used when there is no explicit priority).

(Andriy) #6

IMHO the de-facto order in web-interface is reversed (the last rule matched wins), we even adjusted web-extension code to produce the same behavior (as it was reverse):

(jaumeortola) #7

We filter overlapping rules here. If there is no priority established, we choose the match with the longest string. If the lengths are the same, we choose the last one (mimicking the web-interface behavior).
This filter is used in LT server and LibreOffice, but not in LT command-line or LT GUI (because these are testing environments and it is preferable to see all the results).