com.swabunga.spell.engine
Class SpellDictionaryDisk

java.lang.Object
  extended bycom.swabunga.spell.engine.SpellDictionaryASpell
      extended bycom.swabunga.spell.engine.SpellDictionaryDisk
All Implemented Interfaces:
SpellDictionary

public class SpellDictionaryDisk
extends SpellDictionaryASpell

An implementation of SpellDictionary that doesn't cache any words in memory. Avoids the huge footprint of SpellDictionaryHashMap at the cost of relatively minor latency. A future version of this class that implements some caching strategies might be a good idea in the future, if there's any demand for it.

This class makes use of the "classic" Java IO library (java.io). However, it could probably benefit from the new IO APIs (java.nio) and it is anticipated that a future version of this class, probably called SpellDictionaryDiskNIO will appear at some point.

Since:
0.5
Version:
0.1
Author:
Ben Galbraith ([email protected])

Field Summary
protected  boolean ready
           
 
Fields inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
tf
 
Constructor Summary
SpellDictionaryDisk(java.io.File base, java.io.File phonetic, boolean block)
          NOTE: Do *not* create two instances of this class pointing to the same File unless you are sure that a new dictionary does not have to be created.
 
Method Summary
 void addWord(java.lang.String word)
          Add a word permanently to the dictionary.
protected  void buildNewDictionaryDatabase()
           
 java.util.List getWords(java.lang.String code)
          Returns a list of words that have the same phonetic code.
 boolean isReady()
           
protected  void loadIndex()
           
 
Methods inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
getCode, getSuggestions, isCorrect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ready

protected boolean ready
Constructor Detail

SpellDictionaryDisk

public SpellDictionaryDisk(java.io.File base,
                           java.io.File phonetic,
                           boolean block)
                    throws java.io.FileNotFoundException,
                           java.io.IOException
NOTE: Do *not* create two instances of this class pointing to the same File unless you are sure that a new dictionary does not have to be created. In the future, some sort of external locking mechanism may be created that handles this scenario gracefully.

Parameters:
base - the base directory in which SpellDictionaryDisk can expect to find its necessary files
block - if a new word db needs to be created, there can be a considerable delay before the constructor returns. If block is true, this method will block while the db is created and return when done. If block is false, this method will create a thread to create the new dictionary and return immediately.
Method Detail

buildNewDictionaryDatabase

protected void buildNewDictionaryDatabase()
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
Throws:
java.io.FileNotFoundException
java.io.IOException

addWord

public void addWord(java.lang.String word)
Description copied from interface: SpellDictionary
Add a word permanently to the dictionary.


getWords

public java.util.List getWords(java.lang.String code)
Description copied from class: SpellDictionaryASpell
Returns a list of words that have the same phonetic code.

Specified by:
getWords in class SpellDictionaryASpell

isReady

public boolean isReady()

loadIndex

protected void loadIndex()
                  throws java.io.IOException
Throws:
java.io.IOException