Package org.languagetool.rules.de
Class AgreementRule
java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.de.AgreementRule
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)
- DET/PRO ADJ ADJ NOUN: e.g. "der große riesige Tisch" (correct), "die große riesige 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 ClassesModifier and TypeClassDescription(package private) static enum(package private) static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final List<List<PatternToken>> private final Supplier<List<DisambiguationPatternRule>> private static final Patternprivate static final AnalyzedToken[]private final Germanprivate JLanguageToolprivate static final Patternprivate static final Stringprivate static final Stringprivate static final Patternprivate static final String[]private static final Stringprivate static final Patternprivate static final Patternprivate static final Patternprivate static final AnalyzedToken[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanagreementWithCategoryRelaxation(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AgreementRule.GrammarCategory categoryToRelax) private RuleMatchcheckDetAdjAdjNounAgreement(AnalyzedTokenReadings maybePreposition, AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedTokenReadings token4, AnalyzedSentence sentence, int tokenPos, Map<Integer, AgreementRule.ReplacementType> replMap, String skippedStr) private RuleMatchcheckDetAdjNounAgreement(AnalyzedTokenReadings maybePreposition, AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedSentence sentence, int tokenPos, Map<Integer, AgreementRule.ReplacementType> replMap, String skippedStr) private RuleMatchcheckDetNounAgreement(AnalyzedTokenReadings maybePreposition, AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedSentence sentence, int tokenPos, Map<Integer, AgreementRule.ReplacementType> replMap, String skippedStr) private booleancouldBeRelativeOrDependentClause(AnalyzedTokenReadings[] tokens, int pos) intA number that estimates how many words there must be after a match before we can be (relatively) sure the match is valid.Overwrite this to avoid false alarms by ignoring these patterns - note that yourRule.match(AnalyzedSentence)method needs to callRule.getSentenceWithImmunization(org.languagetool.AnalyzedSentence)for this to be used and you need to checkAnalyzedTokenReadings.isImmunized()getCategoriesCausingError(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2) private RuleMatchgetCompoundError(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, int tokenPos, AnalyzedSentence sentence) private RuleMatchgetCompoundError(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, int tokenPos, AnalyzedSentence sentence) private RuleMatchgetCompoundError(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedTokenReadings token4, int tokenPos, AnalyzedSentence sentence, String skippedStr) A short description of the error this rule can detect, usually in the language of the text that is checked.getId()A string used to identify the rule in e.g.private intgetPosAfterModifier(int startAt, 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 RuleMatchgetRuleMatch(AnalyzedTokenReadings token, AnalyzedTokenReadings token2, AnalyzedSentence sentence, String testPhrase, String hyphenTestPhrase) private voidinitLt()private booleanisException(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2) private booleanisNonPredicativeAdjective(AnalyzedTokenReadings tokensReadings) private booleanisParticiple(AnalyzedTokenReadings tokensReadings) private booleanisRelevantPronoun(AnalyzedTokenReadings[] tokens, int pos) match(AnalyzedSentence sentence) Check whether the given sentence matches this error rule, i.e.private Map<Integer, AgreementRule.ReplacementType> retainCommonCategories(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3) retainCommonCategories(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedTokenReadings token4) Methods inherited from class org.languagetool.rules.Rule
addExamplePair, addTags, addToneTags, cacheAntiPatterns, getCategory, getCorrectExamples, getDistanceTokens, getErrorTriggeringExamples, getFullId, getIncorrectExamples, getLocQualityIssueType, getMinPrevMatches, getPriority, getRuleOptions, getSentenceWithImmunization, getSourceFile, getSubId, getTags, getToneTags, getUrl, hasTag, hasToneTag, isDefaultOff, isDefaultTempOff, isDictionaryBasedSpellingRule, isGoalSpecific, isIncludedInHiddenMatches, isOfficeDefaultOff, isOfficeDefaultOn, isPremium, makeAntiPatterns, setCategory, setCorrectExamples, setDefaultOff, setDefaultOn, setDefaultTempOff, setDistanceTokens, setErrorTriggeringExamples, setExamplePair, setGoalSpecific, setIncludedInHiddenMatches, setIncorrectExamples, setLocQualityIssueType, setMinPrevMatches, setOfficeDefaultOff, setOfficeDefaultOn, setPremium, setPriority, setTags, setToneTags, setUrl, supportsLanguage, toRuleMatchArray, useInOffice
-
Field Details
-
MIT_MIR_ETC
-
OHNE_MICH_ETC
-
ZUGESCHRIEBENEN_GENANNTEN
-
VIEL_WEIT
-
WENIGER_EHER
-
HERR_FRAU
-
language
-
antiPatterns
-
lt
-
INS_REPLACEMENT
-
ZUR_REPLACEMENT
-
MSG
- See Also:
-
MSG2
- See Also:
-
SHORT_MSG
- See Also:
-
MODIFIERS
-
VIELE_WENIGE_LOWERCASE
-
REL_PRONOUN_LEMMAS
-
PRONOUNS_TO_BE_IGNORED
-
NOUNS_TO_BE_IGNORED
-
allAntiPatterns
-
-
Constructor Details
-
AgreementRule
-
-
Method Details
-
getId
Description copied from class:RuleA string used to identify the rule in e.g. configuration files. This string is supposed to be unique and to stay the same in all upcoming versions of LanguageTool. It's supposed to contain only the charactersA-Zand the underscore. -
estimateContextForSureMatch
public int estimateContextForSureMatch()Description copied from class:RuleA number that estimates how many words there must be after a match before we can be (relatively) sure the match is valid. This is useful for check-as-you-type, where a match might occur and the word that gets typed next makes the match disappear (something one would obviously like to avoid). Note: this may over-estimate the real context size. Returns-1when the sentence needs to end to be sure there's a match.- Overrides:
estimateContextForSureMatchin classRule
-
getDescription
Description copied from class:RuleA short description of the error this rule can detect, usually in the language of the text that is checked.- Specified by:
getDescriptionin classRule
-
replacePrepositionsByArticle
private Map<Integer,AgreementRule.ReplacementType> replacePrepositionsByArticle(AnalyzedTokenReadings[] tokens) -
match
Description copied from class:RuleCheck whether the given sentence matches this error rule, i.e. whether it contains the error detected by this rule. Note that the order in which this method is called is not always guaranteed, i.e. the sentence order in the text may be different from the order in which you get the sentences (this may be the case when LanguageTool is used as a LibreOffice/OpenOffice add-on, for example). In other words, implementations must be stateless, so that a previous call to this method has no influence on later calls. -
getPosAfterModifier
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
Description copied from class:RuleOverwrite this to avoid false alarms by ignoring these patterns - note that yourRule.match(AnalyzedSentence)method needs to callRule.getSentenceWithImmunization(org.languagetool.AnalyzedSentence)for this to be used and you need to checkAnalyzedTokenReadings.isImmunized()- Overrides:
getAntiPatternsin classRule
-
isNonPredicativeAdjective
-
isParticiple
-
isRelevantPronoun
-
couldBeRelativeOrDependentClause
-
checkDetNounAgreement
@Nullable private RuleMatch checkDetNounAgreement(AnalyzedTokenReadings maybePreposition, AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedSentence sentence, int tokenPos, Map<Integer, AgreementRule.ReplacementType> replMap, String skippedStr) -
getCompoundError
@Nullable private RuleMatch getCompoundError(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, int tokenPos, AnalyzedSentence sentence) -
getCompoundError
@Nullable private RuleMatch getCompoundError(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, int tokenPos, AnalyzedSentence sentence) -
getCompoundError
@Nullable private RuleMatch getCompoundError(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedTokenReadings token4, int tokenPos, AnalyzedSentence sentence, String skippedStr) -
getRuleMatch
@Nullable private RuleMatch getRuleMatch(AnalyzedTokenReadings token, AnalyzedTokenReadings token2, AnalyzedSentence sentence, String testPhrase, String hyphenTestPhrase) -
initLt
private void initLt() -
isException
-
getCategoriesCausingError
-
checkDetAdjNounAgreement
private RuleMatch checkDetAdjNounAgreement(AnalyzedTokenReadings maybePreposition, AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedSentence sentence, int tokenPos, Map<Integer, AgreementRule.ReplacementType> replMap, String skippedStr) -
checkDetAdjAdjNounAgreement
private RuleMatch checkDetAdjAdjNounAgreement(AnalyzedTokenReadings maybePreposition, AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedTokenReadings token4, AnalyzedSentence sentence, int tokenPos, Map<Integer, AgreementRule.ReplacementType> replMap, String skippedStr) -
agreementWithCategoryRelaxation
private boolean agreementWithCategoryRelaxation(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AgreementRule.GrammarCategory categoryToRelax) -
retainCommonCategories
@NotNull private Set<String> retainCommonCategories(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3) -
retainCommonCategories
@NotNull private Set<String> retainCommonCategories(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2, AnalyzedTokenReadings token3, AnalyzedTokenReadings token4) -
getAgreementCategories
-