Package com.swabunga.spell.engine
Class GenericSpellDictionary
java.lang.Object
com.swabunga.spell.engine.SpellDictionaryASpell
com.swabunga.spell.engine.GenericSpellDictionary
- All Implemented Interfaces:
SpellDictionary
The SpellDictionary class holds the instance of the dictionary.
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).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashMap
The hashmap that contains the word dictionary.Fields inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
tf
-
Constructor Summary
ConstructorsConstructorDescriptionGenericSpellDictionary
(File wordList) Dictionary constructor that uses the DoubleMeta class with the English alphabet.GenericSpellDictionary
(File wordList, File phonetic) Dictionary constructor that uses an aspell phonetic file to build the transformation table. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 dictionaryMethods 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
-
GenericSpellDictionary
Dictionary constructor that uses the DoubleMeta class with the English alphabet.- Parameters:
wordList
- The file containing dictionary as a words list.- Throws:
FileNotFoundException
- when the words list file could not be located on the system.IOException
- when problems occurs while reading the words list file
-
GenericSpellDictionary
public GenericSpellDictionary(File wordList, File phonetic) throws FileNotFoundException, IOException Dictionary constructor that uses an aspell phonetic file to build the transformation table. If phonetic is null, then DoubleMeta is used with the English alphabet- Parameters:
wordList
- The file containing dictionary as a words list.phonetic
- The file containing the phonetic transformation information.- Throws:
FileNotFoundException
- when the words list or phonetic file could not be located on the systemIOException
- when problems occurs while reading the words list or phonetic file
-
-
Method Details
-
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
-
putWord
Allocates a word in the dictionary -
getWords
Returns a list of strings (words) for the code.- Specified by:
getWords
in classSpellDictionaryASpell
- Parameters:
code
- The phonetic code we want to find words for- Returns:
- the 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 checked in the dictionary- Returns:
- indication if the word is in the dictionary
-