|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectJLanguageTool
public final class JLanguageTool
The main class used for checking text against different rules:
loadPatternRules(String)
Rule classes added with
addRule(Rule)
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.
| Nested Class Summary | |
|---|---|
static class |
JLanguageTool.ParagraphHandling
Constants for correct paragraph-rule handling. |
| Field Summary | |
|---|---|
static String |
BUILD_DATE
|
static String |
FALSE_FRIEND_FILE
|
static String |
PARAGRAPH_END_TAGNAME
|
static String |
PATTERN_FILE
|
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(String). |
RuleMatch |
adjustRuleMatchPos(RuleMatch rm,
int sentLen,
int columnCount,
int lineCount,
String sentence)
Change RuleMatch positions so they are relative to the complete text, not just to the sentence: |
List<RuleMatch> |
check(String text)
The main check method. |
List<RuleMatch> |
check(String text,
boolean tokenizeText,
JLanguageTool.ParagraphHandling paraMode)
The main check method. |
List<RuleMatch> |
checkAnalyzedSentence(JLanguageTool.ParagraphHandling paraMode,
List<Rule> allRules,
int tokenCount,
int lineCount,
int columnCount,
String sentence,
AnalyzedSentence analyzedText)
|
void |
disableCategory(String categoryName)
Disable a given category so check(String) won't use it. |
void |
disableRule(String ruleId)
Disable a given rule so check(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(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(Rule). |
AnalyzedSentence |
getAnalyzedSentence(String sentence)
Tokenizes the given sentence into words and analyzes it,
and then disambiguates POS tags. |
static ResourceDataBroker |
getDataBroker()
The grammar checker needs resources from following directories: /resource
/rules
This method is thread-safe. |
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. |
AnalyzedSentence |
getRawAnalyzedSentence(String sentence)
Tokenizes the given sentence into words and analyzes it. |
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. |
List<String> |
sentenceTokenize(String text)
Returns tokenized sentences. |
static void |
setDataBroker(ResourceDataBroker broker)
The grammar checker needs resources from following directories: /resource
/rules
This method is thread-safe. |
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 |
|---|
public static final String VERSION
public static final String BUILD_DATE
public static final String PATTERN_FILE
public static final String FALSE_FRIEND_FILE
public static final String SENTENCE_START_TAGNAME
public static final String SENTENCE_END_TAGNAME
public static final String PARAGRAPH_END_TAGNAME
| Constructor Detail |
|---|
public JLanguageTool(Language language)
throws IOException
IOException
public JLanguageTool(Language language,
Language motherTongue)
throws IOException
language - the language to be used.motherTongue - the user's mother tongue or null. The mother tongue
may also be used as a source language for checking bilingual texts.
IOException| Method Detail |
|---|
public static ResourceDataBroker getDataBroker()
/resource/rules
DefaultResourceDataBroker will
be instantiated and returned.public static void setDataBroker(ResourceDataBroker broker)
/resource/rules
broker - The new resource broker to be used.public void setListUnknownWords(boolean listUnknownWords)
true (default: false), you can get the list of unknown words
using getUnknownWords().
public static ResourceBundle getMessageBundle()
public void setOutput(PrintStream printStream)
null to disable verbose output.
public List<PatternRule> loadPatternRules(String filename)
throws IOException
addRule(Rule) to add these
rules to the checking process.
PatternRule objects
IOException
public List<PatternRule> loadFalseFriendRules(String filename)
throws ParserConfigurationException,
SAXException,
IOException
addRule(Rule) to add these rules to the
checking process.
PatternRule objects
ParserConfigurationException
SAXException
IOException
public void activateDefaultPatternRules()
throws IOException
rules/<language>/grammar.xml.
ParserConfigurationException
SAXException
IOException
public void activateDefaultFalseFriendRules()
throws ParserConfigurationException,
SAXException,
IOException
rules/false-friends.xml.
ParserConfigurationException
SAXException
IOExceptionpublic void addRule(Rule rule)
check(String).
public void disableRule(String ruleId)
check(String) won't use it.
ruleId - the id of the rule to disablepublic void disableCategory(String categoryName)
check(String) won't use it.
categoryName - the id of the category to disablepublic Language getLanguage()
public Set<String> getDisabledRules()
public void enableDefaultOffRule(String ruleId)
ruleId - the id of the turned off rule to enable.public Set<String> getDisabledCategories()
public void enableRule(String ruleId)
check(String) will use it.
ruleId - the id of the rule to enablepublic List<String> sentenceTokenize(String text)
public List<RuleMatch> check(String text)
throws IOException
text - the text to check
RuleMatch objects
IOException
public List<RuleMatch> check(String text,
boolean tokenizeText,
JLanguageTool.ParagraphHandling paraMode)
throws IOException
text - The text to check. Call this method with the complete text to check. If you call it
with smaller chunks like paragraphs or sentence, those rules that work across
paragraphs/sentences won't work (their status gets reset whenever this).tokenizeText - If true, then the text is tokenized into sentences.
Otherwise, it is assumed it's already tokenized.paraMode - Uses paragraph-level rules only if true.
RuleMatch objects
IOException
public List<RuleMatch> checkAnalyzedSentence(JLanguageTool.ParagraphHandling paraMode,
List<Rule> allRules,
int tokenCount,
int lineCount,
int columnCount,
String sentence,
AnalyzedSentence analyzedText)
throws IOException
IOException
public RuleMatch adjustRuleMatchPos(RuleMatch rm,
int sentLen,
int columnCount,
int lineCount,
String sentence)
rm - RuleMatchsentLen - Count of characterscolumnCount - Current column numberlineCount - Current line numbersentence - The text being checked
public List<String> getUnknownWords()
IllegalStateException - if listUnknownWords is set to false
public AnalyzedSentence getAnalyzedSentence(String sentence)
throws IOException
sentence into words and analyzes it,
and then disambiguates POS tags.
IOException
public AnalyzedSentence getRawAnalyzedSentence(String sentence)
throws IOException
sentence into words and analyzes it.
sentence - Sentence to be analyzed
IOExceptionpublic List<Rule> getAllRules()
addRule(Rule).
Rule objectspublic int getSentenceCount()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||