public interface SpellingChecker
This interface defines methods useful when constructing a spelling checker in an application. The interface provides for looking up words in two persistent dictionaries, a global dictionary shared among many users, and a local dictionary specific to an individual. An individual use can also add words to a transient "ignore" cache which contains words which should be ignored during the course of spell checking a specific document.
A typical SpellingChecker implementation might store the dictionaries in a file or a database. Usually some kind of hash code is stored along with each word in the dictionary to support the notion of spelling correction. For example, an English dictionary might store the soundex or metaphone code for each word in the dictionary to ease production of a list of correctly spelled alternatives to a misspelled word.
Assuming an implementation called "MySpellingChecker", a sample sequence to spelling check a word might go as follows.
MySpellingChecker myChecker =
new MySpellingChecker(
new FileBasedSpellingDictionary( "global.english" ) ,
new FileBasedSpellingDictionary( "user.english" ) );
...
if ( !myChecker.checkSpelling( someWord ) )
{
String[] suggestions = myChecker.suggest( someWord );
// Show list of suggestions, etc.
}
Modifier and Type | Method and Description |
---|---|
boolean |
addWordToGlobalDictionary(java.lang.String word)
Add a word to the global dictionary.
|
boolean |
addWordToIgnoreList(java.lang.String word)
Add word to ignore list.
|
boolean |
addWordToLocalDictionary(java.lang.String word)
Add a word to the local dictionary.
|
boolean |
checkSpelling(java.lang.String word)
Check spelling of word.
|
void |
emptyIgnoreList()
Empties the ignore list.
|
java.lang.String[] |
suggest(java.lang.String word)
Suggest alternative words for misspelled item.
|
void |
useGlobalDictionary(SpellingDictionary dictionary)
Select global dictionary to use to check spelling.
|
void |
useLocalDictionary(SpellingDictionary dictionary)
Select local dictionary to use to check spelling.
|
void useGlobalDictionary(SpellingDictionary dictionary)
dictionary
- Identifies global dictionary,
a class implementing the
SpellingDictionary interface.
If the name is null, no global
dictionary is used.
The global dictionary is usually shared among many users. Typically it is created by a system administrator as a shareable resource.
void useLocalDictionary(SpellingDictionary dictionary)
dictionary
- Identifies local dictionary,
a class implementing the
SpellingDictionary interface.
If the name is null, no local
dictionary is used.
The local dictionary is usually limited to access by a single individual. The local dictionary generally contains words added by an individual while checking the spelling of one or more documents.
boolean checkSpelling(java.lang.String word)
word
- The word whose spelling should be checked.java.lang.String[] suggest(java.lang.String word)
word
- The misspelled word for which
possible alternatives are desired.The suggested words are typically words which are similar in sound or spelling to the misspelled word. For English, an implementation might return all words with the same soundex or metaphone code as the misspelled word.
boolean addWordToLocalDictionary(java.lang.String word)
word
- The word to add to the local dictionary.boolean addWordToGlobalDictionary(java.lang.String word)
word
- The word to add to the global dictionary.Typically this function is retricted to system administrators.
boolean addWordToIgnoreList(java.lang.String word)
word
- Word to ignore.The ignore list contains words which an individual marks as ignorable while checking the spelling of one of more documents. The ignore list is transient. If an ignored word is to persist across multiple spelling check sessions, the word should be added to the local dictionary.
void emptyIgnoreList()
Removes all words from the ignore list. Typically this is invoked at the start of a spelling checker session for a new document.