public class DiskSpellingDictionary extends ASpellSpellingDictionary
SpellDictionary that doesn't cache any
words in memory. Avoids the huge footprint of
HashedSpellingDictionary 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), or those introduced in Java 8.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
ready
A flag indicating if the initial preparation or loading of the on disk
dictionary is complete.
|
transformator| Constructor and Description |
|---|
DiskSpellingDictionary(java.io.File baseDirectory,
java.io.File phoneticFile)
Construct a spell dictionary on disk.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addWord(java.lang.String word)
Adds another word to the dictionary.
|
protected void |
buildNewDictionaryDatabase()
Builds the file words database file and the contents file for the on disk
dictionary.
|
java.util.List<java.lang.String> |
getWords(java.lang.String code)
Returns a list of words that have the same phonetic code.
|
boolean |
isReady()
Indicates if the initial preparation or loading of the on disk dictionary
is complete.
|
protected void |
loadIndex()
Loads the index file from disk.
|
getPhoneticCode, getSuggestions, getSuggestions, isCorrectprotected boolean ready
public DiskSpellingDictionary(java.io.File baseDirectory,
java.io.File phoneticFile)
throws java.io.FileNotFoundException,
java.io.IOException
base/words dictionary where base is the path to
words dictionary. The on disk spell dictionary is created in
base/db dictionary and contains files:
contents list the words files used for spelling.words.db the content of words files organized as a
database of words.words.idx an index file to the words.db
file content.contents file has a list of filename, size
indicating the name and length of each files in the
base/words dictionary. If one of theses files was changed,
added or deleted before the call to the constructor, the process of
producing new or updated words.db and words.idx
files is started again.
The spellchecking process is then worked upon the words.db
and words.idx files.
NB: the constructor may take a long time to run while it constructs or loads the dictionaries. The caller should run this constructor in a separate thread to avoid the calling thread being blocked.
NOTE: Do *not* create two instances of this class pointing to the samebase 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.baseDirectory - the base directory in which SpellDictionaryDisk
can expect to find its necessary files.phoneticFile - the phonetic file used by the spellchecker.java.io.FileNotFoundException - indicates problems locating the
files on the systemjava.io.IOException - indicates problems reading the filesprotected final void buildNewDictionaryDatabase()
throws java.io.FileNotFoundException,
java.io.IOException
java.io.FileNotFoundException - if the files cannot be locatedjava.io.IOExceptionpublic void addWord(java.lang.String word)
word - The word to add.public java.util.List<java.lang.String> getWords(java.lang.String code)
getWords in class ASpellSpellingDictionarycode - The phonetic code common to the list of wordspublic boolean isReady()
protected final void loadIndex()
throws java.io.IOException
java.io.IOException - if a problem is encountered reading the index file.