Package com.swabunga.spell.engine
Class SpellDictionaryDisk
- java.lang.Object
-
- com.swabunga.spell.engine.SpellDictionaryASpell
-
- com.swabunga.spell.engine.SpellDictionaryDisk
-
- All Implemented Interfaces:
SpellDictionary
public class SpellDictionaryDisk extends SpellDictionaryASpell
An implementation ofSpellDictionarythat doesn't cache any words in memory. Avoids the huge footprint ofSpellDictionaryHashMapat 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
SpellDictionaryDiskNIOwill appear at some point.- Since:
- 0.5
- Version:
- 0.1
- Author:
- Ben Galbraith (ben@galbraiths.org)
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanreadyThe flag indicating if the initial preparation or loading of the on disk dictionary is complete.-
Fields inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
tf
-
-
Constructor Summary
Constructors Constructor Description SpellDictionaryDisk(java.io.File base, java.io.File phonetic, boolean block)Construct a spell dictionary on disk.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddWord(java.lang.String word)Adds another word to the dictionary.protected voidbuildNewDictionaryDatabase()Builds the file words database file and the contents file for the on disk dictionary.java.util.ListgetWords(java.lang.String code)Returns a list of words that have the same phonetic code.booleanisReady()Indicates if the initial preparation or loading of the on disk dictionary is complete.protected voidloadIndex()Loads the index file from disk.-
Methods inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
getCode, getSuggestions, getSuggestions, isCorrect
-
-
-
-
Constructor Detail
-
SpellDictionaryDisk
public SpellDictionaryDisk(java.io.File base, java.io.File phonetic, boolean block) throws java.io.FileNotFoundException, java.io.IOExceptionConstruct a spell dictionary on disk. The spell dictionary is created from words list(s) contained in file(s). A words list file is a file with one word per line. Words list files are located in abase/wordsdictionary wherebaseis the path towordsdictionary. The on disk spell dictionary is created inbase/dbdictionary and contains files:contentslist the words files used for spelling.words.dbthe content of words files organized as a database of words.words.idxan index file to thewords.dbfile content.
contentsfile has a list offilename, sizeindicating the name and length of each files in thebase/wordsdictionary. If one of theses files was changed, added or deleted before the call to the constructor, the process of producing new or updatedwords.dbandwords.idxfiles is started again. The spellchecking process is then worked upon thewords.dbandwords.idxfiles. NOTE: Do *not* create two instances of this class pointing to the samebaseunless 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 whichSpellDictionaryDiskcan expect to find its necessary files.phonetic- the phonetic file used by the spellchecker.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.- Throws:
java.io.FileNotFoundException- indicates problems locating the files on the systemjava.io.IOException- indicates problems reading the files
-
-
Method Detail
-
buildNewDictionaryDatabase
protected void buildNewDictionaryDatabase() throws java.io.FileNotFoundException, java.io.IOExceptionBuilds the file words database file and the contents file for the on disk dictionary.- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
addWord
public void addWord(java.lang.String word)
Adds another word to the dictionary. This method is not yet implemented for this class.- Parameters:
word- The word to add.
-
getWords
public java.util.List getWords(java.lang.String code)
Returns a list of words that have the same phonetic code.- Specified by:
getWordsin classSpellDictionaryASpell- Parameters:
code- The phonetic code common to the list of words- Returns:
- A list of words having the same phonetic code
-
isReady
public boolean isReady()
Indicates if the initial preparation or loading of the on disk dictionary is complete.- Returns:
- the indication that the dictionary initial setup is done.
-
loadIndex
protected void loadIndex() throws java.io.IOExceptionLoads the index file from disk. The index file accelerates words lookup into the dictionary db file.- Throws:
java.io.IOException
-
-