|
RapidSpell Web |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.keyoti.rapidSpell.RapidSpellChecker
public class RapidSpellChecker
Checks a text string for spelling errors and makes suggested corrections.
This is a non-GUI bean component, suitable for the business/logic layer of your application.
You would use this component in web server based applications.
This component can be used in 2 different ways. The most common usage, in an iterative fashion is detailed below, but it may also be used on a query by query basis.
To use this component in an iterative way you must first call check(text)
to set the text to check and
then iterate through
nextBadWord()
to identify misspelt words. nextBadWord()
will return
a BadWord object and internally locate the
the misspelt word in the text, then you can call findSuggestions()
which will return a Vector of suggestions as String objects. You may also call changeBadWord(replacement)
to replace that current misspelt word in the text.
nextBadWord()
will return null when the text has been checked. getAmendedText()
returns the current
state of the text with corrections.
Calling changeBadWord(replacement)
or findSuggestions()
before nextBadWord()
has been called
and returned a BadWord (i.e. not null) will result in a
NoCurrentBadWordException
Example 1.
RapidSpellChecker c = new RapidSpellChecker();
BadWord badWord;
Enumeration suggestions;
//check some text.
c.check("This is sume text.");
//iterate through all bad words in the text.
while((badWord = c.nextBadWord())!=null){
System.out.println(badWord.getWord() + "- is not spelt correctly. Suggestions:");
try{
//get suggestions for the current bad word.
suggestions = c.findSuggestions().elements();
//display all suggestions.
while(suggestions.hasMoreElements()) {
System.out.println(suggestions.nextElement());
}
//change the bad word in the text with "replacement".
c.changeBadWord("replacement");
} catch (NoCurrentBadWordException e){
System.err.println(e);
}
}
System.out.println(c.getAmendedText());
The second way to use this component is simply to query words yourself using lookUp(word)
to check if word
is in the lexicon/dictionary and findSuggestions(word)
to find spelling suggestions for word
.
Field Summary | |
---|---|
int |
currentBadWordEnd
The start and end position of the current bad word being inspected |
int |
currentBadWordStart
The start and end position of the current word being inspected |
protected java.lang.String[] |
dontSuggest
Dont suggest words in this array (swear words). |
static boolean |
findLowercaseSuggestions
|
static int |
HASHING_SUGGESTIONS
Indicator for suggestion method (Hashing is default). |
java.util.Vector |
ignoreList
Vector of words to be ignored. |
static int |
OPTIMIZE_FOR_MEMORY
Indicator for optimization (OPTIMIZE_FOR_SPEED only works with PHONETIC_SUGGESTIONS method). |
static int |
OPTIMIZE_FOR_SPEED
Indicator for optimization (OPTIMIZE_FOR_SPEED only works with PHONETIC_SUGGESTIONS method). |
boolean |
optimizeForMemory
Whether to optimize suggestion finding for memory instead of speed. |
static int |
PHONETIC_SUGGESTIONS
Indicator for suggestion method (Hashing is default). |
protected java.lang.String |
previousWord
|
UserDictionary |
userDictionary
The UserDictionary being used. |
Constructor Summary | |
---|---|
RapidSpellChecker()
Creates a RapidSpellChecker, with no user dictionary. |
|
RapidSpellChecker(java.lang.String licenseKey)
Creates a RapidSpellChecker, with no user dictionary. |
Method Summary | |
---|---|
boolean |
addWord(java.lang.String word)
Adds word to the user dictionary (if it has been specified). |
void |
changeBadWord(java.lang.String newWord)
Changes the current bad word to newWord in the text |
void |
check(java.lang.String text)
Checks text for spelling correctness, from beginning of text, mis-spelt words can be accessed through nextBadWord() |
void |
check(java.lang.String text,
int startPosition)
Checks text for spelling correctness, from startPosition in text, mis-spelt words can be accessed through nextBadWord(). |
static java.lang.String |
convertHtmlEntities(java.lang.String text)
|
void |
dispose()
Frees up resources. |
void |
findAnagrams(java.lang.String word,
java.util.List anagrams)
Finds anagrams of |
boolean |
findCompoundWords(java.lang.String text,
java.util.List subwords)
Finds the compound words in |
java.util.Vector |
findSuggestions()
Gets an enumeration of String suggestions for spelling of current bad word. |
java.util.Vector |
findSuggestions(java.lang.String word)
Gets an enumeration of String suggestions for spelling of word . |
protected java.util.Vector |
findSuggestions(java.lang.String word,
boolean searchLowerCase)
|
boolean |
flagged(java.lang.String word)
Checks if word has been flagged as misspelt by the check() method |
boolean |
getAllowAnyCase()
Whether to allow words spelt with incorrect case, eg. |
boolean |
getAllowMixedCase()
Whether to allow words spelt with mixed case, eg. |
java.lang.String |
getAmendedText()
Returns the original text sent to check() but with any alterations made through change() |
boolean |
getCheckCompoundWords()
Whether to check if words are made of compound forms - to be used in languages which use compounds, such as German. |
int |
getConsiderationRange()
Gets the factor for words to consider for suggestions. |
java.lang.String |
getDictFilePath()
The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used. |
boolean |
getFindCapitalizedSuggestions()
Whether to look for capitalized suggestions. |
boolean |
getIgnoreCapitalizedWords()
Gets whether to ignore words that start with capital letters. |
boolean |
getIgnoreWordsWithDigits()
Whether to ignore words with digits in them. |
boolean |
getIgnoreXML()
Whether to ignore XML/HTML tags, should be set true for 'rich HTML text box' support, false by default. |
boolean |
getIncludeUserDictionaryInSuggestions()
Gets whether the user dictionary should be used in finding suggestions for misspelt words. |
int |
getLanguageParser()
Gets the type of language parsing to use. |
boolean |
getLookIntoHyphenatedText()
Whether to 'look into' text with hyphens (-), if the word has hyphens in it and LookIntoHyphenatedText is set true (default), the parts of the text around the hyphens will be checked individually. |
int |
getMaximumAnagramLength()
Gets the longest word length to find anagrams for. |
java.lang.String |
getNextWord()
Returns the next word in the text. |
int |
getOptimization()
Gets the optimization method to use. |
boolean |
getSeparateHyphenWords()
Gets whether to treat hyphenated (-) words as separate words, default is false. |
boolean |
getSharedDictionary()
Whether to use one shared dictionary amongst all RapidSpell instances under this VM. |
int |
getSuggestionsMethod()
Gets the suggestions method to use. |
boolean |
getSuggestSplitWords()
Whether to check for joined words when looking for suggestions. |
UserDictionary |
getUserDictionary()
Gets the user dictionary to use. |
boolean |
getWarnDuplicates()
Whether to treat duplicate words as errors (eg. |
int |
getWordEnd()
Gets the current word's end index in the text |
AdvancedTextBoundary |
getWordIterator()
The word iterator used to break strings into words. |
int |
getWordStart()
Gets the current word's start index in the text |
void |
ignoreAll(java.lang.String word)
Marks word to be ignored in rest of the text |
boolean |
lookUp(java.lang.String query)
Checks if query is in the word dictionary. |
protected boolean |
lookUpMainDictionary(java.lang.String query)
Checks if query is in the word dictionary - returns true if doesnt start with a letter of apostrophe |
protected boolean |
lookUpUserDictionary(java.lang.String query)
Look up the query in the user dictionary if it exists |
BadWord |
nextBadWord()
Returns the next mis-spelt word in the text, as a BadWord object. |
static void |
nullSharedDictionary()
This will null the shared dictionary, allowing it to be GC'ed. |
void |
setAllowAnyCase(boolean value)
Whether to allow words spelt with incorrect case, eg. |
void |
setAllowMixedCase(boolean value)
Whether to allow words spelt with mixed case, eg. |
void |
setCheckCompoundWords(boolean value)
Whether to check if words are made of compound forms - to be used in languages which use compounds, such as German. |
void |
setConsiderationRange(int w)
Sets the factor for words to consider for suggestions, Should be O(100), lower values are faster but consider less words for suggestions. |
void |
setDictFilePath(java.lang.String value)
The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used. |
void |
setDictFileStream(java.io.InputStream dictFileStream,
java.lang.String dictionaryID)
Passes a Dict file as a stream, to be used for the main dictionary. |
void |
setFindCapitalizedSuggestions(boolean value)
Whether to look for capitalized suggestions. |
void |
setIgnoreCapitalizedWords(boolean v)
Sets whether to ignore words that start with capital letters. |
void |
setIgnoreWordsWithDigits(boolean value)
Whether to ignore words with digits in them. |
void |
setIgnoreXML(boolean value)
Whether to ignore XML/HTML tags, should be set true for 'rich HTML text box' support, false by default. |
void |
setIncludeUserDictionaryInSuggestions(boolean v)
Sets whether the user dictionary should be used in finding suggestions for misspelt words. |
void |
setLanguageParser(int language)
The type of language parsing to use. |
void |
setLookIntoHyphenatedText(boolean value)
Whether to 'look into' text with hyphens (-), if the word has hyphens in it and LookIntoHyphenatedText is set true (default), the parts of the text around the hyphens will be checked individually. |
void |
setMaximumAnagramLength(int maxAnagramLength)
Sets the longest word length to find anagrams for. |
void |
setOptimization(int indicator)
Sets the optimization method to use. |
void |
setPosition(int pos)
Sets the pointer position for the nextBadWord() iterator. |
void |
setSeparateHyphenWords(boolean f)
Sets whether to treat hyphenated (-) words as separate words, default is false. |
void |
setSharedDictionary(boolean useSharedDictionary)
Whether to use one shared dictionary amongst all RapidSpell instances under this VM. |
void |
setSuggestionsMethod(int method)
Sets the suggestions method to use. |
void |
setSuggestSplitWords(boolean value)
Whether to check for joined words when looking for suggestions. |
void |
setUserDictionary(java.io.File userDictionaryFile)
Sets the user dictionary to use. |
void |
setUserDictionary(UserDictionary userDictionary)
Sets the user dictionary to use. |
void |
setWarnDuplicates(boolean value)
Whether to treat duplicate words as errors (eg. |
void |
setWordIterator(AdvancedTextBoundary value)
The word iterator used to break strings into words. |
protected boolean |
wordHasDigits(java.lang.String w)
|
protected boolean |
wordIsDigits(java.lang.String w)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean findLowercaseSuggestions
public java.util.Vector ignoreList
public boolean optimizeForMemory
public int currentBadWordEnd
public int currentBadWordStart
protected java.lang.String previousWord
public static int OPTIMIZE_FOR_SPEED
public static int OPTIMIZE_FOR_MEMORY
public static int PHONETIC_SUGGESTIONS
public static int HASHING_SUGGESTIONS
protected java.lang.String[] dontSuggest
public UserDictionary userDictionary
Constructor Detail |
---|
public RapidSpellChecker()
public RapidSpellChecker(java.lang.String licenseKey)
Method Detail |
---|
public int getWordStart()
public int getWordEnd()
public static void nullSharedDictionary()
public void setMaximumAnagramLength(int maxAnagramLength)
setMaximumAnagramLength
in interface ICheckerEngine
public int getMaximumAnagramLength()
public AdvancedTextBoundary getWordIterator()
public void setWordIterator(AdvancedTextBoundary value)
public boolean getCheckCompoundWords()
getCheckCompoundWords
in interface ICheckerEngine
public void setCheckCompoundWords(boolean value)
setCheckCompoundWords
in interface ICheckerEngine
public boolean getWarnDuplicates()
getWarnDuplicates
in interface ICheckerEngine
public void setWarnDuplicates(boolean value)
setWarnDuplicates
in interface ICheckerEngine
public boolean getFindCapitalizedSuggestions()
public void setFindCapitalizedSuggestions(boolean value)
public boolean getSuggestSplitWords()
getSuggestSplitWords
in interface ICheckerEngine
public void setSuggestSplitWords(boolean value)
setSuggestSplitWords
in interface ICheckerEngine
public void setSuggestionsMethod(int method)
setSuggestionsMethod
in interface ICheckerEngine
public int getSuggestionsMethod()
getSuggestionsMethod
in interface ICheckerEngine
public void setIncludeUserDictionaryInSuggestions(boolean v)
setIncludeUserDictionaryInSuggestions
in interface ICheckerEngine
public boolean getIncludeUserDictionaryInSuggestions()
getIncludeUserDictionaryInSuggestions
in interface ICheckerEngine
public void setIgnoreCapitalizedWords(boolean v)
setIgnoreCapitalizedWords
in interface ICheckerEngine
public boolean getIgnoreCapitalizedWords()
getIgnoreCapitalizedWords
in interface ICheckerEngine
public void setConsiderationRange(int w)
Default is 80.
setConsiderationRange
in interface ICheckerEngine
public int getConsiderationRange()
getConsiderationRange
in interface ICheckerEngine
public void setSeparateHyphenWords(boolean f)
Also see LookIntoHyphenatedText.
setSeparateHyphenWords
in interface ICheckerEngine
public boolean getSeparateHyphenWords()
Also see LookIntoHyphenatedText.
public boolean getAllowMixedCase()
getAllowMixedCase
in interface ICheckerEngine
public void setAllowMixedCase(boolean value)
setAllowMixedCase
in interface ICheckerEngine
public boolean getAllowAnyCase()
getAllowAnyCase
in interface ICheckerEngine
public void setAllowAnyCase(boolean value)
setAllowAnyCase
in interface ICheckerEngine
public java.lang.String getDictFilePath()
getDictFilePath
in interface ICheckerEngine
public void setDictFilePath(java.lang.String value)
setDictFilePath
in interface ICheckerEngine
public void setDictFileStream(java.io.InputStream dictFileStream, java.lang.String dictionaryID) throws java.io.IOException, java.lang.IllegalStateException
check
is called, and the stream position must be at beginning of Dict file
java.lang.IllegalStateException
- if called after dictionary has been loaded.
java.io.IOException
public boolean getLookIntoHyphenatedText()
getLookIntoHyphenatedText
in interface ICheckerEngine
public void setLookIntoHyphenatedText(boolean value)
setLookIntoHyphenatedText
in interface ICheckerEngine
public boolean getIgnoreWordsWithDigits()
getIgnoreWordsWithDigits
in interface ICheckerEngine
public void setIgnoreWordsWithDigits(boolean value)
setIgnoreWordsWithDigits
in interface ICheckerEngine
public boolean getIgnoreXML()
getIgnoreXML
in interface ICheckerEngine
public void setIgnoreXML(boolean value)
setIgnoreXML
in interface ICheckerEngine
public void setOptimization(int indicator)
public int getOptimization()
public int getLanguageParser()
Eg. If the dictionary is set to French, you should use the French parser.
getLanguageParser
in interface ICheckerEngine
LanguageType
public void setLanguageParser(int language)
Eg. If the dictionary is set to French, you should use the French parser.
setLanguageParser
in interface ICheckerEngine
language
- an int identifier from LanguageTypeLanguageType
public boolean findCompoundWords(java.lang.String text, java.util.List subwords)
Eg. "catchmentarea" has words "catchment" and "area" but not "cat", "me" etc.
/* The order of the words in the list is the reverse of their order in
public boolean addWord(java.lang.String word) throws java.lang.NullPointerException
word
to the user dictionary (if it has been specified).
addWord
in interface ICheckerEngine
java.lang.NullPointerException
- if word parameter is null.public void changeBadWord(java.lang.String newWord) throws NoCurrentBadWordException, java.lang.NullPointerException
newWord
in the text
changeBadWord
in interface ICheckerEngine
newWord
- replaces the current misspelt word.
NoCurrentBadWordException
- if nextBadWord() hasn't been run first AND found an erroneous word.
java.lang.NullPointerException
- if newWord parameter is null.public void check(java.lang.String text, int startPosition) throws java.lang.NullPointerException
text
- the text to be checkedstartPosition
- the position in the text to begin checking from
java.lang.NullPointerException
- if text parameter is null.public void check(java.lang.String text) throws java.lang.NullPointerException
check
in interface ICheckerEngine
text
- to spell check.
java.lang.NullPointerException
- if text parameter is null.public java.util.Vector findSuggestions() throws NoCurrentBadWordException
findSuggestions
in interface ICheckerEngine
NoCurrentBadWordException
- if nextBadWord() hasn't been run first AND found an erroneous word.public java.util.Vector findSuggestions(java.lang.String word) throws java.lang.NullPointerException
word
.
java.lang.NullPointerException
- if word
is null.protected java.util.Vector findSuggestions(java.lang.String word, boolean searchLowerCase) throws java.lang.NullPointerException
java.lang.NullPointerException
public java.lang.String getAmendedText()
public static java.lang.String convertHtmlEntities(java.lang.String text)
public void ignoreAll(java.lang.String word) throws java.lang.NullPointerException
word
to be ignored in rest of the text
ignoreAll
in interface ICheckerEngine
word
- to ignore
java.lang.NullPointerException
- if word parameter is null.public boolean lookUp(java.lang.String query) throws java.lang.NullPointerException
query
- the word to check spelling of
java.lang.NullPointerException
- if query parameter is null.public BadWord nextBadWord()
nextBadWord
in interface ICheckerEngine
BadWord
public void setPosition(int pos)
pos
.
If position > the text length it is set to the text length.
If position < 0, it is set to zero.
setPosition
in interface ICheckerEngine
public void findAnagrams(java.lang.String word, java.util.List anagrams)
word
- The word to find anagrams ofanagram
- A list that anagrams will be added to.public UserDictionary getUserDictionary()
getUserDictionary
in interface ICheckerEngine
public void setUserDictionary(java.io.File userDictionaryFile) throws java.lang.NullPointerException
If the userDictionary can not be created/read it will be ignored and a message sent to System.err
setUserDictionary
in interface ICheckerEngine
userDictionary
- a file to be used as a user dictionary
java.lang.NullPointerException
- if userDictionaryFile is nullpublic void setUserDictionary(UserDictionary userDictionary) throws java.lang.NullPointerException
If the userDictionary can not be created/read it will be ignored and a message sent to System.err
setUserDictionary
in interface ICheckerEngine
userDictionary
- a UserDictionary object representing a user dictionary
java.lang.NullPointerException
- if userDictionary is null.public void setSharedDictionary(boolean useSharedDictionary)
public boolean getSharedDictionary()
public void dispose()
public boolean flagged(java.lang.String word)
protected boolean wordHasDigits(java.lang.String w)
protected boolean wordIsDigits(java.lang.String w)
public java.lang.String getNextWord()
protected boolean lookUpMainDictionary(java.lang.String query)
query
- the word to check spelling of
protected boolean lookUpUserDictionary(java.lang.String query)
|
RapidSpell Web |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |