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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
WrongWordInContextRule.ContextWords
-
Field Summary
Fields Modifier and Type Field Description private static com.google.common.cache.LoadingCache<java.lang.String,java.util.List<WrongWordInContextRule.ContextWords>>
cache
private java.util.List<WrongWordInContextRule.ContextWords>
contextWordsSet
private boolean
matchLemmas
-
Constructor Summary
Constructors Constructor Description WrongWordInContextRule(java.util.ResourceBundle messages)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
getCategoryString()
java.lang.String
getDescription()
A short description of the error this rule can detect, usually in the language of the text that is checked.protected abstract java.lang.String
getFilename()
java.lang.String
getId()
A string used to identify the rule in e.g.protected abstract java.lang.String
getLongMessageString()
private java.lang.String
getMessage(java.lang.String wrongWord, java.lang.String suggestion, java.lang.String explanationSuggestion, java.lang.String explanationWrongWord)
protected abstract java.lang.String
getMessageString()
protected abstract java.lang.String
getShortMessageString()
private static java.util.List<WrongWordInContextRule.ContextWords>
loadContextWords(java.lang.String path)
Load words, contexts, and explanations.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
-
-
-
-
Field Detail
-
cache
private static final com.google.common.cache.LoadingCache<java.lang.String,java.util.List<WrongWordInContextRule.ContextWords>> cache
-
contextWordsSet
private final java.util.List<WrongWordInContextRule.ContextWords> contextWordsSet
-
matchLemmas
private boolean matchLemmas
-
-
Method Detail
-
getFilename
protected abstract java.lang.String getFilename()
-
getCategoryString
protected java.lang.String getCategoryString()
-
getId
public java.lang.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 java.lang.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 java.lang.String getMessageString()
- Returns:
- a string like "Possible confusion of words: Did you mean <suggestion>$SUGGESTION</suggestion> instead of '$WRONGWORD'?"
-
getShortMessageString
protected abstract java.lang.String getShortMessageString()
- Returns:
- a string like "Possible confusion of words"
-
getLongMessageString
protected abstract java.lang.String getLongMessageString()
- Returns:
- a string like "Possible confusion of words: Did you mean <suggestion>$SUGGESTION</suggestion> (= $EXPLANATION_SUGGESTION) instead of '$WRONGWORD' (= $EXPLANATION_WRONGWORD)?"
-
getMessage
private java.lang.String getMessage(java.lang.String wrongWord, java.lang.String suggestion, java.lang.String explanationSuggestion, java.lang.String explanationWrongWord)
-
loadContextWords
private static java.util.List<WrongWordInContextRule.ContextWords> loadContextWords(java.lang.String path)
Load words, contexts, and explanations.
-
-