com.wallstreetwise.app.jspell.domain
Class JSpellIndex

java.lang.Object
  extended by com.wallstreetwise.app.jspell.domain.JSpellIndex

public class JSpellIndex
extends java.lang.Object

This class manages a hybrid trie/linked list data structure on disk. The data structure contains a trie of phonetic codes, at the leaf node of the trie a linked list is maintained of all the words in that same phonetic grouping. When an attempt to locate a similar word is made the original word is compared against the words in the same phonetic grouping by using an equivalence/similarity scoring algorithm found in the Phonetics class. The first n words with a score greater than a given value are returned to the client.


Field Summary
static int baseOffset
          Represents the starting offset for phonetic and data nodes in this file.
static java.lang.String defaultCountry
          Default country of this dictionary file.
static java.lang.String defaultLanguage
          Default language of this dictionary file.
protected static java.util.HashMap mistakeHash
          Common spelling mistakes.
static java.lang.StringBuffer version
          Identifies JSpell dictionary version.
 
Constructor Summary
JSpellIndex()
          Constructor for the JSpellIndex class.
JSpellIndex(java.lang.String path, java.lang.String language, java.lang.String country)
          Constructs a JSpellIndex object.
JSpellIndex(java.lang.String path, java.lang.String language, java.lang.String country, java.lang.String jdxversion)
          Constructs a JSpellIndex object.
 
Method Summary
 void add(java.lang.String word)
          Add a word to the dictionary
 void close()
          Close access to the JSpellIndex.
protected  boolean englishChecks(boolean specialCase, java.lang.String lowerFirst, java.lang.String soundexCode, Suggestions suggestions)
          Handle additional English language specific checks.
protected  boolean frenchChecks(boolean specialCase, java.lang.String lowerFirst, java.lang.String soundexCode, Suggestions suggestions, boolean forceUpperCase)
          Handle additional French specific spell checker operations.
 int getBufferHit()
          An int containing the number of buffer 'hits'.
 int getBufferMiss()
          An int containing the number of buffer 'misses'.
 java.lang.String getIndexCountry()
          Returns the country of this dictionary file.
 java.lang.String getIndexLanguage()
          Returns the language of this dictionary file.
 java.lang.String getIndexPath()
          Returns the location of this dictionary file.
 boolean getLocked()
          Returns whether or not the JSpellIndex is currently locked, i.e., performing a search or add operation.
 java.lang.StringBuffer getVersion()
          Returns the version tag of this dictionary file.
 boolean isIndexReady()
          Returns the status of the JSpellIndex.
 void remove(java.lang.String original)
          Remove a word from the dictionary
 void resetBufferStatistics()
          Clear the number of buffer hits and misses.
 boolean search(java.lang.String soundex, java.lang.String original, java.lang.String[] suggestions)
          Overloaded to call search with true, get suggestions.
 boolean search(java.lang.String soundex, java.lang.String original, java.lang.String[] suggestions, boolean getSuggestions)
          Search for a given word and soundex code and optionally return suggestions.
 boolean search(java.lang.String original, Suggestions suggestions, boolean specialCase, boolean forceUpperCase)
          Wraps the search(String, String, String[]) method and performs additional search using lower case word if the original word passed begins with an upper case letter.
 void setLocked(boolean newValue)
          Sets the lock status of the JSpellIndex.
protected  void upperCaseSuggestions(java.lang.String original, boolean specialCase, boolean forceUpperCase, java.lang.String[] suggestions)
          Convert Strings in Suggestions object to Proper or UPPER CASE depending on parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static java.lang.StringBuffer version
Identifies JSpell dictionary version.


defaultLanguage

public static final java.lang.String defaultLanguage
Default language of this dictionary file.

See Also:
Constant Field Values

defaultCountry

public static final java.lang.String defaultCountry
Default country of this dictionary file.

See Also:
Constant Field Values

baseOffset

public static int baseOffset
Represents the starting offset for phonetic and data nodes in this file.


mistakeHash

protected static java.util.HashMap mistakeHash
Common spelling mistakes.

Constructor Detail

JSpellIndex

public JSpellIndex()
Constructor for the JSpellIndex class.


JSpellIndex

public JSpellIndex(java.lang.String path,
                   java.lang.String language,
                   java.lang.String country)
Constructs a JSpellIndex object.

Parameters:
path - location of this dictionary file.
language - language of this dictionary file.
country - country of this dictionary file.

JSpellIndex

public JSpellIndex(java.lang.String path,
                   java.lang.String language,
                   java.lang.String country,
                   java.lang.String jdxversion)
Constructs a JSpellIndex object.

Parameters:
path - location of this dictionary file.
language - language of this dictionary file.
country - country of this dictionary file.
jdxversion - Medical, Legal, Other, specify as string, becomes part of filename
Method Detail

getBufferHit

public int getBufferHit()
An int containing the number of buffer 'hits'.

Returns:
The number of buffer 'hits'.

getBufferMiss

public int getBufferMiss()
An int containing the number of buffer 'misses'.

Returns:
The number of buffer 'misses'.

resetBufferStatistics

public void resetBufferStatistics()
Clear the number of buffer hits and misses.


getVersion

public java.lang.StringBuffer getVersion()
Returns the version tag of this dictionary file.

Returns:
a String.

getIndexLanguage

public java.lang.String getIndexLanguage()
Returns the language of this dictionary file.

Returns:
a String.

getIndexCountry

public java.lang.String getIndexCountry()
Returns the country of this dictionary file.

Returns:
a String.

getIndexPath

public java.lang.String getIndexPath()
Returns the location of this dictionary file.

Returns:
a String.

close

public final void close()
Close access to the JSpellIndex.


isIndexReady

public final boolean isIndexReady()
Returns the status of the JSpellIndex.

Returns:
true or false

getLocked

public final boolean getLocked()
Returns whether or not the JSpellIndex is currently locked, i.e., performing a search or add operation.

Returns:
true or false

setLocked

public final void setLocked(boolean newValue)
Sets the lock status of the JSpellIndex.

Parameters:
newValue - true or false

add

public final void add(java.lang.String word)
Add a word to the dictionary

Parameters:
word - a String representing an individual word.

remove

public final void remove(java.lang.String original)
Remove a word from the dictionary

Parameters:
original - a String representing an individual word.

search

public final boolean search(java.lang.String original,
                            Suggestions suggestions,
                            boolean specialCase,
                            boolean forceUpperCase)
                     throws java.io.IOException
Wraps the search(String, String, String[]) method and performs additional search using lower case word if the original word passed begins with an upper case letter. This is inexpensive, since, the previous search with the same phonetic code should still be buffered.

Parameters:
original - a String representing a word.
suggestions - a Suggestions object.
specialCase - true or false, should word be proper.
forceUpperCase - true or false, should word be UPPER CASE.
Returns:
true or false, was word found.
Throws:
java.io.IOException - an Exception object.

upperCaseSuggestions

protected void upperCaseSuggestions(java.lang.String original,
                                    boolean specialCase,
                                    boolean forceUpperCase,
                                    java.lang.String[] suggestions)
Convert Strings in Suggestions object to Proper or UPPER CASE depending on parameters.

Parameters:
original - a String representing the original word.
specialCase - true or false, should suggestions be Proper?
forceUpperCase - true or false, should suggestions be UPPER CASE?
suggestions - a Suggestions object.

frenchChecks

protected boolean frenchChecks(boolean specialCase,
                               java.lang.String lowerFirst,
                               java.lang.String soundexCode,
                               Suggestions suggestions,
                               boolean forceUpperCase)
Handle additional French specific spell checker operations.

Parameters:
specialCase - true or false, Proper?
lowerFirst - a String, lower case version of word.
soundexCode - a String representing the phonetic code of the word.
suggestions - a Suggestions object.
forceUpperCase - true or false, return suggestions in UPPER CASE.
Returns:
true or false

englishChecks

protected boolean englishChecks(boolean specialCase,
                                java.lang.String lowerFirst,
                                java.lang.String soundexCode,
                                Suggestions suggestions)
                         throws java.io.IOException
Handle additional English language specific checks.

Parameters:
specialCase - true or false, should suggestions be Proper?
lowerFirst - a String representing the lower case version of the original word.
soundexCode - a String representing a phonetic code.
suggestions - a Suggestions object.
Returns:
true or false.
Throws:
java.io.IOException - an Exception object.

search

public boolean search(java.lang.String soundex,
                      java.lang.String original,
                      java.lang.String[] suggestions)
               throws java.io.IOException
Overloaded to call search with true, get suggestions.

Parameters:
soundex - a String representing the phonetic code.
original - a String representing the original word.
suggestions - a Suggestions object.
Returns:
true or false
Throws:
java.io.IOException - an Exception object.

search

public boolean search(java.lang.String soundex,
                      java.lang.String original,
                      java.lang.String[] suggestions,
                      boolean getSuggestions)
               throws java.io.IOException
Search for a given word and soundex code and optionally return suggestions.

Parameters:
getSuggestions - true or false, return suggestions?
soundex - a String representing a phonetic code.
original - a String representing the original word.
suggestions - a Suggestions object.
Returns:
true or false
Throws:
java.io.IOException - an Exception object.


JSpell SDK 2004 Spell Checker for the Java (tm) Platform
Copyright © 1996-2005 The Solution Cafe Inc, All Rights Reserved - http://www.thesolutioncafe.com