com.jspell.domain
Class JSpellDictionary

java.lang.Object
  extended by com.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 2009/04/01 03:27:31 cliff 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'.
static java.lang.String defaultCountry
          System default country.
static java.lang.String defaultLanguage
          System default language.
static java.lang.String defaultVersion
          Default version.
protected  java.util.Vector errors
          A Vector containing the errors returned by the spell checker.
protected  java.lang.String language
          Descriptive name of language, e.g.
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  Suggestions suggestions
          The suggestions for the incorrect word.
 
Constructor Summary
JSpellDictionary()
          Constructs a JSpellDictionary object.
 
Method Summary
 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.
 java.lang.String getDictionaryCountry()
          Returns the country of the dictionary.
 java.lang.String getDictionaryLanguage()
          Returns the language of the dictionary.
 boolean getDictionaryReady()
          Retrieves the ready state of the dictionary.
 java.lang.String getDictionaryVersion()
          Returns the version 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.
 java.lang.String getLanguage()
          Descriptive text name for language, e.g.
 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.
 boolean isValidWord(java.lang.String word)
          Check if a word is already valid.
 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 setLanguage(java.lang.String language)
          Descriptive text name for language, e.g.
 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.
 void validWordsPut(java.lang.String word)
          Add a to the in memory dictionary only, to save disk access when validating words.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.jspell.domain.JSpellDictionaryAccessor
close, open
 

Field Detail

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.


learnWords

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


errors

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


language

protected java.lang.String language
Descriptive name of language, e.g. English (US)


defaultLanguage

public static java.lang.String defaultLanguage
System default language.


defaultCountry

public static java.lang.String defaultCountry
System default country.


defaultVersion

public static java.lang.String defaultVersion
Default version.

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

setLanguage

public void setLanguage(java.lang.String language)
Descriptive text name for language, e.g. German (DE). Do not confuse with 'dictionaryLanguage' which is the ISO code.

Parameters:
language - a String.

getLanguage

public java.lang.String getLanguage()
Descriptive text name for language, e.g. German (DE). Do not confuse with 'dictionaryLanguage' which is the ISO code.

Returns:
a String.

getDictionaryLanguage

public final java.lang.String getDictionaryLanguage()
Returns the language of the dictionary.

Returns:
a String value representing the language.

getDictionaryCountry

public final java.lang.String getDictionaryCountry()
Returns the country of the dictionary.

Returns:
a String representing the country.

getDictionaryVersion

public final java.lang.String getDictionaryVersion()
Returns the version of the dictionary.

Returns:
a String representing the version.

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

validWordsPut

public void validWordsPut(java.lang.String word)
Add a to the in memory dictionary only, to save disk access when validating words.


isValidWord

public boolean isValidWord(java.lang.String word)
Check if a word is already valid. Wrapper method for JSpellDictionaryWords.


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.

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 - Spell Checker for the Java ™ Platform
Copyright © 2009 Page Scholar Inc, All Rights Reserved - http://www.jspell.com