de.danielnaber.languagetool.rules
Class Rule

Object
  extended by Rule
Direct Known Subclasses:
AbstractPunctuationCheckRule, CommaWhitespaceRule, DoublePunctuationRule, EnglishRule, FrenchRule, GermanRule, PatternRule, PolishRule, RussianRule, SimpleReplaceRule, SwedishRule, UnpairedQuotesBracketsRule, UppercaseSentenceStartRule, WhitespaceRule, WordRepeatRule

public abstract class Rule
extends Object

Abstract rule class. A Rule drescribes a language error and can test whether a given pre-analyzed text contains that error using the match(de.danielnaber.languagetool.AnalyzedSentence) method.

Author:
Daniel Naber

Constructor Summary
Rule()
          Called by language-dependant rules.
Rule(ResourceBundle messages)
          Called by language-independant rules.
 
Method Summary
 void addRuleMatch(RuleMatch r)
          Method to add matches.
 void clearMatches()
           
 Category getCategory()
           
 List<String> getCorrectExamples()
          Get example sentences that are correct and thus will not match this rule.
abstract  String getDescription()
           
abstract  String getId()
           
 List<IncorrectExample> getIncorrectExamples()
          Get example sentences that are incorrect and thus will match this rule.
 List<RuleMatch> getMatches()
           
 int getMatchesIndex()
           
 boolean isDefaultOff()
          Checks whether the rule has been turned off by default by the rule author.
 boolean isInMatches(int i)
           
 boolean isInRemoved(RuleMatch r)
           
 boolean isParagraphBackTrack()
           
abstract  RuleMatch[] match(AnalyzedSentence text)
          Check whether the given text matche this error rule, i.e. whether the text contains this error.
abstract  void reset()
          If a rule keeps it state over more than the check of one sentence, this must be implemented so the internal state it reset.
 void setAsDeleted(int i)
          Deletes (or disables) previously matched rule.
 void setCategory(Category category)
           
 void setCorrectExamples(List<String> correctExamples)
          TODO: Return the number of false positives to be expected.
 void setDefaultOff()
          Turns the rule by default off.
 void setIncorrectExamples(List<IncorrectExample> incorrectExamples)
           
 void setParagraphBackTrack(boolean backTrack)
           
 boolean supportsLanguage(Language language)
          Whether this rule can be used for text in the given language.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rule

public Rule()
Called by language-dependant rules.


Rule

public Rule(ResourceBundle messages)
Called by language-independant rules.

Method Detail

getId

public abstract String getId()

getDescription

public abstract String getDescription()

match

public abstract RuleMatch[] match(AnalyzedSentence text)
                           throws IOException
Check whether the given text matche this error rule, i.e. whether the text contains this error.

Parameters:
text - a pre-analyzed sentence
Returns:
an array of RuleMatch object for each match.
Throws:
IOException

reset

public abstract void reset()
If a rule keeps it state over more than the check of one sentence, this must be implemented so the internal state it reset. It will be called before a new text is going to be checked.


supportsLanguage

public boolean supportsLanguage(Language language)
Whether this rule can be used for text in the given language.


setCorrectExamples

public void setCorrectExamples(List<String> correctExamples)
TODO: Return the number of false positives to be expected. public int getFalsePositives() { return -1; }


getCorrectExamples

public List<String> getCorrectExamples()
Get example sentences that are correct and thus will not match this rule.


setIncorrectExamples

public void setIncorrectExamples(List<IncorrectExample> incorrectExamples)

getIncorrectExamples

public List<IncorrectExample> getIncorrectExamples()
Get example sentences that are incorrect and thus will match this rule.


getCategory

public Category getCategory()

setCategory

public void setCategory(Category category)

isParagraphBackTrack

public boolean isParagraphBackTrack()

setParagraphBackTrack

public void setParagraphBackTrack(boolean backTrack)

addRuleMatch

public final void addRuleMatch(RuleMatch r)
Method to add matches.

Parameters:
r - RuleMatch - matched rule added by check()

setAsDeleted

public final void setAsDeleted(int i)
Deletes (or disables) previously matched rule.

Parameters:
i - Index of the rule that should be deleted.

isInRemoved

public final boolean isInRemoved(RuleMatch r)

isInMatches

public final boolean isInMatches(int i)

clearMatches

public final void clearMatches()

getMatchesIndex

public final int getMatchesIndex()

getMatches

public final List<RuleMatch> getMatches()

isDefaultOff

public final boolean isDefaultOff()
Checks whether the rule has been turned off by default by the rule author.

Returns:
True if the rule is turned off by default.

setDefaultOff

public final void setDefaultOff()
Turns the rule by default off.



Copyright © 2005-2007 Daniel Naber