Package org.languagetool.rules
Class WrongWordInContextRule
- java.lang.Object
-
- org.languagetool.rules.Rule
-
- org.languagetool.rules.WrongWordInContextRule
-
public abstract class WrongWordInContextRule extends Rule
Check if there is a confusion of two words (which might have a similar spelling) depending on the context. This rule loads the words and their respective context from an external file with the following format (tab-separated):word1 word2 match1 match2 context1 context2 explanation1 explanation2
- word1 and word2 are regular expressions of the words that can easily be confused
- match1 is the substring of word1 that will be replaced with match2 when word1 occurs in a context where it is probably wrong (and vice versa)
- context1 is the context in which word1 typically occurs (but which is wrong for word2), given as a regular expression
- context2 is the context in which word2 typically occurs (but which is wrong for word1), given as a regular expression
- explanation1 is a short description of word1 (optional)
- explanation2 is a short description of word2 (optional)
- Author:
- Markus Brenneis
-
-
Constructor Summary
Constructors Constructor Description WrongWordInContextRule(ResourceBundle messages)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
getCategoryString()
String
getDescription()
A short description of the error this rule can detect, usually in the language of the text that is checked.protected abstract String
getFilename()
String
getId()
A string used to identify the rule in e.g.protected abstract String
getLongMessageString()
protected abstract String
getMessageString()
protected abstract String
getShortMessageString()
RuleMatch[]
match(AnalyzedSentence sentence)
Check whether the given sentence matches this error rule, i.e.void
setMatchLemmmas()
-
Methods inherited from class org.languagetool.rules.Rule
addExamplePair, estimateContextForSureMatch, getAntiPatterns, 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
-
-
-
-
Constructor Detail
-
WrongWordInContextRule
public WrongWordInContextRule(ResourceBundle messages)
-
-
Method Detail
-
getFilename
protected abstract String getFilename()
-
getCategoryString
protected String getCategoryString()
-
getId
public String 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.
-
getDescription
public String 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
-
setMatchLemmmas
public void setMatchLemmmas()
-
match
public RuleMatch[] match(AnalyzedSentence sentence)
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).
-
getMessageString
protected abstract String getMessageString()
- Returns:
- a string like "Possible confusion of words: Did you mean <suggestion>$SUGGESTION</suggestion> instead of '$WRONGWORD'?"
-
getShortMessageString
protected abstract String getShortMessageString()
- Returns:
- a string like "Possible confusion of words"
-
getLongMessageString
protected abstract String getLongMessageString()
- Returns:
- a string like "Possible confusion of words: Did you mean <suggestion>$SUGGESTION</suggestion> (= $EXPLANATION_SUGGESTION) instead of '$WRONGWORD' (= $EXPLANATION_WRONGWORD)?"
-
-