de.danielnaber.languagetool
Class JLanguageTool

Object
  extended by JLanguageTool

public final class JLanguageTool
extends Object

The main class used for checking text against different rules:

Note that the constructors create a language checker that uses the built-in rules only. Other rules (e.g. from XML) need to be added explicitly.

Author:
Daniel Naber

Field Summary
static String FALSE_FRIEND_FILE
           
static String PARAGRAPH_END_TAGNAME
           
static String PATTERN_FILE
           
static String RULES_DIR
           
static String SENTENCE_END_TAGNAME
           
static String SENTENCE_START_TAGNAME
           
static String VERSION
           
 
Constructor Summary
JLanguageTool(Language language)
          Create a JLanguageTool and setup the built-in rules appropriate for the given language, ignoring false friend hints.
JLanguageTool(Language language, Language motherTongue)
          Create a JLanguageTool and setup the built-in rules appropriate for the given language.
 
Method Summary
 void activateDefaultFalseFriendRules()
          Loads and activates the false friend rules from rules/false-friends.xml.
 void activateDefaultPatternRules()
          Loads and activates the pattern rules from rules/<language>/grammar.xml.
 void addRule(Rule rule)
          Add a rule to be used by the next call to check(java.lang.String).
 List<RuleMatch> check(String text)
          The main check method.
 void disableCategory(String categoryName)
          Disable a given category so check(java.lang.String) won't use it.
 void disableRule(String ruleId)
          Disable a given rule so check(java.lang.String) won't use it.
 void enableDefaultOffRule(String ruleId)
          Enable a rule that was switched off by default.
 void enableRule(String ruleId)
          Re-enable a given rule so check(java.lang.String) will use it.
 List<Rule> getAllRules()
          Get all rules for the current language that are built-in or that have been added using addRule(de.danielnaber.languagetool.rules.Rule).
 AnalyzedSentence getAnalyzedSentence(String sentence)
          Tokenizes the given sentence into words and analyzes it.
 Set<String> getDisabledCategories()
          Get category ids of the rules that have been explicitly disabled.
 Set<String> getDisabledRules()
          Get rule ids of the rules that have been explicitly disabled.
 Language getLanguage()
          Get the language that was used to configure this instance.
static ResourceBundle getMessageBundle()
          Gets the ResourceBundle for the default language of the user's system.
 int getSentenceCount()
          Number of sentences the latest call to check() has checked.
 List<String> getUnknownWords()
          Get the list of unknown words in the last run of the check() method.
 List<PatternRule> loadFalseFriendRules(String filename)
          Load false friend rules from an XML file.
 List<PatternRule> loadPatternRules(String filename)
          Load pattern rules from an XML file.
 void setListUnknownWords(boolean listUnknownWords)
          Whether the check() method stores unknown words.
 void setOutput(PrintStream printStream)
          Set a PrintStream that will receive verbose output.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
See Also:
Constant Field Values

RULES_DIR

public static final String RULES_DIR
See Also:
Constant Field Values

PATTERN_FILE

public static final String PATTERN_FILE
See Also:
Constant Field Values

FALSE_FRIEND_FILE

public static final String FALSE_FRIEND_FILE
See Also:
Constant Field Values

SENTENCE_START_TAGNAME

public static final String SENTENCE_START_TAGNAME
See Also:
Constant Field Values

SENTENCE_END_TAGNAME

public static final String SENTENCE_END_TAGNAME
See Also:
Constant Field Values

PARAGRAPH_END_TAGNAME

public static final String PARAGRAPH_END_TAGNAME
See Also:
Constant Field Values
Constructor Detail

JLanguageTool

public JLanguageTool(Language language)
              throws IOException
Create a JLanguageTool and setup the built-in rules appropriate for the given language, ignoring false friend hints.

Throws:
IOException

JLanguageTool

public JLanguageTool(Language language,
                     Language motherTongue)
              throws IOException
Create a JLanguageTool and setup the built-in rules appropriate for the given language.

Parameters:
language - the language to be used.
motherTongue - the user's mother tongue or null
Throws:
IOException
Method Detail

setListUnknownWords

public void setListUnknownWords(boolean listUnknownWords)
Whether the check() method stores unknown words. If set to true (default: false), you can get the list of unknown words using getUnknownWords().


getMessageBundle

public static ResourceBundle getMessageBundle()
Gets the ResourceBundle for the default language of the user's system.


setOutput

public void setOutput(PrintStream printStream)
Set a PrintStream that will receive verbose output. Set to null to disable verbose output.


loadPatternRules

public List<PatternRule> loadPatternRules(String filename)
                                   throws IOException
Load pattern rules from an XML file. Use addRule(de.danielnaber.languagetool.rules.Rule) to add these rules to the checking process.

Returns:
a List of PatternRule objects
Throws:
ParserConfigurationException
SAXException
IOException

loadFalseFriendRules

public List<PatternRule> loadFalseFriendRules(String filename)
                                       throws ParserConfigurationException,
                                              SAXException,
                                              IOException
Load false friend rules from an XML file. Only those pairs will be loaded that match the current text language and the mother tongue specified in the JLanguageTool constructor. Use addRule(de.danielnaber.languagetool.rules.Rule) to add these rules to the checking process.

Returns:
a List of PatternRule objects
Throws:
ParserConfigurationException
SAXException
IOException

activateDefaultPatternRules

public void activateDefaultPatternRules()
                                 throws IOException
Loads and activates the pattern rules from rules/<language>/grammar.xml.

Throws:
ParserConfigurationException
SAXException
IOException

activateDefaultFalseFriendRules

public void activateDefaultFalseFriendRules()
                                     throws ParserConfigurationException,
                                            SAXException,
                                            IOException
Loads and activates the false friend rules from rules/false-friends.xml.

Throws:
ParserConfigurationException
SAXException
IOException

addRule

public void addRule(Rule rule)
Add a rule to be used by the next call to check(java.lang.String).


disableRule

public void disableRule(String ruleId)
Disable a given rule so check(java.lang.String) won't use it.

Parameters:
ruleId - the id of the rule to disable

disableCategory

public void disableCategory(String categoryName)
Disable a given category so check(java.lang.String) won't use it.

Parameters:
categoryName - the id of the category to disable

getLanguage

public Language getLanguage()
Get the language that was used to configure this instance.


getDisabledRules

public Set<String> getDisabledRules()
Get rule ids of the rules that have been explicitly disabled.


enableDefaultOffRule

public void enableDefaultOffRule(String ruleId)
Enable a rule that was switched off by default.

Parameters:
ruleId - the id of the turned off rule to enable.

getDisabledCategories

public Set<String> getDisabledCategories()
Get category ids of the rules that have been explicitly disabled.


enableRule

public void enableRule(String ruleId)
Re-enable a given rule so check(java.lang.String) will use it.

Parameters:
ruleId - the id of the rule to enable

check

public List<RuleMatch> check(String text)
                      throws IOException
The main check method. Tokenizes the text into sentences and matches these sentences against all currently active rules.

Parameters:
text - the text to check
Returns:
a List of RuleMatch objects
Throws:
IOException

getUnknownWords

public List<String> getUnknownWords()
Get the list of unknown words in the last run of the check() method.

Throws:
IllegalStateException - listUnknownWords is set to false

getAnalyzedSentence

public AnalyzedSentence getAnalyzedSentence(String sentence)
                                     throws IOException
Tokenizes the given sentence into words and analyzes it.

Throws:
IOException

getAllRules

public List<Rule> getAllRules()
Get all rules for the current language that are built-in or that have been added using addRule(de.danielnaber.languagetool.rules.Rule).

Returns:
a List of Rule objects

getSentenceCount

public int getSentenceCount()
Number of sentences the latest call to check() has checked.



Copyright © 2005-2007 Daniel Naber