Wintertree Software Inc.

Sentry Spelling Checker Engine for Java

Home Site index Contact us Catalog Shopping Cart Products Support Search

You are here: Home > Support > Sentry Spelling Checker Engine > Java SDK > Most/all words misspelled


Most or all words reported as misspelled

Product: Sentry Spelling Checker Engine Java SDK

Problem: Most or all words are reported as misspelled. The suggestions list is empty or nearly empty.

Description: Sentry is a lexicon or dictionary based spelling engine, which means it validates the spelling of words by checking that they exist in a dictionary of words known to be spelled correctly. The dictionary exists as a set of one or more files, which may be accessed directly or as resource streams. If the dictionary files cannot be opened, all words will be reported as misspelled and no suggestions will be offered. If only some of the dictionary files are opened, then many or most words will be reported as misspelled.

In the Java environment, many external factors can prevent files or resources from being accessed. For example, an unsigned Java applet is usually unable to open local files (see Using the Sentry Spelling Checker Engine in a Java applet for more details). The Sentry engine is simply Java code which is subject to the same constraints as any other Java code. The Sentry engine uses standard packages such as java.io to access dictionaries. It doesn't have any special powers or do anything tricky, undocumented, or "behind the scenes" which enables it to access otherwise inaccessible files or resources. If code you write can't open a certain file or access a certain resource stream, the Sentry engine will not be able to, either.

Virtually all issues with opening dictionaries stem from external or configuration factors:

The key to solving problems with dictionary access is to diagnose the cause of the problem. Unfortunately this isn't always easy. Information in this document may help.

Starting with version 5.9, the PropSpellingSession class in Sentry engine logs any failed attempts to open dictionaries to System.err. The System.err log may contain information that helps to explain why a dictionary could not be accessed.

The following list shows the standard Java classes and methods used internally for dictionary access in the Sentry engine:

One way to diagnose dictionary access problems is to insert test code into your application which attempts to open or access a dictionary file or resource in the same way as the Sentry engine (as listed above). For example, if you use PropSpellingSession to access "/ssceam2.clx" using a definition such as the following:

MainLexicon2=/ssceam2.clx,resource,c

then insert Java code similar to the following near the place in your code where PropSpellingSession is constructed:

InputStream is = getClass().getResourceAsStream("/ssceam2.clx");
if (null == is) throw new Exception("/ssceam2.clx not found");
CompressedLexicon lex = new CompressedLexicon(is);

Any exceptions raised can be caught and may help you to determine the reason PropSpellingSession was unable to access "/ssceam2.clx".

Note that when the "resource" access method is specified in the Properties object passed to PropSpellingSession, the PropSpellingSession class uses getClass().getResourceAsStream() to open a stream to the resource. If PropSpellingSession is constructed from a static method (such as "main"), in some Java implementations the call to getResourceAsStream will fail and the lexicon will not be opened. To avoid this, ensure that PropSpellingSession is constructed from a non-static object method (if necessary, create a class whose sole purpose is to call PropSpellingSession and provide access to the constructed PropSpellingSession object through a public member).

Different Java implementations have different rules about how resources with relative names are located. For example, if a Properties object contains the following definition:

MainLexicon1=ssceam.tlx,resource,t

the approach used to locate ssceam.tlx may vary depending on the Java implementation. It's generally safest to specify an absolute location for the resource:

MainLexicon1=/ssceam.tlx,resource,t

Even if absolute paths to resources are specified, the location of the resource root may not be what you expect. For example, some servers allow the root of a servlet to be configured. If the servlet's root was configured to be something other than what you expect, then an absolute resource name such as "/ssceam.tlx" will not point to the actual location of the resource. Even if the root has not been changed through configuration, a common source of problems with dictionary access when the Sentry engine is used in a servlet is failing to place the dictionary files in the correct directory on the server.

Another common cause of all words being reported as misspelled is forgetting to call LicenseKey.setKey with your license key, passing an invalid or expired evaluation key to LicenseKey.setKey, or calling LicenseKey.setKey at the wrong point. If you are evaluating Sentry Java SDK, the document Evaluation version reports all words as misspelled may help. It's important to note that license keys are associated with specific versions of Sentry Java SDK. When you obtain an upgrade to a newer version of Sentry Java SDK, you will receive a new license key. You must use that new license key with the new version of the Sentry class library. The old key, the one you received with the previous version, will not work with the new version.

Before your application can use the Sentry Java class library, it must call the LicenseKey.setKey method and pass a valid license key. Your license key is provided by Wintertree Software. The license key is an eight-digit hexadecimal number.

If the LicenseKey.setKey method is not called, or the license key passed is not valid, the Sentry engine will not work correctly.

The LicenseKey.setKey method needs to be called only once, but there is no harm in calling it more than once.

The LicenseKey.setKey method must be called before the first time you construct any Sentry objects, including objects derived from the Lexicon or SpellingSession classes:

LicenseKey.setKey(0x1234ABCD);  // substitute your license key for 0x1234ABCD
PropSpellingSession speller = new PropSpellingSession(properties);

or

LicenseKey.setKey(0x1234ABCD);  // substitute your license key for 0x1234ABCD
Lexicon myLexicons[1];
myLexicons[0] = new FileTextLexicon("ssceam.tlx");
SpellingSession speller = new SpellingSession();
speller.setLexicons(myLexicons);

If your application uses PropSpellingSession, one way to tell if the problem is caused by a missing or invalid license key is to display the length of the array returned by PropSpellingSession.getLength like this:

   System.out.println("Lexicon count: " + speller.getLexicons().length);

If the length is 0, the cause is most likely related to the license key. (PropSpellingSession always attempts to open a temporary MemTextLexicon, so the lexicon count should be at least 1. However, no lexicons will be opened if the license key is not valid.)

See "About the Sentry license key" in the "Getting Started" chapter of the Sentry Java SDK programmer's guide for further information.


Home Site index Contact us Catalog Shopping Cart Products Support Search


Copyright © 2015 Wintertree Software Inc.