com.wallstreetwise.app.jspell.domain
Class JSpellDictionary

java.lang.Object
  extended by com.wallstreetwise.app.jspell.domain.JSpellDictionary
All Implemented Interfaces:
JSpellDictionaryAccessor
Direct Known Subclasses:
JSpellDictionaryLocal, JSpellDictionaryServlet

public abstract class JSpellDictionary
extends java.lang.Object
implements JSpellDictionaryAccessor

A JSpellDictionary is an abstract class that is the base class for all JSpell dictionary access classes. CVS Version ID $Id: JSpellDictionary.java,v 1.2 2005/09/07 14:50:23 clifford_admin Exp $


Field Summary
protected  int batchCount
          This variable is used internally.
protected  int batchSize
          This variable determines the number of words to send to the server in a single 'batch'.
protected  JSpellErrorInfo currentError
          The current error being processed.
protected  boolean dictionaryReady
          Was the dictionary opened successfully and can it be searched?
protected  java.util.HashMap errorCache
          A HashMap containing the errors waiting to be processed.
protected  java.util.Vector errors
          A Vector containing the errors returned by the spell checker.
protected  boolean forceUpperCase
          When true, all suggestions returned by the spell checker will be in UPPER CASE.
protected  boolean ignoreDoubleWords
          When true, JSpell will not flag an error if a word is repeated.
protected  boolean ignoreFirstCaps
          If false and the first character in a field being spell checked is not capitalized then JSpell will flag an error.
protected  boolean ignoreIrregularCaps
          When false, JSpell will flag an error if a word is at the beginning of a sentence but is not capitalized.
protected  boolean ignoreUpper
          If true, JSpell will not attempt to spell check words that are in all UPPER CASE.
protected  java.util.HashMap ignoreWords
          A HashMap of words to ignore.
protected  boolean ignoreWordsWithNumbers
          When true, JSpell will ignore any words containing numbers and will not attempt to spell check them.
protected  boolean learnWords
          If true, the user (local or server) may permanently add words to the dictionary.
protected  int maxSuggestions
          The maximum number of suggestions to return.
protected  java.lang.String nextWord
          This variable determines the number of words to send to the server in one spell check request.
protected  Suggestions suggestions
          The suggestions for the incorrect word.
protected  java.util.HashMap validWords
          A HashMap of all the validWords that have been accessed by the JSpell spell checker routines.
 
Constructor Summary
JSpellDictionary()
          Constructs a JSpellDictionary object.
 
Method Summary
protected  void addFrequentWords()
          Loads validWords HashMap with frequently used words in the English language.
 void adjustErrorPositions(int offset)
          Used to adjust the internal position references of the errors returned by the spell checker.
 boolean checkCaps(char curChar, char prevChar)
          This method determines if JSpell is at the end of a sentence.
 boolean checkCaps(char curChar, char prevChar, boolean hasDigits, boolean capsFlag)
          This method determines if JSpell is at the end of a sentence.
 boolean checkWord(JSpellWordBundle word)
          Sends words to be checked by the dictionary.
 int getBatchSize()
          Get the number of words that can be validated by this access interface before getting errors back
 JSpellErrorInfo getCurrentError()
          Returns the current error from the dictionary.
 boolean getDictionaryReady()
          Retrieves the ready state of the dictionary.
 boolean getForceUpperCase()
          Is this dictionary configured to return suggestions in UPPER CASE.
 boolean getIgnoreDoubleWords()
          Returns the ignoreDoubleWords variable.
 boolean getIgnoreFirstCaps()
          Return whether this dictionary accessor ignores capitalization errors on the first word.
 boolean getIgnoreIrregularCaps()
          Returns ignoreIrregularCaps variable.
 boolean getIgnoreUpper()
          Returns the ignoreUpper variable.
 boolean getIgnoreWordsWithNumbers()
          Returns the ignoreWordsWithNumbers variable.
 boolean getLearnWords()
          Can words be added to the dictionary?
 JSpellErrorInfo getNextError()
          Retrieves the next error from the dictionary.
 void ignoreWord(java.lang.String word)
          Add a word to the list of words to ignore/not check.
protected  void init()
          Initializes the JSpellDictionary object by creating the HashMaps, Vectors and other internal structures used by the JSpellDictionary object.
 void learnWord(java.lang.String word)
          Add a new word to the dictionary.
 void learnWordManual(java.lang.String word)
          Add a word to the internal dictionary but don't persist it to local storage or a network dictionary.
 void resetAll()
          Resets the state of the dictionary.
 void resetErrors()
          Resets any pending errors.
 void setBatchSize(int batchSize)
          Set the number of words to validate in one call to the dictionary access interface.
protected  void setDictionaryReady(boolean newValue)
          Sets the ready state of the dictionary.
 void setForceUpperCase(boolean forceUpperCase)
          When true, causes all suggestions to be in UPPER CASE.
 void setIgnoreDoubleWords(boolean ignoreDoubleWords)
          Sets the ignoreDoubleWords variable.
 void setIgnoreFirstCaps(boolean ignoreFirstCaps)
          Ignore irregular capitalization on the first word.
 void setIgnoreIrregularCaps(boolean ignoreIrregularCaps)
          When false, JSpell will flag an error if a word is at the beginning of a sentence but is not capitalized.
 void setIgnoreUpper(boolean ignoreUpper)
          Sets the ignoreUpper variable.
 void setIgnoreWordsWithNumbers(boolean ignoreWordsWithNumbers)
          Sets the ignoreWordsWithNumbers variable.
 void setLearnWords(boolean learnWords)
          Can words be added to the dictionary.
 void setMaxSuggestions(int count)
          Sets the maximum number of suggestions that the spell checker engine should return.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.wallstreetwise.app.jspell.domain.JSpellDictionaryAccessor
close, open
 

Field Detail

validWords

protected java.util.HashMap validWords
A HashMap of all the validWords that have been accessed by the JSpell spell checker routines. For example, valid suggestions are added to this list as well as words learned by the user.


ignoreWords

protected java.util.HashMap ignoreWords
A HashMap of words to ignore. This is built dynamically by the user when the user selects 'Ignore All' from the GUI.


nextWord

protected java.lang.String nextWord
This variable determines the number of words to send to the server in one spell check request.


batchSize

protected int batchSize
This variable determines the number of words to send to the server in a single 'batch'.


batchCount

protected int batchCount
This variable is used internally.


suggestions

protected Suggestions suggestions
The suggestions for the incorrect word.


maxSuggestions

protected int maxSuggestions
The maximum number of suggestions to return.


currentError

protected JSpellErrorInfo currentError
The current error being processed.


ignoreIrregularCaps

protected boolean ignoreIrregularCaps
When false, JSpell will flag an error if a word is at the beginning of a sentence but is not capitalized.


dictionaryReady

protected boolean dictionaryReady
Was the dictionary opened successfully and can it be searched?


learnWords

protected boolean learnWords
If true, the user (local or server) may permanently add words to the dictionary.


forceUpperCase

protected boolean forceUpperCase
When true, all suggestions returned by the spell checker will be in UPPER CASE. Likewise, if a lower case word is being spell checked, even if it is correct, an UPPER CASE suggestion will be returned.


ignoreFirstCaps

protected boolean ignoreFirstCaps
If false and the first character in a field being spell checked is not capitalized then JSpell will flag an error.


ignoreUpper

protected boolean ignoreUpper
If true, JSpell will not attempt to spell check words that are in all UPPER CASE.


ignoreDoubleWords

protected boolean ignoreDoubleWords
When true, JSpell will not flag an error if a word is repeated.


ignoreWordsWithNumbers

protected boolean ignoreWordsWithNumbers
When true, JSpell will ignore any words containing numbers and will not attempt to spell check them. If false, the word will be spell checked and any numbers will be treated as vowels for comparison purposes.


errors

protected java.util.Vector errors
A Vector containing the errors returned by the spell checker.


errorCache

protected java.util.HashMap errorCache
A HashMap containing the errors waiting to be processed.

Constructor Detail

JSpellDictionary

public JSpellDictionary()
Constructs a JSpellDictionary object. Because this is an abstract class this constructor can not be called directly, however, it is used by this classes subclasses.

Method Detail

init

protected void init()
Initializes the JSpellDictionary object by creating the HashMaps, Vectors and other internal structures used by the JSpellDictionary object.


setDictionaryReady

protected void setDictionaryReady(boolean newValue)
Sets the ready state of the dictionary.

Parameters:
newValue - Is dictionary ready?

getDictionaryReady

public boolean getDictionaryReady()
Retrieves the ready state of the dictionary.

Specified by:
getDictionaryReady in interface JSpellDictionaryAccessor
Returns:
Is dictionary ready?

setForceUpperCase

public void setForceUpperCase(boolean forceUpperCase)
When true, causes all suggestions to be in UPPER CASE.

Specified by:
setForceUpperCase in interface JSpellDictionaryAccessor
Parameters:
forceUpperCase - true or false

getForceUpperCase

public boolean getForceUpperCase()
Is this dictionary configured to return suggestions in UPPER CASE.

Specified by:
getForceUpperCase in interface JSpellDictionaryAccessor
Returns:
true or false

setLearnWords

public void setLearnWords(boolean learnWords)
Can words be added to the dictionary.

Parameters:
learnWords - true or false

getLearnWords

public boolean getLearnWords()
Can words be added to the dictionary?

Specified by:
getLearnWords in interface JSpellDictionaryAccessor
Returns:
true or false

getBatchSize

public int getBatchSize()
Get the number of words that can be validated by this access interface before getting errors back

Specified by:
getBatchSize in interface JSpellDictionaryAccessor
Returns:
number of words

setIgnoreIrregularCaps

public void setIgnoreIrregularCaps(boolean ignoreIrregularCaps)
When false, JSpell will flag an error if a word is at the beginning of a sentence but is not capitalized.

Specified by:
setIgnoreIrregularCaps in interface JSpellDictionaryAccessor
Parameters:
ignoreIrregularCaps - true or false

getIgnoreIrregularCaps

public boolean getIgnoreIrregularCaps()
Returns ignoreIrregularCaps variable.

Specified by:
getIgnoreIrregularCaps in interface JSpellDictionaryAccessor
Returns:
true or false

setIgnoreFirstCaps

public void setIgnoreFirstCaps(boolean ignoreFirstCaps)
Ignore irregular capitalization on the first word.

Specified by:
setIgnoreFirstCaps in interface JSpellDictionaryAccessor
Parameters:
ignoreFirstCaps - true or false

getIgnoreFirstCaps

public boolean getIgnoreFirstCaps()
Return whether this dictionary accessor ignores capitalization errors on the first word.

Specified by:
getIgnoreFirstCaps in interface JSpellDictionaryAccessor
Returns:
true or false

setIgnoreUpper

public void setIgnoreUpper(boolean ignoreUpper)
Sets the ignoreUpper variable. If true, JSpell ignores words in UPPER CASE when performing a spell check.

Specified by:
setIgnoreUpper in interface JSpellDictionaryAccessor
Parameters:
ignoreUpper - true or false

getIgnoreUpper

public boolean getIgnoreUpper()
Returns the ignoreUpper variable. If true, JSpell ignores words in UPPER CASE when performing a spell check.

Specified by:
getIgnoreUpper in interface JSpellDictionaryAccessor
Returns:
true or false

setIgnoreDoubleWords

public void setIgnoreDoubleWords(boolean ignoreDoubleWords)
Sets the ignoreDoubleWords variable. If true, JSpell will NOT flag an error when a word is repeated.

Specified by:
setIgnoreDoubleWords in interface JSpellDictionaryAccessor
Parameters:
ignoreDoubleWords - true or false

getIgnoreDoubleWords

public boolean getIgnoreDoubleWords()
Returns the ignoreDoubleWords variable.

Specified by:
getIgnoreDoubleWords in interface JSpellDictionaryAccessor
Returns:
true or false

setIgnoreWordsWithNumbers

public void setIgnoreWordsWithNumbers(boolean ignoreWordsWithNumbers)
Sets the ignoreWordsWithNumbers variable. If true, JSpell will not attempt to spell check words having embedded numbers. If false, JSpell will attempt to spell check these words and will treat the numbers as vowels for the purpose of spell checking.

Specified by:
setIgnoreWordsWithNumbers in interface JSpellDictionaryAccessor
Parameters:
ignoreWordsWithNumbers - true or false

getIgnoreWordsWithNumbers

public boolean getIgnoreWordsWithNumbers()
Returns the ignoreWordsWithNumbers variable.

Specified by:
getIgnoreWordsWithNumbers in interface JSpellDictionaryAccessor
Returns:
true or false

setMaxSuggestions

public void setMaxSuggestions(int count)
Sets the maximum number of suggestions that the spell checker engine should return.

Parameters:
count - number of suggestions

setBatchSize

public void setBatchSize(int batchSize)
Set the number of words to validate in one call to the dictionary access interface. Increasing this number improves efficiency of spell checking, however, increasing it too much delays feedback to the user in the form of misspelled words.

Specified by:
setBatchSize in interface JSpellDictionaryAccessor
Parameters:
batchSize - number of words for each batch

learnWord

public void learnWord(java.lang.String word)
Add a new word to the dictionary. This method ignores learnWords boolean since user can keep words in their own private local dictionary Vector which is refreshed the next time a spell check is performed, however, subclasses should respect the value of learnWords to prevent addition of words to the master dictionary.

Specified by:
learnWord in interface JSpellDictionaryAccessor
Parameters:
word - A string containing an individual word.

learnWordManual

public void learnWordManual(java.lang.String word)
Add a word to the internal dictionary but don't persist it to local storage or a network dictionary.

Specified by:
learnWordManual in interface JSpellDictionaryAccessor
Parameters:
word - A string containing an individual word.

ignoreWord

public void ignoreWord(java.lang.String word)
Add a word to the list of words to ignore/not check.

Specified by:
ignoreWord in interface JSpellDictionaryAccessor
Parameters:
word - A string containing an individual word.

resetAll

public void resetAll()
Resets the state of the dictionary. Similar to the init() method but keeps the dictionary open and searchable.

Specified by:
resetAll in interface JSpellDictionaryAccessor

resetErrors

public void resetErrors()
Resets any pending errors.

Specified by:
resetErrors in interface JSpellDictionaryAccessor

adjustErrorPositions

public void adjustErrorPositions(int offset)
Used to adjust the internal position references of the errors returned by the spell checker. This is often used when a word is replaced by a longer or shorter word.

Specified by:
adjustErrorPositions in interface JSpellDictionaryAccessor
Parameters:
offset - The number of characters by which to adjust the remaining errors.

getNextError

public JSpellErrorInfo getNextError()
                             throws java.lang.Exception
Retrieves the next error from the dictionary.

Specified by:
getNextError in interface JSpellDictionaryAccessor
Returns:
A JSpellErrorInfo object.
Throws:
java.lang.Exception - The exception that occurred during processing.

getCurrentError

public JSpellErrorInfo getCurrentError()
Returns the current error from the dictionary.

Specified by:
getCurrentError in interface JSpellDictionaryAccessor
Returns:
A JSpellErrorInfo object referencing the current error.

checkWord

public boolean checkWord(JSpellWordBundle word)
                  throws java.lang.Exception
Sends words to be checked by the dictionary. Returning true or false indicates whether the checker should continue checking words, not whether the word is valid or not.

Specified by:
checkWord in interface JSpellDictionaryAccessor
Parameters:
word - A String containing an individual word.
Returns:
true or false
Throws:
java.lang.Exception - The Exception object when an error occurs.

addFrequentWords

protected final void addFrequentWords()
Loads validWords HashMap with frequently used words in the English language.


checkCaps

public boolean checkCaps(char curChar,
                         char prevChar)
This method determines if JSpell is at the end of a sentence.

Specified by:
checkCaps in interface JSpellDictionaryAccessor
Parameters:
curChar - The current character.
prevChar - The previous character.
Returns:
true or false

checkCaps

public boolean checkCaps(char curChar,
                         char prevChar,
                         boolean hasDigits,
                         boolean capsFlag)
This method determines if JSpell is at the end of a sentence.

Specified by:
checkCaps in interface JSpellDictionaryAccessor
Parameters:
curChar - The current character.
prevChar - The previous character.
hasDigits - Word contains digits.
capsFlag - Is caps checking enabled?
Returns:
true or false


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