public abstract class Rule extends Object
match(AnalyzedSentence)
method.
Rules are created whenever a JLanguageTool or
a MultiThreadedJLanguageTool object is created.
As these objects are not thread-safe, this can happen often. Rules should thus
make sure that their initialization works fast. For example, if a rule needs
to load data from disk, it should store it in a static variable to make sure
the loading happens only once.
| Modifier and Type | Field and Description |
|---|---|
protected ResourceBundle |
messages |
| Constructor and Description |
|---|
Rule() |
Rule(ResourceBundle messages)
Called by rules that require a translation of their messages.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addExamplePair(IncorrectExample incorrectSentence,
String correctSentence)
Convenience method to add a pair of sentences: an incorrect sentence and the same sentence
with the error corrected.
|
Category |
getCategory() |
List<String> |
getCorrectExamples()
Get example sentences that are correct and thus will not match this rule.
|
abstract String |
getDescription()
A short description of the error this rule can detect, usually in the language of the text
that is checked.
|
abstract String |
getId()
A string used to identify the rule in e.g. configuration files.
|
List<IncorrectExample> |
getIncorrectExamples()
Get example sentences that are incorrect and thus will match this rule.
|
ITSIssueType |
getLocQualityIssueType()
Returns the Localization Quality Issue Type, as defined
at http://www.w3.org/International/multilingualweb/lt/drafts/its20/its20.html#lqissue-typevalues.
|
URL |
getUrl()
An optional URL describing the rule match in more detail.
|
boolean |
isDefaultOff()
Checks whether the rule has been turned off by default by the rule author.
|
boolean |
isDictionaryBasedSpellingRule()
Whether this is a spelling rule that uses a dictionary.
|
abstract RuleMatch[] |
match(AnalyzedSentence sentence)
Check whether the given sentence matches this error rule, i.e. whether it
contains the error detected by this rule.
|
abstract void |
reset()
If a rule keeps its state over more than the check of one sentence, this
must be implemented so the internal state is reset.
|
void |
setCategory(Category category) |
void |
setCorrectExamples(List<String> correctExamples)
Set the examples that are correct and thus do not trigger the rule.
|
void |
setDefaultOff()
Turns the rule off by default.
|
void |
setDefaultOn()
Turns the rule on by default.
|
void |
setIncorrectExamples(List<IncorrectExample> incorrectExamples)
Set the examples that are incorrect and thus do trigger the rule.
|
void |
setLocQualityIssueType(ITSIssueType locQualityIssueType)
Set the Localization Quality Issue Type.
|
void |
setUrl(URL url) |
boolean |
supportsLanguage(Language language)
Whether this rule can be used for text in the given language.
|
protected RuleMatch[] |
toRuleMatchArray(List<RuleMatch> ruleMatches) |
boolean |
useInOffice()
Whether this rule should be forced to be used in LO/OO extension.
|
protected final ResourceBundle messages
public Rule()
public Rule(ResourceBundle messages)
public abstract String getId()
A-Z
and the underscore.public abstract String getDescription()
public abstract RuleMatch[] match(AnalyzedSentence sentence) throws IOException
sentence - a pre-analyzed sentenceRuleMatch objectsIOExceptionpublic abstract void reset()
public boolean supportsLanguage(Language language)
PatternRules
(before, it used to always return false for those).public boolean isDictionaryBasedSpellingRule()
true here are basically rules that work like
a simple hunspell-like spellchecker: they check words without considering
the words' context.public boolean useInOffice()
true will be enabled always in LO/OO extension
regardless of other options like isDictionaryBasedSpellingRule().public final void setCorrectExamples(List<String> correctExamples)
public final List<String> getCorrectExamples()
public final void setIncorrectExamples(List<IncorrectExample> incorrectExamples)
public final List<IncorrectExample> getIncorrectExamples()
public final Category getCategory()
public final void setCategory(Category category)
public final boolean isDefaultOff()
public final void setDefaultOff()
public final void setDefaultOn()
@Nullable public URL getUrl()
null for rules that have no URL.public ITSIssueType getLocQualityIssueType()
Note that not all languages nor all rules actually map yet to a type yet. In those cases, uncategorized is returned.
public void setLocQualityIssueType(ITSIssueType locQualityIssueType)
getLocQualityIssueType()protected void addExamplePair(IncorrectExample incorrectSentence, String correctSentence)