Package org.languagetool.rules.patterns
Class AbstractPatternRule
java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.patterns.AbstractPatternRule
- Direct Known Subclasses:
DisambiguationPatternRule,PatternRule,RegexPatternRule
An Abstract Pattern Rule that describes a pattern of words or part-of-speech tags
used for PatternRule and DisambiguationPatternRule.
Introduced to minimize code duplication between those classes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<DisambiguationPatternRule> private final Stringprotected intprotected RuleFilterprotected Stringprivate final booleanprivate final booleanprivate final Stringprotected final Languageprotected Stringprotected final List<PatternToken> protected final Patternprotected final intprotected final booleanprotected Stringprotected intprotected Stringprotected Stringprotected final boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionAbstractPatternRule(String id, String description, Language language, List<PatternToken> patternTokens, boolean getUnified) AbstractPatternRule(String id, String description, Language language, List<PatternToken> patternTokens, boolean getUnified, String message) privateAbstractPatternRule(String id, String description, Language language, List<PatternToken> patternTokens, Pattern regex, int regexMark, boolean getUnified) AbstractPatternRule(String id, String description, Language language, Pattern regex, int regexMark) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd formatted suggestion elements.final voidAdd formatted suggestion elements outside message.final List<DisambiguationPatternRule> 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()A short description of the error this rule can detect, usually in the language of the text that is checked.final int@Nullable RuleFilter@Nullable StringThe rule id and its sub id, if any.getId()A string used to identify the rule in e.g.final Languagefinal StringGet the message shown to the user if this rule matches.The rule id and its sub id, if any.(package private) String@Nullable Stringfinal intfinal StringgetSubId()final @NotNull Stringprivate booleanbooleanbooleanbooleanbooleanmatch(AnalyzedSentence sentence) Check whether the given sentence matches this error rule, i.e.voidsetAntiPatterns(List<DisambiguationPatternRule> antiPatterns) Set up the list of antipatterns used to immunize tokens, i.e., make them non-matchable by the current rule.final voidsetEndPositionCorrection(int endPositionCorrection) voidsetFilter(RuleFilter filter) voidsetFilterArguments(String filterArgs) final voidsetMessage(String message) Set the message shown to the user if this rule matches.(package private) voidsetSourceFile(String sourceFile) final voidsetStartPositionCorrection(int startPositionCorrection) final voidbooleansupportsLanguage(Language language) Whether this rule can be used for text in the given language.toString()Methods inherited from class org.languagetool.rules.Rule
addExamplePair, estimateContextForSureMatch, 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, toRuleMatchArray, useInOffice
-
Field Details
-
language
-
patternTokens
-
regex
-
regexMark
protected final int regexMark -
testUnification
protected final boolean testUnification -
sentStart
protected final boolean sentStart -
suggestionMatches
-
suggestionMatchesOutMsg
-
antiPatterns
-
subId
-
startPositionCorrection
protected int startPositionCorrection -
endPositionCorrection
protected int endPositionCorrection -
suggestionsOutMsg
-
filter
-
filterArgs
-
message
-
sourceFile
-
id
-
description
-
getUnified
private final boolean getUnified -
groupsOrUnification
private final boolean groupsOrUnification
-
-
Constructor Details
-
AbstractPatternRule
public AbstractPatternRule(String id, String description, Language language, Pattern regex, int regexMark) - Since:
- 3.2
-
AbstractPatternRule
-
AbstractPatternRule
public AbstractPatternRule(String id, String description, Language language, List<PatternToken> patternTokens, boolean getUnified) -
AbstractPatternRule
-
-
Method Details
-
supportsLanguage
Description copied from class:RuleWhether this rule can be used for text in the given language. Since LanguageTool 2.6, this also worksPatternRules (before, it used to always returnfalsefor those).- Overrides:
supportsLanguagein classRule
-
initUnifier
private boolean initUnifier() -
toString
-
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
-
getSourceFile
-
setSourceFile
-
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. -
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 than 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).- Specified by:
matchin classRule- Parameters:
sentence- a pre-analyzed sentence- Returns:
- an array of
RuleMatchobjects - Throws:
IOException
-
getLanguage
- Since:
- 2.3
-
setStartPositionCorrection
public final void setStartPositionCorrection(int startPositionCorrection) -
getStartPositionCorrection
public final int getStartPositionCorrection() -
setEndPositionCorrection
public final void setEndPositionCorrection(int endPositionCorrection) -
getEndPositionCorrection
public final int getEndPositionCorrection() -
getFullId
The rule id and its sub id, if any. The format is likeRULE_ID[SUB_ID], e.g.WANT_TO[2].- Since:
- 3.2
- See Also:
-
getPatternRuleId
The rule id and its sub id, if any.- Since:
- 3.2
-
getSubId
-
setSubId
-
isGroupsOrUnification
public boolean isGroupsOrUnification()- Since:
- 2.3
-
isGetUnified
public boolean isGetUnified()- Since:
- 2.3
-
isSentStart
public boolean isSentStart()- Since:
- 2.3
-
isTestUnification
public boolean isTestUnification()- Since:
- 2.3
-
getPatternTokens
- Since:
- 2.3
-
addSuggestionMatch
Add formatted suggestion elements. -
addSuggestionMatchOutMsg
Add formatted suggestion elements outside message. -
getSuggestionMatches
-
getSuggestionMatchesOutMsg
-
getSuggestionsOutMsg
-
getMessage
Get the message shown to the user if this rule matches. -
setMessage
Set the message shown to the user if this rule matches. -
setFilter
- Since:
- 2.7 (public since 3.2)
-
getFilter
- Since:
- 2.7 (public since 3.2)
-
setFilterArguments
- Since:
- 2.7 (public since 3.2)
-
getFilterArguments
- Since:
- 2.7 (public since 3.2)
-
setAntiPatterns
Set up the list of antipatterns used to immunize tokens, i.e., make them non-matchable by the current rule. Useful for multi-word complex exceptions, such as multi-word idiomatic expressions.- Parameters:
antiPatterns- A list of antiPatterns, implemented asDisambiguationPatternRule.- Since:
- 2.5
-
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- Since:
- 3.1
-
getShortMessage
String getShortMessage()- Returns:
- String of short message as specified in <short>...</short>
- Since:
- 4.4
-