com.cfdev.activspell2.SpellChecker - Object Reference

Properties

Property

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

setEnglishPhoneticComparator

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.

charlimit

getCharLimit
setCharLimit

integer

none
default:24000

Gets or sets the maximum number of characters allowed. If the limit is exceeded, an error message is returned.

format

checkSpelling

text

javascript or wddx

Returns either a set of Java Script arrays of mispelled words, or output in WDDX XML Format. 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.
getCharLimit() Returns the character limit as an integer.
setCharLimit(int charlimit) Sets the character limit for the spelling session.
addLexicon(String tlx, String clx) Adds a dictionary to the spelling session.

An example instantiating a SpellChecker object:

<%
    // Define some variables used in the object instantiation

    // jsoutput is the variable that will hold the results returned by the object
    String jsoutput="";

    // spellCheckContent is a word or string passed to the page through the url or a form variable
    String spellCheckContent="";
    if(request.getParameter("spellCheckContent")!=null)
    spellCheckContent=request.getParameter("spellCheckContent");
%>

<%
 com.cfdev.activspell2.SpellChecker sc = new com.cfdev.activspell2.SpellChecker();
 sc.init(userdict, tlx, clx);
 sc.setEnglishPhoneticComparator(englishphonetic);
 sc.setSearchDepth(searchdepth);
 sc.setNumSuggestions(suggestions);
 jsoutput = sc.checkSpelling(spellCheckContent, format, striphtml);
%>

Most properties are stored in application variables or in an include file as with the default front-end, 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.

The addLexicon() method can be used to extend a language or create multilingual spelling sessions. It must be called after init().

<%
 com.cfdev.activspell2.SpellChecker sc = new com.cfdev.activspell2.SpellChecker();
 sc.init(userdict, tlx, clx);
 sc.setEnglishPhoneticComparator(englishphonetic);
 sc.setSearchDepth(searchdepth);
 sc.setNumSuggestions(suggestions);
 sc.addLexicon(medTLX, medCLX);
 jsoutput = sc.checkSpelling(spellCheckContent, format, striphtml);
%>

See addword.jsp, spell.jsp and suggest.jsp for example object useage in the supplied front-end.