Class AgreementRule

java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.de.AgreementRule

public class AgreementRule extends org.languagetool.rules.Rule
Simple agreement checker for German noun phrases. Checks agreement in:
  • DET/PRO NOUN: e.g. "mein Auto", "der Mann", "die Frau" (correct), "die Haus" (incorrect)
  • DET/PRO ADJ NOUN: e.g. "der riesige Tisch" (correct), "die riesigen Tisch" (incorrect)
Note that this rule only checks agreement inside the noun phrase, not whether e.g. the correct case is used. For example, "Es ist das Haus dem Mann" is not detected as incorrect.

TODO: the implementation could use a re-write that first detects the relevant noun phrases and then checks agreement

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final List<List<org.languagetool.rules.patterns.PatternToken>>
     
    private static final org.languagetool.AnalyzedToken[]
     
    private final German
     
    private org.languagetool.JLanguageTool
     
    private static final Set<String>
     
    private static final Set<String>
     
    private static final Set<String>
     
    private static final String[]
     
    private static final Set<String>
     
    private static final org.languagetool.AnalyzedToken[]
     

    Fields inherited from class org.languagetool.rules.Rule

    messages
  • Constructor Summary

    Constructors
    Constructor
    Description
    AgreementRule(ResourceBundle messages, German language)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private boolean
    agreementWithCategoryRelaxation(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, AgreementRule.GrammarCategory categoryToRelax)
     
    private org.languagetool.rules.RuleMatch
    checkDetAdjNounAgreement(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3, org.languagetool.AnalyzedSentence sentence, int tokenPos)
     
    private @Nullable org.languagetool.rules.RuleMatch
    checkDetNounAgreement(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedSentence sentence, int tokenPos)
     
    private boolean
    couldBeRelativeOrDependentClause(org.languagetool.AnalyzedTokenReadings[] tokens, int pos)
     
    int
     
    private Set<String>
    getAgreementCategories(org.languagetool.AnalyzedTokenReadings aToken)
     
    List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule>
     
    private List<String>
    getCategoriesCausingError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2)
     
    private @Nullable org.languagetool.rules.RuleMatch
    getCompoundError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, int tokenPos, org.languagetool.AnalyzedSentence sentence)
     
    private @Nullable org.languagetool.rules.RuleMatch
    getCompoundError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3, int tokenPos, org.languagetool.AnalyzedSentence sentence)
     
     
     
    private int
    getPosAfterModifier(int startAt, org.languagetool.AnalyzedTokenReadings[] tokens)
    Search for modifiers (such as "sehr", "1,4 Meter") which can expand a determiner - adjective - noun group ("ein hohes Haus" -> "ein sehr hohes Haus", "ein 500 Meter hohes Haus") and return the index of the first non-modifier token ("Haus")
    private @Nullable org.languagetool.rules.RuleMatch
    getRuleMatch(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedSentence sentence, org.languagetool.AnalyzedTokenReadings nextToken, String testPhrase, String hyphenTestPhrase)
     
    private void
     
    private boolean
    isException(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2)
     
    private boolean
    isNonPredicativeAdjective(org.languagetool.AnalyzedTokenReadings tokensReadings)
     
    private boolean
    isParticiple(org.languagetool.AnalyzedTokenReadings tokensReadings)
     
    private boolean
    isRelevantPronoun(org.languagetool.AnalyzedTokenReadings[] tokens, int pos)
     
    org.languagetool.rules.RuleMatch[]
    match(org.languagetool.AnalyzedSentence sentence)
     
    private void
    replacePrepositionsByArticle(org.languagetool.AnalyzedTokenReadings[] tokens)
     
    private @NotNull Set<String>
    retainCommonCategories(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3)
     

    Methods inherited from class org.languagetool.rules.Rule

    addExamplePair, getCategory, getConfigureText, getCorrectExamples, getDefaultValue, getErrorTriggeringExamples, getIncorrectExamples, getLocQualityIssueType, getMaxConfigurableValue, getMinConfigurableValue, getSentenceWithImmunization, getUrl, hasConfigurableValue, isDefaultOff, isDefaultTempOff, isDictionaryBasedSpellingRule, isOfficeDefaultOff, isOfficeDefaultOn, makeAntiPatterns, setCategory, setCorrectExamples, setDefaultOff, setDefaultOn, setDefaultTempOff, setErrorTriggeringExamples, setIncorrectExamples, setLocQualityIssueType, setOfficeDefaultOff, setOfficeDefaultOn, setUrl, supportsLanguage, toRuleMatchArray, useInOffice

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • language

      private final German language
    • lt

      private org.languagetool.JLanguageTool lt
    • INS_REPLACEMENT

      private static final org.languagetool.AnalyzedToken[] INS_REPLACEMENT
    • ZUR_REPLACEMENT

      private static final org.languagetool.AnalyzedToken[] ZUR_REPLACEMENT
    • ANTI_PATTERNS

      private static final List<List<org.languagetool.rules.patterns.PatternToken>> ANTI_PATTERNS
    • MODIFIERS

      private static final Set<String> MODIFIERS
    • VIELE_WENIGE_LOWERCASE

      private static final Set<String> VIELE_WENIGE_LOWERCASE
    • REL_PRONOUN_LEMMAS

      private static final String[] REL_PRONOUN_LEMMAS
    • PRONOUNS_TO_BE_IGNORED

      private static final Set<String> PRONOUNS_TO_BE_IGNORED
    • NOUNS_TO_BE_IGNORED

      private static final Set<String> NOUNS_TO_BE_IGNORED
  • Constructor Details

  • Method Details

    • getId

      public String getId()
      Specified by:
      getId in class org.languagetool.rules.Rule
    • estimateContextForSureMatch

      public int estimateContextForSureMatch()
      Overrides:
      estimateContextForSureMatch in class org.languagetool.rules.Rule
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in class org.languagetool.rules.Rule
    • replacePrepositionsByArticle

      private void replacePrepositionsByArticle(org.languagetool.AnalyzedTokenReadings[] tokens)
    • match

      public org.languagetool.rules.RuleMatch[] match(org.languagetool.AnalyzedSentence sentence)
      Specified by:
      match in class org.languagetool.rules.Rule
    • getPosAfterModifier

      private int getPosAfterModifier(int startAt, org.languagetool.AnalyzedTokenReadings[] tokens)
      Search for modifiers (such as "sehr", "1,4 Meter") which can expand a determiner - adjective - noun group ("ein hohes Haus" -> "ein sehr hohes Haus", "ein 500 Meter hohes Haus") and return the index of the first non-modifier token ("Haus")
      Parameters:
      startAt - index of array where to start searching for modifier
      Returns:
      index of first non-modifier token
    • getAntiPatterns

      public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns()
      Overrides:
      getAntiPatterns in class org.languagetool.rules.Rule
    • isNonPredicativeAdjective

      private boolean isNonPredicativeAdjective(org.languagetool.AnalyzedTokenReadings tokensReadings)
    • isParticiple

      private boolean isParticiple(org.languagetool.AnalyzedTokenReadings tokensReadings)
    • isRelevantPronoun

      private boolean isRelevantPronoun(org.languagetool.AnalyzedTokenReadings[] tokens, int pos)
    • couldBeRelativeOrDependentClause

      private boolean couldBeRelativeOrDependentClause(org.languagetool.AnalyzedTokenReadings[] tokens, int pos)
    • checkDetNounAgreement

      @Nullable private @Nullable org.languagetool.rules.RuleMatch checkDetNounAgreement(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedSentence sentence, int tokenPos)
    • getCompoundError

      @Nullable private @Nullable org.languagetool.rules.RuleMatch getCompoundError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, int tokenPos, org.languagetool.AnalyzedSentence sentence)
    • getCompoundError

      @Nullable private @Nullable org.languagetool.rules.RuleMatch getCompoundError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3, int tokenPos, org.languagetool.AnalyzedSentence sentence)
    • getRuleMatch

      @Nullable private @Nullable org.languagetool.rules.RuleMatch getRuleMatch(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedSentence sentence, org.languagetool.AnalyzedTokenReadings nextToken, String testPhrase, String hyphenTestPhrase)
    • initLt

      private void initLt()
    • isException

      private boolean isException(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2)
    • getCategoriesCausingError

      private List<String> getCategoriesCausingError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2)
    • checkDetAdjNounAgreement

      private org.languagetool.rules.RuleMatch checkDetAdjNounAgreement(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3, org.languagetool.AnalyzedSentence sentence, int tokenPos)
    • agreementWithCategoryRelaxation

      private boolean agreementWithCategoryRelaxation(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, AgreementRule.GrammarCategory categoryToRelax)
    • retainCommonCategories

      @NotNull private @NotNull Set<String> retainCommonCategories(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3)
    • getAgreementCategories

      private Set<String> getAgreementCategories(org.languagetool.AnalyzedTokenReadings aToken)