public class HashedSpellingDictionary extends ASpellSpellingDictionary
This class is thread safe. Derived classes should ensure that this preserved.
There are many open source dictionary files. For just a few see: http://wordlist.sourceforge.net/
This dictionary class reads words one per line. Make sure that your word list is formatted in this way (most are).
Note that you must create the dictionary with a word list for the added words to persist.
transformator| Constructor and Description |
|---|
HashedSpellingDictionary()
Dictionary Constructor.
|
HashedSpellingDictionary(java.io.File wordListFile)
Dictionary convenience Constructor.
|
HashedSpellingDictionary(java.io.File wordListFile,
boolean isNormalised)
Dictionary convenience Constructor with the option to normalise the
entries.
|
HashedSpellingDictionary(java.io.File wordListFile,
java.io.File phonetic)
Dictionary constructor that uses an aspell phonetic file to build the
transformation table.
|
HashedSpellingDictionary(java.io.File wordListFile,
java.io.File phonetic,
java.lang.String phoneticEncoding)
Dictionary constructor that uses an aspell phonetic file to build the
transformation table.
|
HashedSpellingDictionary(java.io.Reader wordList)
Dictionary Constructor.
|
HashedSpellingDictionary(java.io.Reader wordList,
boolean isNormalised)
Dictionary Constructor with the option to normalise the entries.
|
HashedSpellingDictionary(java.io.Reader wordListFile,
java.io.Reader phonetic)
Dictionary constructor that uses an aspell phonetic file to build the
transformation table.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDictionary(java.io.File wordListFile)
Add words from a file to an existing dictionary
HashMap. |
void |
addDictionary(java.io.Reader wordList)
Add words from a Reader to existing dictionary
HashMap. |
protected void |
addDictionaryHelper(java.io.BufferedReader in)
Adds to the existing dictionary from a word list file.
|
void |
addWord(java.lang.String word)
Add a word permanently to the dictionary (and the dictionary file).
|
protected void |
createDictionary(java.io.BufferedReader in)
Constructs the dictionary from a word list file.
|
protected void |
createNormalisedDictionary(java.io.BufferedReader in)
Constructs the dictionary from a word list file where all words are
normalised to lower case.
|
java.util.List<java.lang.String> |
getWords(java.lang.String code)
Returns a list of strings (words) for the phonetic code.
|
protected void |
putWord(java.lang.String word)
Stores a word in the dictionary
|
protected void |
putWordUnique(java.lang.String word)
Stores a word, if it is not already present in the dictionary.
|
getPhoneticCode, getSuggestions, getSuggestions, isCorrectpublic HashedSpellingDictionary()
throws java.io.IOException
java.io.IOException - indicates a problem with the file systempublic HashedSpellingDictionary(java.io.Reader wordList)
throws java.io.IOException
wordList - The file containing the words list for the dictionaryjava.io.IOException - indicates problems reading the words list
filepublic HashedSpellingDictionary(java.io.Reader wordList,
boolean isNormalised)
throws java.io.IOException
wordList - The file containing the words list for the dictionaryisNormalised - indicates whether the word list should be normalised
to lower casejava.io.IOException - if problems were encountered reading the
word list filepublic HashedSpellingDictionary(java.io.File wordListFile)
throws java.io.FileNotFoundException,
java.io.IOException
wordListFile - The file containing the words list for the dictionaryjava.io.FileNotFoundException - if a problem was encountered
locating the word list file on the systemjava.io.IOException - if problems were encountered reading the
word list filepublic HashedSpellingDictionary(java.io.File wordListFile,
boolean isNormalised)
throws java.io.FileNotFoundException,
java.io.IOException
wordListFile - The file containing the words list for the dictionaryisNormalised - indicates whether the word list should be normalised
to lower casejava.io.FileNotFoundException - if a problem was encountered
locating the word list file on the systemjava.io.IOException - if problems were encountered reading the
word list filepublic HashedSpellingDictionary(java.io.File wordListFile,
java.io.File phonetic)
throws java.io.FileNotFoundException,
java.io.IOException
wordListFile - The file containing the words list for the dictionaryphonetic - The file to use for phonetic transformation of the
wordlist.java.io.FileNotFoundException - if a problem was encountered
locating the word list file on the systemjava.io.IOException - if problems were encountered reading the
word list filepublic HashedSpellingDictionary(java.io.File wordListFile,
java.io.File phonetic,
java.lang.String phoneticEncoding)
throws java.io.FileNotFoundException,
java.io.IOException
wordListFile - The file containing the words list for the dictionaryphonetic - The file to use for phonetic transformation of the
wordlist.phoneticEncoding - Uses the character set encoding specifiedjava.io.FileNotFoundException - if a problem was encountered
locating the word list file on the systemjava.io.IOException - if problems were encountered reading the
word list filepublic HashedSpellingDictionary(java.io.Reader wordListFile,
java.io.Reader phonetic)
throws java.io.IOException
wordListFile - The file containing the words list for the dictionaryphonetic - The reader to use for phonetic transformation of the
wordlist.java.io.IOException - if problems were encountered reading the
word list or phonetic informationpublic void addDictionary(java.io.File wordListFile)
throws java.io.FileNotFoundException,
java.io.IOException
HashMap. This
method can be called as many times as needed to build the internal
word list. Duplicates are not added.
Note that adding a dictionary does not affect the target dictionary file for the addWord method. That is, addWord() continues to make additions to the dictionary file specified in createDictionary()
wordListFile - a File object that contains the words, one word per
line.java.io.FileNotFoundException - if the file is not locatedjava.io.IOException - if a problem is encountered reading the filepublic void addDictionary(java.io.Reader wordList)
throws java.io.IOException
HashMap. This
method can be called as many times as needed to build the internal
word list. Duplicates are not added.
Note that adding a dictionary does not affect the target dictionary file for the addWord method. That is, addWord() continues to make additions to the dictionary file specified in createDictionary()
wordList - a Reader object that contains the words, one word per
line.java.io.IOException - if a problem is encountered adding words to the
dictionary.public void addWord(java.lang.String word)
This needs to be made thread safe
Not implemented!
word - A word to add to the dictionary.protected final void createDictionary(java.io.BufferedReader in)
throws java.io.IOException
Each word in the reader should be on a separate line.
in - a reader for a word list filejava.io.IOException - if a problem is encountered reading the file.protected final void createNormalisedDictionary(java.io.BufferedReader in)
throws java.io.IOException
Each word in the reader should be on a separate line.
This is a very slow function. On my machine it takes quite a while to load the data in. I suspect that we could speed this up quite a lot.
in - a reader for a word list filejava.io.IOException - if a problem is encountered reading the file.protected void addDictionaryHelper(java.io.BufferedReader in)
throws java.io.IOException
Each word in the reader should be on a separate line.
in - a reader for a word list filejava.io.IOException - if a problem is encountered reading the file.protected void putWord(java.lang.String word)
word - The word to addprotected void putWordUnique(java.lang.String word)
word - The word to addpublic java.util.List<java.lang.String> getWords(java.lang.String code)
getWords in class ASpellSpellingDictionarycode - a phonetic code.