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 String
protected int
protected RuleFilter
protected String
private final boolean
private final boolean
private final String
protected final Language
protected String
protected final List<PatternToken>
protected final Pattern
protected final int
protected final boolean
protected String
protected int
protected String
protected String
protected 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) private
AbstractPatternRule
(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 void
Add formatted suggestion elements.final void
Add 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 String
The rule id and its sub id, if any.getId()
A string used to identify the rule in e.g.final Language
final String
Get the message shown to the user if this rule matches.The rule id and its sub id, if any.(package private) String
@Nullable String
final int
final String
getSubId()
final @NotNull String
private boolean
boolean
boolean
boolean
boolean
match
(AnalyzedSentence sentence) Check whether the given sentence matches this error rule, i.e.void
setAntiPatterns
(List<DisambiguationPatternRule> antiPatterns) Set up the list of antipatterns used to immunize tokens, i.e., make them non-matchable by the current rule.final void
setEndPositionCorrection
(int endPositionCorrection) void
setFilter
(RuleFilter filter) void
setFilterArguments
(String filterArgs) final void
setMessage
(String message) Set the message shown to the user if this rule matches.(package private) void
setSourceFile
(String sourceFile) final void
setStartPositionCorrection
(int startPositionCorrection) final void
boolean
supportsLanguage
(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:Rule
Whether this rule can be used for text in the given language. Since LanguageTool 2.6, this also worksPatternRule
s (before, it used to always returnfalse
for those).- Overrides:
supportsLanguage
in classRule
-
initUnifier
private boolean initUnifier() -
toString
-
getDescription
Description copied from class:Rule
A short description of the error this rule can detect, usually in the language of the text that is checked.- Specified by:
getDescription
in classRule
-
getSourceFile
-
setSourceFile
-
getId
Description copied from class:Rule
A 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-Z
and the underscore. -
match
Description copied from class:Rule
Check 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:
match
in classRule
- Parameters:
sentence
- a pre-analyzed sentence- Returns:
- an array of
RuleMatch
objects - 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:Rule
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()
- Overrides:
getAntiPatterns
in classRule
- Since:
- 3.1
-
getShortMessage
String getShortMessage()- Returns:
- String of short message as specified in <short>...</short>
- Since:
- 4.4
-