Class SpellDictionaryHashMap
- All Implemented Interfaces:
SpellDictionary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Hashtable
The hashmap that contains the word dictionary.Fields inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
tf
-
Constructor Summary
ConstructorsConstructorDescriptionDictionary Constructor.SpellDictionaryHashMap
(File wordList) Dictionary convenience Constructor.SpellDictionaryHashMap
(File wordList, File phonetic) Dictionary constructor that uses an aspell phonetic file to build the transformation table.SpellDictionaryHashMap
(File wordList, File phonetic, String phoneticEncoding) Dictionary constructor that uses an aspell phonetic file to build the transformation table.SpellDictionaryHashMap
(Reader wordList) Dictionary Constructor.SpellDictionaryHashMap
(Reader wordList, Reader phonetic) Dictionary constructor that uses an aspell phonetic file to build the transformation table. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDictionary
(File wordList) Add words from a file to existing dictionary hashmap.void
addDictionary
(Reader wordList) Add words from a Reader to existing dictionary hashmap.protected void
Adds to the existing dictionary from a word list file.void
Add a word permanently to the dictionary (and the dictionary file).protected void
Constructs the dictionary from a word list file.Returns a list of strings (words) for the code.boolean
Returns true if the word is correctly spelled against the current word list.protected void
Allocates a word in the dictionaryprotected void
putWordUnique
(String word) Allocates a word, if it is not already present in the dictionary.Methods inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
getCode, getSuggestions, getSuggestions
-
Field Details
-
mainDictionary
The hashmap that contains the word dictionary. The map is hashed on the doublemeta code. The map entry contains a LinkedList of words that have the same double meta code.
-
-
Constructor Details
-
SpellDictionaryHashMap
Dictionary Constructor.- Throws:
IOException
- indicates a problem with the file system
-
SpellDictionaryHashMap
Dictionary Constructor.- Parameters:
wordList
- The file containing the words list for the dictionary- Throws:
IOException
- indicates problems reading the words list file
-
SpellDictionaryHashMap
Dictionary convenience Constructor.- Parameters:
wordList
- The file containing the words list for the dictionary- Throws:
FileNotFoundException
- indicates problems locating the words list file on the systemIOException
- indicates problems reading the words list file
-
SpellDictionaryHashMap
public SpellDictionaryHashMap(File wordList, File phonetic) throws FileNotFoundException, IOException Dictionary constructor that uses an aspell phonetic file to build the transformation table.- Parameters:
wordList
- The file containing the words list for the dictionaryphonetic
- The file to use for phonetic transformation of the wordlist.- Throws:
FileNotFoundException
- indicates problems locating the file on the systemIOException
- indicates problems reading the words list file
-
SpellDictionaryHashMap
public SpellDictionaryHashMap(File wordList, File phonetic, String phoneticEncoding) throws FileNotFoundException, IOException Dictionary constructor that uses an aspell phonetic file to build the transformation table. Encoding is used for phonetic file only; default encoding is used for wordList- Parameters:
wordList
- 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 specified- Throws:
FileNotFoundException
- indicates problems locating the file on the systemIOException
- indicates problems reading the words list or phonetic information
-
SpellDictionaryHashMap
Dictionary constructor that uses an aspell phonetic file to build the transformation table.- Parameters:
wordList
- The file containing the words list for the dictionaryphonetic
- The reader to use for phonetic transformation of the wordlist.- Throws:
IOException
- indicates problems reading the words list or phonetic information
-
-
Method Details
-
addDictionary
Add words from a file to existing dictionary hashmap. This function 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()
- Parameters:
wordList
- a File object that contains the words, on word per line.- Throws:
FileNotFoundException
IOException
-
addDictionary
Add words from a Reader to existing dictionary hashmap. This function 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()
- Parameters:
wordList
- a Reader object that contains the words, on word per line.- Throws:
IOException
-
addWord
Add a word permanently to the dictionary (and the dictionary file).This needs to be made thread safe (synchronized)
- Parameters:
word
- The word to add to the dictionary
-
createDictionary
Constructs the dictionary from a word list file.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 allot.
- Throws:
IOException
-
addDictionaryHelper
Adds to the existing dictionary from a word list file. If the word already exists in the dictionary, a new entry is not added.Each word in the reader should be on a separate line.
Note: for whatever reason that I haven't yet looked into, the phonetic codes for a particular word map to a vector of words rather than a hash table. This is a drag since in order to check for duplicates you have to iterate through all the words that use the phonetic code. If the vector-based implementation is important, it may be better to subclass for the cases where duplicates are bad.
- Throws:
IOException
-
putWord
Allocates a word in the dictionary- Parameters:
word
- The word to add
-
putWordUnique
Allocates a word, if it is not already present in the dictionary. A word with a different case is considered the same.- Parameters:
word
- The word to add
-
getWords
Returns a list of strings (words) for the code.- Specified by:
getWords
in classSpellDictionaryASpell
- Parameters:
code
- The phonetic code common to the list of words- Returns:
- A list of words having the same phonetic code
-
isCorrect
Returns true if the word is correctly spelled against the current word list.- Specified by:
isCorrect
in interfaceSpellDictionary
- Overrides:
isCorrect
in classSpellDictionaryASpell
- Parameters:
word
- The word to verify if it's spelling is OK.- Returns:
- Indicates if the word is present in the dictionary.
-