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
public abstract class AbstractPatternRule extends Rule
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
Fields Modifier and Type Field Description protected java.util.List<DisambiguationPatternRule>antiPatternsprivate java.lang.Stringdescriptionprotected intendPositionCorrectionprotected RuleFilterfilterprotected java.lang.StringfilterArgsprivate booleangetUnifiedprivate booleangroupsOrUnificationprivate java.lang.Stringidprotected Languagelanguageprotected java.lang.Stringmessageprotected java.util.List<PatternToken>patternTokensprotected java.util.regex.Patternregexprotected intregexMarkprotected booleansentStartprotected java.lang.StringsourceFileprotected intstartPositionCorrectionprotected java.lang.StringsubIdprotected java.util.List<Match>suggestionMatchesprotected java.util.List<Match>suggestionMatchesOutMsgprotected java.lang.StringsuggestionsOutMsgprotected booleantestUnification
-
Constructor Summary
Constructors Modifier Constructor Description AbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.List<PatternToken> patternTokens, boolean getUnified)AbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.List<PatternToken> patternTokens, boolean getUnified, java.lang.String message)privateAbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.List<PatternToken> patternTokens, java.util.regex.Pattern regex, int regexMark, boolean getUnified)AbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.regex.Pattern regex, int regexMark)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSuggestionMatch(Match m)Add formatted suggestion elements.voidaddSuggestionMatchOutMsg(Match m)Add formatted suggestion elements outside message.java.util.List<DisambiguationPatternRule>getAntiPatterns()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()java.lang.StringgetDescription()A short description of the error this rule can detect, usually in the language of the text that is checked.intgetEndPositionCorrection()@Nullable RuleFiltergetFilter()@Nullable java.lang.StringgetFilterArguments()java.lang.StringgetFullId()The rule id and its sub id, if any.java.lang.StringgetId()A string used to identify the rule in e.g.LanguagegetLanguage()java.lang.StringgetMessage()Get the message shown to the user if this rule matches.PatternRuleIdgetPatternRuleId()The rule id and its sub id, if any.java.util.List<PatternToken>getPatternTokens()(package private) java.lang.StringgetShortMessage()@Nullable java.lang.StringgetSourceFile()intgetStartPositionCorrection()java.lang.StringgetSubId()(package private) java.util.List<Match>getSuggestionMatches()(package private) java.util.List<Match>getSuggestionMatchesOutMsg()@NotNull java.lang.StringgetSuggestionsOutMsg()private booleaninitUnifier()booleanisGetUnified()booleanisGroupsOrUnification()booleanisSentStart()booleanisTestUnification()RuleMatch[]match(AnalyzedSentence sentence)Check whether the given sentence matches this error rule, i.e.voidsetAntiPatterns(java.util.List<DisambiguationPatternRule> antiPatterns)Set up the list of antipatterns used to immunize tokens, i.e., make them non-matchable by the current rule.voidsetEndPositionCorrection(int endPositionCorrection)voidsetFilter(RuleFilter filter)voidsetFilterArguments(java.lang.String filterArgs)voidsetMessage(java.lang.String message)Set the message shown to the user if this rule matches.(package private) voidsetSourceFile(java.lang.String sourceFile)voidsetStartPositionCorrection(int startPositionCorrection)voidsetSubId(java.lang.String subId)booleansupportsLanguage(Language language)Whether this rule can be used for text in the given language.java.lang.StringtoString()-
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 Detail
-
language
protected final Language language
-
patternTokens
protected final java.util.List<PatternToken> patternTokens
-
regex
protected final java.util.regex.Pattern regex
-
regexMark
protected final int regexMark
-
testUnification
protected final boolean testUnification
-
sentStart
protected final boolean sentStart
-
suggestionMatches
protected final java.util.List<Match> suggestionMatches
-
suggestionMatchesOutMsg
protected final java.util.List<Match> suggestionMatchesOutMsg
-
antiPatterns
protected final java.util.List<DisambiguationPatternRule> antiPatterns
-
subId
protected java.lang.String subId
-
startPositionCorrection
protected int startPositionCorrection
-
endPositionCorrection
protected int endPositionCorrection
-
suggestionsOutMsg
protected java.lang.String suggestionsOutMsg
-
filter
protected RuleFilter filter
-
filterArgs
protected java.lang.String filterArgs
-
message
protected java.lang.String message
-
sourceFile
protected java.lang.String sourceFile
-
id
private final java.lang.String id
-
description
private final java.lang.String description
-
getUnified
private final boolean getUnified
-
groupsOrUnification
private final boolean groupsOrUnification
-
-
Constructor Detail
-
AbstractPatternRule
public AbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.regex.Pattern regex, int regexMark)- Since:
- 3.2
-
AbstractPatternRule
public AbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.List<PatternToken> patternTokens, boolean getUnified, java.lang.String message)
-
AbstractPatternRule
public AbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.List<PatternToken> patternTokens, boolean getUnified)
-
AbstractPatternRule
private AbstractPatternRule(java.lang.String id, java.lang.String description, Language language, java.util.List<PatternToken> patternTokens, java.util.regex.Pattern regex, int regexMark, boolean getUnified)
-
-
Method Detail
-
supportsLanguage
public boolean supportsLanguage(Language language)
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDescription
public java.lang.String 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
@Nullable public @Nullable java.lang.String getSourceFile()
-
setSourceFile
void setSourceFile(java.lang.String sourceFile)
-
getId
public java.lang.String 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.- Specified by:
getIdin classRule- See Also:
getFullId()
-
match
public RuleMatch[] match(AnalyzedSentence sentence) throws java.io.IOException
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).
-
getLanguage
public final Language 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
public java.lang.String 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:
getId()
-
getPatternRuleId
public PatternRuleId getPatternRuleId()
The rule id and its sub id, if any.- Since:
- 3.2
-
getSubId
public final java.lang.String getSubId()
-
setSubId
public final void setSubId(java.lang.String subId)
-
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
public java.util.List<PatternToken> getPatternTokens()
- Since:
- 2.3
-
addSuggestionMatch
public final void addSuggestionMatch(Match m)
Add formatted suggestion elements.
-
addSuggestionMatchOutMsg
public final void addSuggestionMatchOutMsg(Match m)
Add formatted suggestion elements outside message.
-
getSuggestionMatches
java.util.List<Match> getSuggestionMatches()
-
getSuggestionMatchesOutMsg
java.util.List<Match> getSuggestionMatchesOutMsg()
-
getSuggestionsOutMsg
@NotNull public final @NotNull java.lang.String getSuggestionsOutMsg()
-
getMessage
public final java.lang.String getMessage()
Get the message shown to the user if this rule matches.
-
setMessage
public final void setMessage(java.lang.String message)
Set the message shown to the user if this rule matches.
-
setFilter
public void setFilter(RuleFilter filter)
- Since:
- 2.7 (public since 3.2)
-
getFilter
@Nullable public @Nullable RuleFilter getFilter()
- Since:
- 2.7 (public since 3.2)
-
setFilterArguments
public void setFilterArguments(java.lang.String filterArgs)
- Since:
- 2.7 (public since 3.2)
-
getFilterArguments
@Nullable public @Nullable java.lang.String getFilterArguments()
- Since:
- 2.7 (public since 3.2)
-
setAntiPatterns
public void setAntiPatterns(java.util.List<DisambiguationPatternRule> antiPatterns)
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
public final java.util.List<DisambiguationPatternRule> 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
java.lang.String getShortMessage()
- Returns:
- String of short message as specified in <short>...</short>
- Since:
- 4.4
-
-