PenProfile 2.x

com.livescribe.icr
Class ICRContext

java.lang.Object
  extended by com.livescribe.icr.ICRContext

public abstract class ICRContext
extends Object

This class allows the application to use the Intelligent Character Recognition (ICR) engine. An instance of the context can be retrieved from PenletContext.getICRContext(int, HWRListener).

Notes:

See Also:
PenletContext.getICRContext(int, HWRListener), PenletContext.getICRContext(int, HWRListener, Language, WritingStyle)

Field Summary
static String CALCULATOR
          Deprecated. Add the resource to the application.
static String CALCULATOR_BIAS1
          Deprecated. Add the resource to the application.
static short ISOLATED_CHARACTER_TYPE_INK
          The "ink" isolated character type for use in startNewIsolatedCharacter(short).
static short ISOLATED_CHARACTER_TYPE_SPACE
          The "space" isolated character type for use in startNewIsolatedCharacter(short).
static String SYSRES_AK_FASTER
          Alphabet Knowledge for recognition.
static String SYSRES_AK_FULL
          Alphabet Knowledge for recognition.
static String SYSRES_AK_LMEM
          Alphabet Knowledge for recognition.
static String SYSRES_AK_LMEM_FASTER
          Alphabet Knowledge for recognition.
static String SYSRES_LK_BIGRAM
          Linguistic Knowledge resource that contains more than 100,000 words with associated bigram frequency.
static String SYSRES_LK_BIGRAM_100K
          Linguistic Knowledge resource that contains 100,000 words with associated bigram frequency.
static String SYSRES_LK_BIGRAM_30K
          Linguistic Knowledge resource that contains 30,000 words with associated bigram frequency.
static String SYSRES_LK_BIGRAM_65K
          Linguistic Knowledge resource that contains 65,000 words with associated bigram frequency.
static String SYSRES_LK_FREE
          A "Free" resource that allows for recognition of any words.
static String SYSRES_LK_GRAMMAR
          Grammar resource needed for recognition of multiple words (i.e.
static String SYSRES_LK_GRAMMER
          Deprecated. Use SYSRES_LK_GRAMMAR.
static String SYSRES_LK_OUT_OF_LEXICON
          "Out-of-Lexicon" resource that allows for recognition of words not in a lexicon.
static String SYSRES_LK_TRANSLATOR_DEMO
          Deprecated. Add the resource to the application.
static String SYSRES_LK_WORDLIST
          Linguistic Knowledge resource that contains more than 100,000 words with associated frequency.
static String SYSRES_LK_WORDLIST_100K
          Linguistic Knowledge resource that contains 100,000 words with associated frequency.
static String SYSRES_LK_WORDLIST_30K
          Linguistic Knowledge resource that contains 30,000 words with associated frequency.
static String SYSRES_LK_WORDLIST_65K
          Linguistic Knowledge resource that contains 65,000 words with associated frequency.
static String SYSRES_SK_ALNUM
          Subset Knowledge that contains only letters and digits.
static String SYSRES_SK_ALPHA
          Subset Knowledge that contains only alphabetic characters.
static String SYSRES_SK_DIGIT
          Subset Knowledge that contains only digits.
static String SYSRES_SK_LOWER
          Subset Knowledge that contains only lowercase letters.
static String SYSRES_SK_PUNCT
          Subset Knowledge that contains only certain punctuation characters.
static String SYSRES_SK_UPPER
          Subset Knowledge that contains only uppercase letters.
static long UNDEFINED_VALUE
          The "undefined value" for use in setGuidelines(long, long).
 
Method Summary
 void addResource(Resource resource)
          Adds a Resource to the ICR context.
abstract  void addResourceSet(Resource[] resources)
          Adds a set of resources to the ICR context.
abstract  void addStroke(PageInstance page, long time)
          Adds a stroke referenced by its time to the recognition context.
abstract  void addStroke(Stroke stroke)
          Adds a stroke to the recognition context.
abstract  void clearStrokes()
          Erases all strokes from the recognition context.
 Resource createAKSystemResource(String resourceName)
          Creates a new Resource from the specified Alphabet Knowledge system resource name.
abstract  Resource createAppResource(String resourceName)
          Creates a new Resource from the specified resource name.
abstract  LKDynamicResource createLKDynamicResource()
          Creates a new Lexicon Knowledge dynamic resource.
 Resource createLKSystemResource(String resourceName)
          Creates a new Resource from the specified Linguistic Knowledge system resource name.
abstract  SKDynamicResource createSKDynamicResource()
          This feature is not currently supported, but may be supported in a future release.
 Resource createSKSystemResource(String resourceName)
          Creates a new Resource from the specified Subset Knowledge system resource name.
abstract  void dispose()
          Dispose all the resources added to this recognition context.
abstract  void enableDoubleTapFilter(boolean enable)
          Indicates whether to prevent double taps from going to the recognition context.
 Resource getDefaultAlphabetKnowledgeResource()
          Gets the default Alphabet Knowledge resource to use for handwriting recognition in the specified language and writing style.
 Resource getDefaultLexiconKnowledgeResource()
          Gets the default lexicon resource to use for handwriting recognition in the specified language and writing style.
abstract  Locale getLocale()
          Normally this will be the same as the requested locale passed when the ICR context is created.
 Resource[] getMultiWordDefaultResourceSet()
          Gets a resource set that is appropriate for the recognition of multiple words in the specified language.
 Resource[] getSingleWordDefaultResourceSet()
          Gets a resource set that is appropriate for the recognition of single words in the specified language.
abstract  Rectangle getTextBoundingBox()
          Gets the bounding box of the recognized text.
static boolean isLocaleSupported(Locale locale)
          Check to see if a particular locale is supported on this pen.
abstract  void notifyPenDown(long time)
          Notify ICR that the user is starting to write.
abstract  void setGuidelines(long baseline, long midline)
          Define the Guidelines to use for recognition.
abstract  void setOptionUseMultiLineResult(boolean flag)
          If set to false, the recognizer will not try to split the input ink into multiple lines for recognition.
abstract  void setOptionUseUnlimitedResult(boolean option)
          Enables or disables the unlimited result recognition mechanism.
abstract  void startNewIsolatedCharacter(short characterType)
          Start a new character in Isolated Handwriting style.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSRES_AK_FULL

public static final String SYSRES_AK_FULL
Alphabet Knowledge for recognition. It is the most accurate one but it is also the slowest. However, it is still fast enough for synchronous recognition. The following table shows the resource size for each writing style.
Writing StyleResource Size
Cursive307k
Printing287k
Isolated284k

Since:
0.3
See Also:
Constant Field Values

SYSRES_AK_FASTER

public static final String SYSRES_AK_FASTER
Alphabet Knowledge for recognition. It consumes less memory than, and is faster than, the full AK, but is less accurate. It is similar in accuracy to the low memory AK, but is faster and uses more memory. The following table shows the resource size for each writing style.
Writing StyleResource Size
Cursive143k
Printing132k
Isolated130k

Since:
0.3
See Also:
Constant Field Values

SYSRES_AK_LMEM

public static final String SYSRES_AK_LMEM
Alphabet Knowledge for recognition. It consumes less memory than, and is faster than, the full AK, but is less accurate. It is similar in accuracy to the faster AK, but uses less memory and is slower. The following table shows the resource size for each writing style.
Writing StyleResource Size
Cursive168k
Printing158k
Isolated156k

Since:
0.3
See Also:
Constant Field Values

SYSRES_AK_LMEM_FASTER

public static final String SYSRES_AK_LMEM_FASTER
Alphabet Knowledge for recognition. It is the fastest and consumes the least memory but is also the least accurate. The following table shows the resource size for each writing style.
Writing StyleResource Size
Cursive75k
Printing70k
Isolated68k

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_WORDLIST_30K

public static final String SYSRES_LK_WORDLIST_30K
Linguistic Knowledge resource that contains 30,000 words with associated frequency. Every word is stored with an associated usage frequency. These frequencies were computed on large English corpuses. The resource size is 309k.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_WORDLIST_65K

public static final String SYSRES_LK_WORDLIST_65K
Linguistic Knowledge resource that contains 65,000 words with associated frequency. Every word is stored with an associated usage frequency. These frequencies were computed on large English corpuses. The resource size is 661k.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_WORDLIST_100K

public static final String SYSRES_LK_WORDLIST_100K
Linguistic Knowledge resource that contains 100,000 words with associated frequency. Every word is stored with an associated usage frequency. These frequencies were computed on large English corpuses. The resource size is 1002k.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_WORDLIST

public static final String SYSRES_LK_WORDLIST
Linguistic Knowledge resource that contains more than 100,000 words with associated frequency. Every word is stored with an associated usage frequency. These frequencies were computed on large English corpuses. The resource size is 661k. This resource is not available for all locales.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_BIGRAM_30K

public static final String SYSRES_LK_BIGRAM_30K
Linguistic Knowledge resource that contains 30,000 words with associated bigram frequency. Every word is stored with an associated usage frequency. Bigrams (pairs) of word frequencies are also stored. These bigram frequencies help for recognition of sentences or texts and not for just a single word. These frequencies were computed on large English corpuses. The resource size is 449k.

Note that this cannot be used with the unlimited result option.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_BIGRAM_65K

public static final String SYSRES_LK_BIGRAM_65K
Linguistic Knowledge resource that contains 65,000 words with associated bigram frequency. Every word is stored with an associated usage frequency. Bigrams (pairs) of word frequencies are also stored. These bigram frequencies help for recognition of sentences or texts and not for just a single word. These frequencies were computed on large English corpuses. The resource size is 889k.

Note that this cannot be used with the unlimited result option.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_BIGRAM_100K

public static final String SYSRES_LK_BIGRAM_100K
Linguistic Knowledge resource that contains 100,000 words with associated bigram frequency. Every word is stored with an associated usage frequency. Bigrams (pairs) of word frequencies are also stored. These bigram frequencies help for recognition of sentences or texts and not for just a single word. These frequencies have been computed on large English corpuses. The resource size is 1316k.

Note that this cannot be used with the unlimited result option.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_BIGRAM

public static final String SYSRES_LK_BIGRAM
Linguistic Knowledge resource that contains more than 100,000 words with associated bigram frequency. Every word is stored with an associated usage frequency. Bigrams (pairs) of word frequencies are also stored. These bigram frequencies help for recognition of sentences or texts and not for just a single word. These frequencies have been computed on large English corpuses. The resource size is 1676k. This resource is not available for all locales.

Note that this cannot be used with the unlimited result option.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_OUT_OF_LEXICON

public static final String SYSRES_LK_OUT_OF_LEXICON
"Out-of-Lexicon" resource that allows for recognition of words not in a lexicon. It should be used with a lexicon (such as a word list or bigram resource) to allow for recognition of entries not listed in the lexicon. The resource size is 74k.

This resource should not be used if you wish to recognize only a limited set of words or expressions, exclusively.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_TRANSLATOR_DEMO

public static final String SYSRES_LK_TRANSLATOR_DEMO
Deprecated. Add the resource to the application.
Translator demo lexicon. This is used by the translator demo on the pen.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_FREE

public static final String SYSRES_LK_FREE
A "Free" resource that allows for recognition of any words. This resource must be used without a lexicon. It should be used only in last resort situations when no lexicon can be used at all. The resource size is 23k.

This resource also provides an "out-of-lexicon" capability. It helps with the recognition of:

For example, "SOPHIA" may also be recognized as "S0PH1A". This resource helps the '0' and '1' be recognized as 'O' and 'I', respectively, because their surrounding letters are uppercase characters.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_GRAMMAR

public static final String SYSRES_LK_GRAMMAR
Grammar resource needed for recognition of multiple words (i.e. sentences). When the grammar is used, ICR will be able to recognize several words instead of only one. For example, a lexicon alone will allow for recognition of only one word from the lexicon, but a lexicon plus grammar allow for recognition of several words from the lexicon. The resource size is 1k.

Since:
0.3
See Also:
Constant Field Values

SYSRES_LK_GRAMMER

public static final String SYSRES_LK_GRAMMER
Deprecated. Use SYSRES_LK_GRAMMAR.
See Also:
Constant Field Values

SYSRES_SK_ALPHA

public static final String SYSRES_SK_ALPHA
Subset Knowledge that contains only alphabetic characters. Use it to limit recognized characters to only lowercase and uppercase letters.

See Also:
Constant Field Values

SYSRES_SK_LOWER

public static final String SYSRES_SK_LOWER
Subset Knowledge that contains only lowercase letters. Use it to limit recognized characters to only lowercase letters.

Since:
0.3
See Also:
Constant Field Values

SYSRES_SK_UPPER

public static final String SYSRES_SK_UPPER
Subset Knowledge that contains only uppercase letters. Use it to limit recognized characters to only uppercase letters.

Since:
0.3
See Also:
Constant Field Values

SYSRES_SK_ALNUM

public static final String SYSRES_SK_ALNUM
Subset Knowledge that contains only letters and digits. Use it to limit recognized characters to only uppercase and lowercase letters, and the digits 0–9.

Since:
0.3
See Also:
Constant Field Values

SYSRES_SK_DIGIT

public static final String SYSRES_SK_DIGIT
Subset Knowledge that contains only digits. Use it to limit recognized characters to only 0–9.

Since:
0.3
See Also:
Constant Field Values

SYSRES_SK_PUNCT

public static final String SYSRES_SK_PUNCT
Subset Knowledge that contains only certain punctuation characters. Use it to limit recognized characters to only common punctuation marks for the given language. only !,-.:;?"()'

Since:
0.3
See Also:
Constant Field Values

CALCULATOR

public static final String CALCULATOR
Deprecated. Add the resource to the application.
See Also:
Constant Field Values

CALCULATOR_BIAS1

public static final String CALCULATOR_BIAS1
Deprecated. Add the resource to the application.
See Also:
Constant Field Values

UNDEFINED_VALUE

public static final long UNDEFINED_VALUE
The "undefined value" for use in setGuidelines(long, long).

Since:
0.3
See Also:
Constant Field Values

ISOLATED_CHARACTER_TYPE_INK

public static final short ISOLATED_CHARACTER_TYPE_INK
The "ink" isolated character type for use in startNewIsolatedCharacter(short).

Since:
0.3
See Also:
Constant Field Values

ISOLATED_CHARACTER_TYPE_SPACE

public static final short ISOLATED_CHARACTER_TYPE_SPACE
The "space" isolated character type for use in startNewIsolatedCharacter(short).

Since:
0.3
See Also:
Constant Field Values
Method Detail

getDefaultAlphabetKnowledgeResource

public Resource getDefaultAlphabetKnowledgeResource()
Gets the default Alphabet Knowledge resource to use for handwriting recognition in the specified language and writing style.

The current default is SYSRES_AK_FASTER.

Returns:
a Resource object containing the default Alphabet Knowledge resource.
Since:
0.3
See Also:
PenletContext.getICRContext(int, HWRListener, Language, WritingStyle)

getDefaultLexiconKnowledgeResource

public Resource getDefaultLexiconKnowledgeResource()
Gets the default lexicon resource to use for handwriting recognition in the specified language and writing style.

The current default is SYSRES_LK_WORDLIST_30K.

Returns:
a Resource object containing the default Lexicon Knowledge resource.
Since:
0.3
See Also:
PenletContext.getICRContext(int, HWRListener, Language, WritingStyle)

getSingleWordDefaultResourceSet

public Resource[] getSingleWordDefaultResourceSet()
Gets a resource set that is appropriate for the recognition of single words in the specified language. This currently contains the following resources:

Returns:
a resource array containing resources suitable for the recognition of single words.
Since:
0.3
See Also:
PenletContext.getICRContext(int, HWRListener, Language, WritingStyle)

getMultiWordDefaultResourceSet

public Resource[] getMultiWordDefaultResourceSet()
Gets a resource set that is appropriate for the recognition of multiple words in the specified language. This currently contains the following resources:

Returns:
a resource array containing resources suitable for the recognition of multiple words.
Since:
0.3
See Also:
PenletContext.getICRContext(int, HWRListener, Language, WritingStyle)

createSKDynamicResource

public abstract SKDynamicResource createSKDynamicResource()
This feature is not currently supported, but may be supported in a future release.

Creates a new Subset Knowledge dynamic resource. This can be added to the resources with addResource(Resource) or addResourceSet(Resource[]).

Returns:
a new Subset Knowledge dynamic resource.
Since:
0.3

createLKDynamicResource

public abstract LKDynamicResource createLKDynamicResource()
Creates a new Lexicon Knowledge dynamic resource. This can be added to the resources with addResource(Resource) or addResourceSet(Resource[]).

Returns:
a new Lexicon Knowledge dynamic resource.
Since:
0.3
See Also:
addResource(Resource), addResourceSet(Resource[])

createAppResource

public abstract Resource createAppResource(String resourceName)
Creates a new Resource from the specified resource name. The resource can be a Subset Knowledge, Alphabet Knowledge, or Linguistic Knowledge resource.

For example, if an SK resource file named MyApp.sk exists for the application, then the resource name would be "/icr/SK_MyApp.res".

Parameters:
resourceName - the application resource name
Returns:
a new Resource object representing the specified resource.
Since:
0.3

createAKSystemResource

public Resource createAKSystemResource(String resourceName)
Creates a new Resource from the specified Alphabet Knowledge system resource name.

Parameters:
resourceName - the resource name
Returns:
a new Resource object representing the specified Alphabet Knowledge system resource.
Throws:
NullPointerException - if resourceName is null.
Since:
0.3
See Also:
"Any of the SYSRES_AK_* fields"

createSKSystemResource

public Resource createSKSystemResource(String resourceName)
Creates a new Resource from the specified Subset Knowledge system resource name.

Parameters:
resourceName - the resource name
Returns:
a new Resource object representing the specified Subset Knowledge system resource.
Throws:
NullPointerException - if resourceName is null.
Since:
0.3
See Also:
"Any of the SYSRES_SK_* fields"

createLKSystemResource

public Resource createLKSystemResource(String resourceName)
Creates a new Resource from the specified Linguistic Knowledge system resource name.

Parameters:
resourceName - the resource name
Returns:
a new Resource object representing the specified Linguistic Knowledge system resource.
Throws:
NullPointerException - if resourceName is null.
Since:
0.3
See Also:
"Any of the SYSRES_LK_* fields"

addResource

public final void addResource(Resource resource)
Adds a Resource to the ICR context. If this resource was already added to ICR context (for example before a modification), it will automatically be removed first and then only it will be added.

Parameters:
resource - add this resource
Throws:
NullPointerException - if resource is null.
RuntimeException - or a subclass thereof if there was an error adding the resource.
Since:
0.3
See Also:
addResourceSet(Resource[]), SKDynamicResource, LKDynamicResource

addResourceSet

public abstract void addResourceSet(Resource[] resources)
Adds a set of resources to the ICR context.

Correct usage: only one Alphabet Knowledge resource and one Subset Knowledge resource should be added. If more are added, only the latest one will stay attached. More than one Linguistic Knowledge resource may be added, however.

Parameters:
resources - add this set of resources, a Resource array
Throws:
RuntimeException - or a subclass thereof if there was an error adding the resource set.
Since:
0.3
See Also:
SKDynamicResource, LKDynamicResource

dispose

public abstract void dispose()
Dispose all the resources added to this recognition context. A new context must be retrieved from getICRContext1 or getICRContext2 for any new operations.

NOTE: Please see the note at getICRContext for a description of how to properly use this method.

See Also:
PenletContext.getICRContext(int, HWRListener), PenletContext.getICRContext(int, HWRListener, Language, WritingStyle)

setGuidelines

public abstract void setGuidelines(long baseline,
                                   long midline)
Define the Guidelines to use for recognition. This should be done before the first stroke is added.

Guidelines Schema

Parameters:
baseline - Y-coordinate of the baseline (mandatory)
midline - Y-coordinate of the midline or UNDEFINED_VALUE if not specified
Since:
0.3
See Also:
UNDEFINED_VALUE

startNewIsolatedCharacter

public abstract void startNewIsolatedCharacter(short characterType)
                                        throws IllegalArgumentException
Start a new character in Isolated Handwriting style. Tells ICR that a new character is starting. This method should be called before sending the first stroke of a new character ("ink"), or when there is an empty box ("space").

Parameters:
characterType - specifies if the character:
Throws:
IllegalArgumentException - If characterType value is not one of ISOLATED_CHARACTER_TYPE_INK or ISOLATED_CHARACTER_TYPE_SPACE
Since:
0.3
See Also:
ISOLATED_CHARACTER_TYPE_INK, ISOLATED_CHARACTER_TYPE_SPACE

notifyPenDown

public abstract void notifyPenDown(long time)
Notify ICR that the user is starting to write. Recognition will wait until the stroke is finished before sending a user-pause event.

This method should be called for every stroke sent to the recognition engine with addStroke(). The best place to call this is from within PenTipListener.penDown(long, Region, PageInstance).

Parameters:
time - the pen-down event time.
See Also:
addStroke(PageInstance, long), addStroke(Stroke)

enableDoubleTapFilter

public abstract void enableDoubleTapFilter(boolean enable)
Indicates whether to prevent double taps from going to the recognition context. These can cause incorrect characters being appended to the end of the result. The default state is true.

Parameters:
enable - indicates whether to enable the double tap filter

addStroke

public abstract void addStroke(Stroke stroke)
Adds a stroke to the recognition context. Each call to this method should be paired with a prior call to notifyPenDown(long).

Note that the delay time specified when creating an ICR context starts from the time this method is called.

Parameters:
stroke - the Stroke to add
See Also:
notifyPenDown(long), addStroke(PageInstance, long)

addStroke

public abstract void addStroke(PageInstance page,
                               long time)
Adds a stroke referenced by its time to the recognition context. Each call to this method should be paired with a prior call to notifyPenDown(long).

Note that the delay time specified when creating an ICR context starts from the time this method is called.

Parameters:
page - the page on which the stroke occurred
time - the stroke event time
See Also:
notifyPenDown(long), addStroke(Stroke), StrokeListener.strokeCreated(long, Region, PageInstance)

clearStrokes

public abstract void clearStrokes()
Erases all strokes from the recognition context. This is used each time the application needs to recognize something new and needs to forget the last result.


getTextBoundingBox

public abstract Rectangle getTextBoundingBox()
Gets the bounding box of the recognized text.

Returns:
a Rectangle containing the bounding box of the current text result.

setOptionUseMultiLineResult

public abstract void setOptionUseMultiLineResult(boolean flag)
If set to false, the recognizer will not try to split the input ink into multiple lines for recognition. This should be set to false when the input is known to be a single line. For example, the recognizer may fail to see a ';' character as one unit.

If set to true, the recognizer will try to recognize the handwriting as multiple lines.

The default is false.

Parameters:
flag - indicates whether to use multi-line recognition

setOptionUseUnlimitedResult

public abstract void setOptionUseUnlimitedResult(boolean option)
Enables or disables the unlimited result recognition mechanism. If enabled and the correct resources are used then HWR can recognize very long text.

Please note that you cannot use this option in conjunction with any of the SYSRES_LK_BIGRAM* Linguistic Knowledge resources. (These are the [language]-lk-text.lex.level2.res files). The feature is disabled if any of these are used.

The default is false.

Parameters:
option - the new value of this option
Throws:
java.lang.IllegalStateException - if recognition has started.

getLocale

public abstract Locale getLocale()
Normally this will be the same as the requested locale passed when the ICR context is created. If, however, the requested locale is not available then the ICR context will default to Locale.EN_US.

Returns:
locale of the ICR Context

isLocaleSupported

public static boolean isLocaleSupported(Locale locale)
Check to see if a particular locale is supported on this pen. Asian languages are not supported on the 1st generation pens.

Parameters:
locale -
Returns:
true if the icr resources are present and if this pen can load them

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.