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)
TODO: the implementation could use a re-write that first detects the relevant noun phrases and then checks agreement
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.languagetool.AnalyzedToken[]private final Germanprivate org.languagetool.JLanguageToolprivate static final String[]private static final org.languagetool.AnalyzedToken[]Fields inherited from class org.languagetool.rules.Rule
messages -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanagreementWithCategoryRelaxation(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, AgreementRule.GrammarCategory categoryToRelax) private org.languagetool.rules.RuleMatchcheckDetAdjNounAgreement(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3, org.languagetool.AnalyzedSentence sentence, int tokenPos) private @Nullable org.languagetool.rules.RuleMatchcheckDetNounAgreement(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedSentence sentence, int tokenPos) private booleancouldBeRelativeOrDependentClause(org.languagetool.AnalyzedTokenReadings[] tokens, int pos) intgetAgreementCategories(org.languagetool.AnalyzedTokenReadings aToken) List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getCategoriesCausingError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2) private @Nullable org.languagetool.rules.RuleMatchgetCompoundError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, int tokenPos, org.languagetool.AnalyzedSentence sentence) private @Nullable org.languagetool.rules.RuleMatchgetCompoundError(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2, org.languagetool.AnalyzedTokenReadings token3, int tokenPos, org.languagetool.AnalyzedSentence sentence) getId()private intgetPosAfterModifier(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.RuleMatchgetRuleMatch(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedSentence sentence, org.languagetool.AnalyzedTokenReadings nextToken, String testPhrase, String hyphenTestPhrase) private voidinitLt()private booleanisException(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2) private booleanisNonPredicativeAdjective(org.languagetool.AnalyzedTokenReadings tokensReadings) private booleanisParticiple(org.languagetool.AnalyzedTokenReadings tokensReadings) private booleanisRelevantPronoun(org.languagetool.AnalyzedTokenReadings[] tokens, int pos) org.languagetool.rules.RuleMatch[]match(org.languagetool.AnalyzedSentence sentence) private voidreplacePrepositionsByArticle(org.languagetool.AnalyzedTokenReadings[] tokens) 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
-
Field Details
-
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
-
MODIFIERS
-
VIELE_WENIGE_LOWERCASE
-
REL_PRONOUN_LEMMAS
-
PRONOUNS_TO_BE_IGNORED
-
NOUNS_TO_BE_IGNORED
-
-
Constructor Details
-
AgreementRule
-
-
Method Details
-
getId
- Specified by:
getIdin classorg.languagetool.rules.Rule
-
estimateContextForSureMatch
public int estimateContextForSureMatch()- Overrides:
estimateContextForSureMatchin classorg.languagetool.rules.Rule
-
getDescription
- Specified by:
getDescriptionin classorg.languagetool.rules.Rule
-
replacePrepositionsByArticle
private void replacePrepositionsByArticle(org.languagetool.AnalyzedTokenReadings[] tokens) -
match
public org.languagetool.rules.RuleMatch[] match(org.languagetool.AnalyzedSentence sentence) - Specified by:
matchin classorg.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:
getAntiPatternsin classorg.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
-
initLt
private void initLt() -
isException
private boolean isException(org.languagetool.AnalyzedTokenReadings token1, org.languagetool.AnalyzedTokenReadings token2) -
getCategoriesCausingError
-
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
-
getAgreementCategories
-