public class SpellChecker
extends java.lang.Object
SpellDictionaryHashMap
to persist the added word, the user dictionary will have the possibility to
grow and be available across differents invocations of the spell checker.Modifier and Type | Field and Description |
---|---|
static int |
SPELLCHECK_CANCEL
Flag indicating that the Spell Check completed due to user cancellation
|
static int |
SPELLCHECK_OK
Flag indicating that the Spell Check completed without any errors present
|
Constructor and Description |
---|
SpellChecker()
Constructs the SpellChecker.
|
SpellChecker(SpellDictionary dictionary)
Constructs the SpellChecker.
|
SpellChecker(SpellDictionary dictionary,
int threshold)
Constructs the SpellChecker with a threshold
|
Modifier and Type | Method and Description |
---|---|
void |
addDictionary(SpellDictionary dictionary)
Accumulates a dictionary at the end of the dictionaries list used
for looking up words.
|
void |
addSpellCheckListener(SpellCheckListener listener)
Adds a SpellCheckListener to the listeners list.
|
void |
addToDictionary(java.lang.String word)
Adds a word to the user dictionary
|
int |
checkSpelling(WordTokenizer tokenizer)
This method is called to check the spelling of the words that are returned
by the WordTokenizer.
|
java.lang.String |
checkString(java.lang.String text)
Deprecated.
use checkSpelling(WordTokenizer)
|
protected boolean |
fireAndHandleEvent(WordTokenizer tokenizer,
SpellCheckEvent event)
This method will fire the spell check event and then handle the event
action that has been selected by the user.
|
protected void |
fireSpellCheckEvent(SpellCheckEvent event)
Fires off a spell check event to the listeners.
|
Configuration |
getConfiguration()
Supply the instance of the configuration holding the spell checking engine
parameters.
|
java.util.List |
getSuggestions(java.lang.String word,
int threshold)
Produces a list of suggested word after looking for suggestions in various
dictionaries.
|
void |
ignoreAll(java.lang.String word)
Adds a word to the list of ignored words
|
boolean |
isCorrect(java.lang.String word)
Verifies if the word to analyze is contained in dictionaries.
|
boolean |
isIgnored(java.lang.String word)
Indicates if a word is in the list of ignored words
|
static boolean |
isINETWord(java.lang.String word)
Verifies if the word that is being spell checked contains an Internet
address.
|
void |
removeSpellCheckListener(SpellCheckListener listener)
Removes a SpellCheckListener from the listeners list.
|
void |
reset()
This method clears the words that are currently being remembered as
Ignore All words and Replace All words. |
void |
setCache()
Activates a cache with the maximum number of entries set to 300
|
void |
setCache(int size)
Activates a cache with specified size
|
void |
setUserDictionary(SpellDictionary dictionary)
Registers the user dictionary to which words are added.
|
public static final int SPELLCHECK_OK
public static final int SPELLCHECK_CANCEL
public SpellChecker()
public SpellChecker(SpellDictionary dictionary)
dictionary
- The dictionary used for looking up words.public SpellChecker(SpellDictionary dictionary, int threshold)
dictionary
- the dictionary used for looking up words.threshold
- the cost value above which any suggestions are
thrown awaypublic void addDictionary(SpellDictionary dictionary)
dictionary
- the dictionary to add at the end of the dictionary list.public void setUserDictionary(SpellDictionary dictionary)
dictionary
- the dictionary to use when the user specify a new word
to add.public Configuration getConfiguration()
public void addSpellCheckListener(SpellCheckListener listener)
listener
- The feature to be added to the SpellCheckListener attributepublic void removeSpellCheckListener(SpellCheckListener listener)
listener
- The listener to be removed from the listeners list.protected void fireSpellCheckEvent(SpellCheckEvent event)
event
- The event that need to be processed by the spell checking
system.public void reset()
Ignore All
words and Replace All
words.public java.lang.String checkString(java.lang.String text)
Returns the corrected string.
text
- The text that need to be spelled checkedpublic static final boolean isINETWord(java.lang.String word)
word
- The word to analyze for an Internet address.protected boolean fireAndHandleEvent(WordTokenizer tokenizer, SpellCheckEvent event)
tokenizer
- Description of the Parameterevent
- The event to handlepublic void ignoreAll(java.lang.String word)
word
- The text of the word to ignorepublic void addToDictionary(java.lang.String word)
word
- The text of the word to addpublic boolean isIgnored(java.lang.String word)
word
- The text of the word checkpublic boolean isCorrect(java.lang.String word)
setUserDictionary(com.swabunga.spell.engine.SpellDictionary)
addDictionary(com.swabunga.spell.engine.SpellDictionary)
word
- The word to verify that it's spelling is known.public java.util.List getSuggestions(java.lang.String word, int threshold)
setUserDictionary(com.swabunga.spell.engine.SpellDictionary)
addDictionary(com.swabunga.spell.engine.SpellDictionary)
word
- The word for which we want to gather suggestionsthreshold
- the cost value above which any suggestions are
thrown awaypublic void setCache()
public void setCache(int size)
size
- - max. number of cache entries (0 to disable chache)public final int checkSpelling(WordTokenizer tokenizer)
tokenizer
- The media containing the text to analyze.