Back to LanguageTool Homepage - Privacy - Imprint

Rule Uniqueness

I am using the LanguageTool Java API and am trying to use JLanguageTool.disableRule(ruleId) and am running into some problems.

  1. Rule.getId() is supposed to be unique but that is not always the case. For example with AbstractPatternRule, there is a subId. In fact JLanguageTool.getAllRules() documents the following:

Please note that XML rules that are grouped will appear as multiple rules with the same id. To tell them apart, check if they are of type AbstractPatternRule , cast them to that type and call their AbstractPatternRule.getSubId() method.

I have noticed that even with the Id and the subId, some rules are still not unique i.e. there are two PatternRules with an ID of PER_PER_A_PIANO and a subId of 2. There are many more examples of this.

My question is, given a RuleMatch, how can I allow a user to disable just the rule for this RuleMatch. The JLanguageTool.disableRule(ruleId) is not granular enough to disambiguate any Rules that have a subId.

PER_PER_A_PIANO uses <or>, which is internally expanded into two rules. I don’t think there’s way to tell apart the two rules. If you think it really makes sense to turn off one, but not the other, it might make more sense to send a bug report with an example here. We might then decide to have two rules instead, which will automatically have two IDs.