|
RapidSpell Desktop |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.keyoti.rapidSpell.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 int |
HASHING_SUGGESTIONS
Indicator for suggestion method (Hashing is default). |
java.util.Vector |
ignoreList
Vector of words to be ignored. |
boolean |
optimizeForMemory
Whether to optimize suggestion finding for memory instead of speed. |
static int |
PHONETIC_SUGGESTIONS
Indicator for suggestion method (Hashing is default). |
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(). |
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 . |
boolean |
flagged(java.lang.String word)
Checks if word has been flagged as mis-spelt 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 |
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 |
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)
Passes a Dict file as a stream, to be used for the main dictionary. |
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. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public java.util.Vector ignoreList
public boolean optimizeForMemory
public int currentBadWordEnd
public int currentBadWordStart
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)
public int getMaximumAnagramLength()
public boolean getCheckCompoundWords()
public void setCheckCompoundWords(boolean value)
public boolean getWarnDuplicates()
public void setWarnDuplicates(boolean value)
public boolean getSuggestSplitWords()
public void setSuggestSplitWords(boolean value)
public void setSuggestionsMethod(int method)
public int getSuggestionsMethod()
public void setIncludeUserDictionaryInSuggestions(boolean v)
public boolean getIncludeUserDictionaryInSuggestions()
public void setIgnoreCapitalizedWords(boolean v)
public boolean getIgnoreCapitalizedWords()
public void setConsiderationRange(int w)
Default is 80.
public int getConsiderationRange()
public void setSeparateHyphenWords(boolean f)
Also see LookIntoHyphenatedText.
public boolean getSeparateHyphenWords()
Also see LookIntoHyphenatedText.
public boolean getAllowMixedCase()
public void setAllowMixedCase(boolean value)
public boolean getAllowAnyCase()
public void setAllowAnyCase(boolean value)
public java.lang.String getDictFilePath()
public void setDictFilePath(java.lang.String value)
public void setDictFileStream(java.io.InputStream dictFileStream) throws java.io.IOException, java.lang.IllegalStateException
check
is called, and the stream position must be at beginning of Dict filepublic boolean getLookIntoHyphenatedText()
public void setLookIntoHyphenatedText(boolean value)
public boolean getIgnoreWordsWithDigits()
public void setIgnoreWordsWithDigits(boolean value)
public boolean getIgnoreXML()
public void setIgnoreXML(boolean value)
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.
LanguageType
public void setLanguageParser(int language)
Eg. If the dictionary is set to French, you should use the French parser.
LanguageType
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 inpublic boolean addWord(java.lang.String word) throws java.lang.NullPointerException
word
to the user dictionary (if it has been specified).public void changeBadWord(java.lang.String newWord) throws NoCurrentBadWordException, java.lang.NullPointerException
newWord
in the textnewWord
- replaces the current misspelt word.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 frompublic void check(java.lang.String text) throws java.lang.NullPointerException
text
- to spell check.public java.util.Vector findSuggestions() throws NoCurrentBadWordException
public java.util.Vector findSuggestions(java.lang.String word) throws java.lang.NullPointerException
word
.word
is null.public java.lang.String getAmendedText()
public void ignoreAll(java.lang.String word) throws java.lang.NullPointerException
word
to be ignored in rest of the textword
- to ignorepublic boolean lookUp(java.lang.String query) throws java.lang.NullPointerException
query
- the word to check spelling ofpublic BadWord nextBadWord()
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.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()
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
userDictionary
- a file to be used as a user dictionarypublic 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
userDictionary
- a UserDictionary object representing a user dictionarypublic void setSharedDictionary(boolean useSharedDictionary)
public boolean getSharedDictionary()
public void dispose()
public boolean flagged(java.lang.String word)
public java.lang.String getNextWord()
protected boolean lookUpMainDictionary(java.lang.String query)
query
- the word to check spelling ofprotected boolean lookUpUserDictionary(java.lang.String query)
|
RapidSpell Desktop |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |