com.swabunga.spell.engine
Class SpellDictionaryHashMap

java.lang.Object
  extended by com.swabunga.spell.engine.SpellDictionaryASpell
      extended by com.swabunga.spell.engine.SpellDictionaryHashMap
All Implemented Interfaces:
SpellDictionary
Direct Known Subclasses:
SpellDictionaryMultiLingual

public class SpellDictionaryHashMap
extends SpellDictionaryASpell

The SpellDictionaryHashMap holds 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).


Constructor Summary
SpellDictionaryHashMap()
          Dictionary Constructor.
SpellDictionaryHashMap(java.io.File wordList)
          Dictionary Convenience Constructor.
SpellDictionaryHashMap(java.io.File wordList, java.io.File phonetic)
          Dictionary constructor that uses an aspell phonetic file to build the transformation table.
SpellDictionaryHashMap(java.io.File wordList, java.io.File phonetic, java.lang.String phoneticEncoding)
          Dictionary constructor that uses an aspell phonetic file to build the transformation table.
SpellDictionaryHashMap(java.io.File wordList, java.io.Reader phonetic)
          Constructor for the SpellDictionaryHashMap object
SpellDictionaryHashMap(java.io.Reader wordList)
          Dictionary Constructor.
SpellDictionaryHashMap(java.io.Reader wordList, java.io.Reader phonetic)
          Dictionary constructor that uses an aspell phonetic file to build the transformation table.
 
Method Summary
 void addDictionary(java.io.File wordList)
          Add words from a file to existing dictionary hashmap.
 void addDictionary(java.io.Reader wordList)
          Adds a feature to the Dictionary attribute of the SpellDictionaryHashMap object
 void addWord(java.lang.String word)
          Add a word permanantly to the dictionary (and the dictionary file).
 java.util.List getWords(java.lang.String code)
          Returns a list of strings (words) for the code.
 boolean isCorrect(java.lang.String word)
          Returns true if the word is correctly spelled against the current word list.
 
Methods inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
getCode, getSuggestions
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpellDictionaryHashMap

public SpellDictionaryHashMap()
                       throws java.io.IOException
Dictionary Constructor.

Throws:
java.io.IOException - Description of the Exception

SpellDictionaryHashMap

public SpellDictionaryHashMap(java.io.Reader wordList)
                       throws java.io.IOException
Dictionary Constructor.

Parameters:
wordList - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

SpellDictionaryHashMap

public SpellDictionaryHashMap(java.io.File wordList)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Dictionary Convenience Constructor.

Parameters:
wordList - Description of the Parameter
Throws:
java.io.FileNotFoundException - Description of the Exception
java.io.IOException - Description of the Exception

SpellDictionaryHashMap

public SpellDictionaryHashMap(java.io.File wordList,
                              java.io.File phonetic)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Dictionary constructor that uses an aspell phonetic file to build the transformation table.

Parameters:
wordList - Description of the Parameter
phonetic - Description of the Parameter
Throws:
java.io.FileNotFoundException - Description of the Exception
java.io.IOException - Description of the Exception

SpellDictionaryHashMap

public SpellDictionaryHashMap(java.io.File wordList,
                              java.io.Reader phonetic)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Constructor for the SpellDictionaryHashMap object

Parameters:
wordList - Description of the Parameter
phonetic - Description of the Parameter
Throws:
java.io.FileNotFoundException - Description of the Exception
java.io.IOException - Description of the Exception

SpellDictionaryHashMap

public SpellDictionaryHashMap(java.io.File wordList,
                              java.io.File phonetic,
                              java.lang.String phoneticEncoding)
                       throws java.io.FileNotFoundException,
                              java.io.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 - Description of the Parameter
phonetic - Description of the Parameter
phoneticEncoding - Description of the Parameter
Throws:
java.io.FileNotFoundException - Description of the Exception
java.io.IOException - Description of the Exception

SpellDictionaryHashMap

public SpellDictionaryHashMap(java.io.Reader wordList,
                              java.io.Reader phonetic)
                       throws java.io.IOException
Dictionary constructor that uses an aspell phonetic file to build the transformation table.

Parameters:
wordList - Description of the Parameter
phonetic - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception
Method Detail

addDictionary

public void addDictionary(java.io.File wordList)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
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:
java.io.FileNotFoundException
java.io.IOException

addDictionary

public void addDictionary(java.io.Reader wordList)
                   throws java.io.IOException
Adds a feature to the Dictionary attribute of the SpellDictionaryHashMap object

Parameters:
wordList - The feature to be added to the Dictionary attribute
Throws:
java.io.IOException - Description of the Exception

addWord

public void addWord(java.lang.String word)
Add a word permanantly to the dictionary (and the dictionary file).

This needs to be made thread safe (synchronized)

Parameters:
word - The feature to be added to the Word attribute

getWords

public java.util.List getWords(java.lang.String code)
Returns a list of strings (words) for the code.

Parameters:
code - Description of the Parameter
Returns:
The words value

isCorrect

public boolean isCorrect(java.lang.String word)
Returns true if the word is correctly spelled against the current word list.

Specified by:
isCorrect in interface SpellDictionary
Overrides:
isCorrect in class SpellDictionaryASpell
Parameters:
word - Description of the Parameter
Returns:
The correct value