com.jspell.domain
Class JSpellParser

java.lang.Object
  extended by com.jspell.domain.JSpellParser

public class JSpellParser
extends java.lang.Object

This class is constructed with a JSpellDictionaryAccessor supplied by the caller of the constructor. The caller of this class may then pass strings of text to be parsed and validated by the JSpellDictionaryAccessor. The responsibility of this class is to tokenize text to be passed to the JSpellDictionaryAccessor. It should not have any language dependencies.


Constructor Summary
JSpellParser()
          Construct the JSpellParser object.
JSpellParser(JSpellDictionaryAccessor dictionary)
          Construct parser using given JSpellDictionaryAccessor object.
JSpellParser(JSpellDictionaryAccessor dictionary, java.lang.String textString)
          Construct parser with the given JSpellDictionaryAccessor and set the text String to check.
 
Method Summary
 void addParserListener(ParserListener p)
          Register a listener to be notified when the parsing and spellcheck is completed.
 java.lang.StringBuffer autoCorrect()
          Returns automatically corrected text.
 void cancel()
          Set the canceled flag to interrupt the spell checker.
 boolean getCanceled()
          Return the boolean indicating whether the spell checking is about to stop.
 int getCurPos()
          Get the current character position in the text.
 JSpellDictionaryAccessor getDictionary()
          Return the JSpellDictionaryAccessor object currently being used by this JSpellParser.
 JSpellErrorInfo getError()
          Initiates validation of textToCheck and is also called repeatedly to get errors from the JSpellDictionaryAccessor.
 boolean getForceUpperCase()
          See JSpellDictionary class for method description.
 boolean getIgnoreDoubleWords()
          Return value of ignoreDoubleWords.
 boolean getIgnoreFirstCaps()
          Return value of ignoreFirstCaps.
 boolean getIgnoreIrregularCaps()
          Return value of ignoreIrregularCaps.
 boolean getIgnoreUpper()
          Return value of ignoreUpper.
 boolean getIgnoreWordsWithNumbers()
          Return value of ignoreWordsWithNumbers.
 boolean getLearnWords()
          Does the underlying dictionary support addition of new words.
 java.util.Vector getParserListeners()
          Return the Vector of ParserListeners.
 boolean getStopped()
          Return the state of the spell checker, ie, is it stopped?
 int getTextLength()
          Get the length of the text to check.
 java.lang.StringBuffer getTextStringBuffer()
          Get the text being checked as a StringBuffer.
 void ignoreWord(java.lang.String word)
          Add this word to the list of words to ignore in the dictionary accessor.
 void learnWord(JSpellErrorInfo errorInfo)
          Add this word to the dictionary.
 void notifyListeners()
          Notify the parser listeners that the parsing and spell check is complete.
 void replaceAll(JSpellErrorInfo errorInfo, java.lang.String repl)
          Replace all instances of 'orig' word with 'repl' word.
 void replaceSingle(JSpellErrorInfo errorInfo, java.lang.String repl)
          Replace single instance of 'orig' word with 'repl' word.
 void reset()
          Reset the pending errors.
 void resetAll()
          Reset the pending errors, alternate method.
 void setCurPos(int curPos)
          Set the current position in the text being checked.
 void setDictionary(JSpellDictionaryAccessor dictionary)
          Initialize the JSpellParser with the given JSpellDictionaryAccessor object.
 void setForceUpperCase(boolean forceUpperCase)
          See JSpellDictionary class for method description.
 void setIgnoreDoubleWords(boolean bValue)
          To not check duplicated words (such as 'the the'), set this value to true, otherwise, repeated words will be returned as an error by the parser.
 void setIgnoreFirstCaps(boolean bValue)
          To ignore irregular capitalization of the first word being checked, set this value to true, otherwise the first word being checked should be capitalized.
 void setIgnoreIrregularCaps(boolean bValue)
          To ignore irregular capitalization, set this value to true, otherwise, words that are irregularly capitalized will be flagged as errors.
 void setIgnoreUpper(boolean bValue)
          To not check words in all upper case, set this value to true, otherwise, words in upper case will be checked in the same manner as lowercase words.
 void setIgnoreWordsWithNumbers(boolean bValue)
          To not check words with embedded numbers, set this value to true, otherwise, words with embedded numbers will be checked in the same manner as other words.
 void setPauseNotif(boolean pauseNotif)
          Pause ParserListener notification.
 void setTextString(java.lang.String textString)
          Pass a string of text to check to the parser.
 void stopped()
          Stop the spell checker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSpellParser

public JSpellParser()
Construct the JSpellParser object. You must call setDictionary when constructing a JSpellParser using this constructor.


JSpellParser

public JSpellParser(JSpellDictionaryAccessor dictionary)
Construct parser using given JSpellDictionaryAccessor object.

Parameters:
dictionary - a JSpellDictionaryAccessor object.

JSpellParser

public JSpellParser(JSpellDictionaryAccessor dictionary,
                    java.lang.String textString)
Construct parser with the given JSpellDictionaryAccessor and set the text String to check.

Parameters:
dictionary - a JSpellDictionaryAccessor object.
textString - a String.
Method Detail

getForceUpperCase

public final boolean getForceUpperCase()
See JSpellDictionary class for method description.

Returns:
true or false

setForceUpperCase

public final void setForceUpperCase(boolean forceUpperCase)
See JSpellDictionary class for method description.

Parameters:
forceUpperCase - true or false

setDictionary

public final void setDictionary(JSpellDictionaryAccessor dictionary)
Initialize the JSpellParser with the given JSpellDictionaryAccessor object.

Parameters:
dictionary - a JSpellDictionaryAccessor object.

stopped

public void stopped()
Stop the spell checker. Notify any ParserListeners.


getStopped

public boolean getStopped()
Return the state of the spell checker, ie, is it stopped?

Returns:
true or false

getDictionary

public final JSpellDictionaryAccessor getDictionary()
Return the JSpellDictionaryAccessor object currently being used by this JSpellParser.

Returns:
a JSpellDictionaryAccessor object.

setTextString

public final void setTextString(java.lang.String textString)
Pass a string of text to check to the parser. After construction, this is the first step in the word validation process. The next step is to call getError() repeatedly until it is null.

Parameters:
textString - a String.

addParserListener

public final void addParserListener(ParserListener p)
Register a listener to be notified when the parsing and spellcheck is completed.

Parameters:
p - a ParserListener.

autoCorrect

public final java.lang.StringBuffer autoCorrect()
                                         throws java.lang.Exception
Returns automatically corrected text. The text corrections will use the first suggested replacement word when a replacement word is suggested. Duplicate words will be removed automatically. This method will respect the settings of the JSpellDictionary that was used to initialize the JSpellParser which control ignoring capitalized words, first caps, repeated words, etc.

Returns:
a JSpellErrorInfo object.
Throws:
java.lang.Exception - an Exception object.

getError

public final JSpellErrorInfo getError()
                               throws java.lang.Exception
Initiates validation of textToCheck and is also called repeatedly to get errors from the JSpellDictionaryAccessor. Sends up to batchSize words to the JSpellDictionaryAccessor before returning.

Returns:
a JSpellErrorInfo object.
Throws:
java.lang.Exception - an Exception object.

getParserListeners

public java.util.Vector getParserListeners()
Return the Vector of ParserListeners.

Returns:
a Vector.

notifyListeners

public final void notifyListeners()
Notify the parser listeners that the parsing and spell check is complete.


cancel

public final void cancel()
Set the canceled flag to interrupt the spell checker.


getCanceled

public final boolean getCanceled()
Return the boolean indicating whether the spell checking is about to stop.

Returns:
true or false

reset

public final void reset()
Reset the pending errors.


resetAll

public final void resetAll()
Reset the pending errors, alternate method.


learnWord

public final void learnWord(JSpellErrorInfo errorInfo)
Add this word to the dictionary.

Parameters:
errorInfo - a JSpellErrorInfo object.

getLearnWords

public final boolean getLearnWords()
Does the underlying dictionary support addition of new words.

Returns:
true or false

ignoreWord

public final void ignoreWord(java.lang.String word)
Add this word to the list of words to ignore in the dictionary accessor.

Parameters:
word - a String.

replaceSingle

public final void replaceSingle(JSpellErrorInfo errorInfo,
                                java.lang.String repl)
Replace single instance of 'orig' word with 'repl' word.

Parameters:
errorInfo - a JSpellErrorInfo object representing the word to replace.
repl - a String representing the replacement word.

replaceAll

public final void replaceAll(JSpellErrorInfo errorInfo,
                             java.lang.String repl)
Replace all instances of 'orig' word with 'repl' word.

Parameters:
errorInfo - A JSpellErrorInfo object representing the word to replace.
repl - a String representing the replacement word.

getCurPos

public final int getCurPos()
Get the current character position in the text.

Returns:
an int.

setCurPos

public final void setCurPos(int curPos)
Set the current position in the text being checked.

Parameters:
curPos - an int.

getTextLength

public final int getTextLength()
Get the length of the text to check.

Returns:
an int.

getTextStringBuffer

public final java.lang.StringBuffer getTextStringBuffer()
Get the text being checked as a StringBuffer.

Returns:
a StringBuffer.

setIgnoreIrregularCaps

public final void setIgnoreIrregularCaps(boolean bValue)
To ignore irregular capitalization, set this value to true, otherwise, words that are irregularly capitalized will be flagged as errors. The default is false, always check for proper capitalization. The capitalization rules are as follows: A word should be capitalized if it appears after a period, question mark, or exclamation point. A word should be capitalized if it appears after a quotation mark when the immediate preceding character is a period. The default is false, do not ignore capitalization rules.

Parameters:
bValue - true or false

setIgnoreWordsWithNumbers

public final void setIgnoreWordsWithNumbers(boolean bValue)
To not check words with embedded numbers, set this value to true, otherwise, words with embedded numbers will be checked in the same manner as other words. The default is false, check words with numbers.

Parameters:
bValue - true or false

setIgnoreDoubleWords

public final void setIgnoreDoubleWords(boolean bValue)
To not check duplicated words (such as 'the the'), set this value to true, otherwise, repeated words will be returned as an error by the parser. The default is false, return duplicated words as an error.

Parameters:
bValue - true or false

setIgnoreFirstCaps

public final void setIgnoreFirstCaps(boolean bValue)
To ignore irregular capitalization of the first word being checked, set this value to true, otherwise the first word being checked should be capitalized. The default value is false, do not ignore first word capitalization.

Parameters:
bValue - true or false

setIgnoreUpper

public final void setIgnoreUpper(boolean bValue)
To not check words in all upper case, set this value to true, otherwise, words in upper case will be checked in the same manner as lowercase words. The default is true, ignore words in upper case.

Parameters:
bValue - true or false

getIgnoreIrregularCaps

public final boolean getIgnoreIrregularCaps()
Return value of ignoreIrregularCaps.

Returns:
true or false

getIgnoreWordsWithNumbers

public final boolean getIgnoreWordsWithNumbers()
Return value of ignoreWordsWithNumbers.

Returns:
true or false

getIgnoreDoubleWords

public final boolean getIgnoreDoubleWords()
Return value of ignoreDoubleWords.

Returns:
true or false.

getIgnoreFirstCaps

public final boolean getIgnoreFirstCaps()
Return value of ignoreFirstCaps.

Returns:
true or false.

getIgnoreUpper

public final boolean getIgnoreUpper()
Return value of ignoreUpper.

Returns:
true or false.

setPauseNotif

public final void setPauseNotif(boolean pauseNotif)
Pause ParserListener notification. This is necessary when spell checking multiple text fields.

Parameters:
pauseNotif - true or false.


JSpell SDK - Spell Checker for the Java ™ Platform
Copyright © 2009 Page Scholar Inc, All Rights Reserved - http://www.jspell.com