Package org.languagetool.rules
Class WrongWordInContextRule
java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.WrongWordInContextRule
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 ClassesModifier and TypeClassDescription(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.common.cache.LoadingCache
<String, List<WrongWordInContextRule.ContextWords>> private final List
<WrongWordInContextRule.ContextWords> private boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
A short description of the error this rule can detect, usually in the language of the text that is checked.protected abstract String
getId()
A string used to identify the rule in e.g.protected abstract String
private String
getMessage
(String wrongWord, String suggestion, String explanationSuggestion, String explanationWrongWord) protected abstract String
protected abstract String
private static List
<WrongWordInContextRule.ContextWords> loadContextWords
(String path) Load words, contexts, and explanations.match
(AnalyzedSentence sentence) Check whether the given sentence matches this error rule, i.e.void
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 Details
-
cache
private static final com.google.common.cache.LoadingCache<String,List<WrongWordInContextRule.ContextWords>> cache -
contextWordsSet
-
matchLemmas
private boolean matchLemmas
-
-
Constructor Details
-
WrongWordInContextRule
-
-
Method Details
-
getFilename
-
getCategoryString
-
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
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
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
- Returns:
- a string like "Possible confusion of words: Did you mean <suggestion>$SUGGESTION</suggestion> instead of '$WRONGWORD'?"
-
getShortMessageString
- Returns:
- a string like "Possible confusion of words"
-
getLongMessageString
- Returns:
- a string like "Possible confusion of words: Did you mean <suggestion>$SUGGESTION</suggestion> (= $EXPLANATION_SUGGESTION) instead of '$WRONGWORD' (= $EXPLANATION_WRONGWORD)?"
-
getMessage
-
loadContextWords
Load words, contexts, and explanations.
-