
com.cfdev.activspell2.SpellChecker - Object Reference
Properties
|
Attribute |
Method |
Type |
State |
Description |
|
clx |
init |
text (path) |
REQUIRED |
Compressed Lexicon File, path to the file in the lex directory with the extension .clx. |
|
tlx |
init |
text (path) |
REQUIRED |
Text Lexicon File, path to the file in the lex directory with the extension .tlx. |
|
userdict |
init addWord |
text (path) |
REQUIRED |
User Dictionary File, path to the file which will contain a user defined dictionary. |
|
searchdepth |
setSearchDepth |
integer |
1 to 100 |
An integer specifing the search depth, this attribute has significant impact on the spell checkers response time. Default value is 50, high values conduct a more in depth search. |
|
englishphonetic |
setSearchDepth |
boolean |
default:false |
Should be set to true if you are using the English language. This option will use an English Phonetic Comparator for searches. This comparator searches by phonetics, which often produces better results, and a few tests show that it has a higher return time. |
|
format |
checkSpelling |
text |
javascript or wddx< /P> |
Returns either a set of Java Script arrays of mispelled words, or output in WDDX XML Format, WDDX can easily be read by ColdFusion Application Server. Default is JavaScript |
| suggestions | setNumSuggestions | integer | 1 to 100 | Sets the maximum number of suggestions that the spell checker will return. Default is 14. |
|
striphtml |
checkSpelling |
boolean |
default: true |
Removes all tags from the words input attribute. It will also remove anything inside <script>javascript</script> or <style>css</style> tags. |
| METHOD | DESCRIPTION |
| init(String userdic, String tlx, String clx) | Initializes the object, tells it what files represent the dictionary. |
| checkSpelling(String text, String format, boolean stripHTML) | Checks the spelling and returns the results in a format specified by format parameter. Valid values for format are javascript and wddx, see here for details. |
| addWord(String tlx, String word) | Adds a word to a text lexicon dictionary. |
| addLexicon(String tlx, String clx) | Adds a dictionary to the spelling session. |
An example instantiating a SpellChecker object:
<cfscript>
spellChecker = CreateObject("java", "com.cfdev.spelling.SpellChecker");
spellChecker.init(Request.userdict, Request.tlx, Request.clx);
spellChecker.setEnglishPhoneticComparator(Request.englishphonetic);
spellChecker.setSearchDepth(Request.searchdepth);
spellChecker.setNumSuggestions(Request.suggestions);
jsoutput = spellChecker.checkSpelling(spellCheckContent , "javascript", Request.striphtml);
</cfscript>
Most properties are stored in application variables, but could also be combined with session variables, for instance to create a unique user dictionary for each user in an application where the user dictionary exists as a file named as indicated.
<cfscript>
spellChecker = CreateObject("java", "com.cfdev.spelling.SpellChecker");
spellChecker.init(Session.userID & Request.userdict, Request.tlx, Request.clx);
jsoutput = spellChecker.checkSpelling(spellCheckContent , "javascript", Request.striphtml);
</cfscript>
The addLexicon() method can be used to extend a language or create multilingual spelling sessions. It must be called after init().
<cfscript>
spellChecker = CreateObject("java", "com.cfdev.spelling.SpellChecker");
spellChecker.init(Request.userdict, Request.tlx, Request.clx);
spellChecker.addLexicon(Request.medTLX, Request.medCLX);
jsoutput = spellChecker.checkSpelling(spellCheckContent , "javascript", Request.striphtml);
</cfscript>
See addword.cfm, spell.cfm and suggest.cfm for example object useage in the supplied front-end.