Build custom resources
This page describes how you can build custom recognition resources to fine-tune the recognition process.
MyScript Developer Portal comes with an online tool that lets you build your own resources, should you want to customize the recognition to address particular needs. This page describes how to prepare files to provide to the tool.
Interactive Ink SDK also comes with a built-in tool to generate recognition assets. Currently, only math grammars can be
generated this way (pass
"Math Grammar" as the target asset type).
The workflow is as follows:
- Create a
IINKRecognitionAssetsBuilderobject from your engine.
- Call its
compile:data:errormethod, passing it the right information.
Serialize the resource into a file using the
- Reference the new resource in your configuration file
- Update your engine or editor configuration if needed (it may not be needed if you keep the same configuration bundle and name)
- Create a new part and associate it with an editor
For example, to compile a math grammar, steps 1 to 3 will look as follows:
// 1. Create a recognition assets builder IINKRecognitionAssetsBuilder *assetsBuilder = [engine createRecognitionAssetsBuilder]; // 2. Define and compile the grammar NSString *grammar = @"..."; [assetsBuilder compile:@"Math Grammar" data:grammar error:nil]; // 3. Save it to the disc [assetsBuilder store:@"custom-grammar.res" error:nil];
Step 4 consists in editing our math configuration (or create a new one) to load our custom grammar instead of the standard one:
You can get the list of recognition assets types that can be compiled via the
supportedRecognitionAssetsTypes property of the
The lexicon is a list of words or expressions, that is being used by the engine to recognize a specific set of terms. You can create your own lexicon to improve the recognition. It may contain terms that are unlikely to appear in a classical dictionary but that you will be led to write many times (proper nouns like the name of your company or your employees, your password, a hashtag, etc.).
For example, a lexicon can be the following set:
Johnson Meyer Lopez Gibbons Cooper Martin Bailey
If needed, you can also download another Lexicon example.
The Subset Knowledge resource (or SK) is a white list that works as a filter to constrain the recognition to a specific set of characters. You can create your own SK to improve the recognition and help the engine reduce the “margin of error”. The expected set can be limited to digits or to letters in a given alphabet or language.
For example: In a form field where you expect a phone number, constraining the recognition with a SK could avoid the engine to mistake a “0” for a “O” or a “1” for a “l”.
See below examples of SK resources:
If needed, you can download another SK example.
The grammar resource indicates the way to parse handwritten mathematical expressions. It specifies:
a limited set of terminal symbols,
Terminal symbols are the elementary symbols. They are basic symbols such as a, b, c, …, 0, 1, …, +, -, ±, etc. that cannot be broken down into “smaller” recognized units. See below the list of supported symbols.
a limited set of non-terminal symbols,
Non-terminal symbols describe groups of terminal symbols organized according to rules.
a limited set of rules,
Rules describe the way to parse digital ink. For instance, a fraction is a rule that contains a numerator, a fraction bar and a denominator. The recognizer expects to find these three elements to fit the fraction rule. See below the list of supported rules.
a start symbol.
This defines the way your mathematical expression should be read depending on the above elements.
For example, a grammar resource can be:
symbol = 0 1 2 3 4 5 6 7 8 9 + - / ÷ = . , % | ( ) : * x leftpar = ( rightpar = ) currency_symbol = $ R € ₹ £ character ::= identity(symbol) | identity(currency_symbol) fractionless ::= identity(character) | fence (fractionless, leftpar, rightpar) | hpair(fractionless, fractionless) fractionable ::= identity(character) | fence (fractionable, leftpar, rightpar) | hpair(fractionable, fractionable) | fraction(fractionless, fractionless) expression ::= identity(character) | fence (expression, leftpar, rightpar) | hpair(expression, expression) | fraction(fractionable, fractionable) start(expression)
If needed, you can download another Grammar example.
You can build your own MyScript-Math-compliant grammar resource. To do so, you must define the grammar in conformity with the syntax set out below and then compile it.
You can add comments in a grammar resource as follows:
// This is the first way to start a whole comment line. # This is the second way to start a whole comment line. " This is the third way to start a whole comment line. /* This is a block comment. */
Inline comments are not supported.
Your grammar resource will contain terminal symbol definitions such as the following:
my_terminal_name = 0 1 2 3 4 5 6 7 8 9
The terminal symbol name is defined as: [-a-zA-Z_][-a-zA-Z_0-9]
It is a character string which starts with a character from [-a-zA-Z_] and whose other characters are any of [-a-zA-Z_0-9]. In the above example, the terminal symbol name is
The list of symbols referred to by the terminal name are defined as: ( ( !EOL . )+ | EOL space+ )+
The definition of the symbols referred to by the terminal name does not start by a EOL (end of line). They can be any existing character separated by a space or EOL and a space. In other words, the definition of the symbols is allowed to span multiple lines, providing that the “continuation line” starts with a space. This means you can format long terminal symbol definitions in a more visually organized (“pretty-formatted”) manner. In the above example, the list of symbols referred to by
0 1 2 3 4 5 6 7 8 9.
Space is defined as ‘ ’ or ‘\t’
EOL is defined as ‘\r\n’ or ‘\n’ or ‘\r’
You will also need to list non-terminal symbol definitions. Here is an example:
my_non_terminal_name ::= fraction(my_terminal_name,my_terminal_name)
- The non-terminal symbol name is defined as : [-a-zA-Z_][-a-zA-Z_0-9]
It is a character string which starts with a character from [-a-zA-Z_] and whose other characters are any of [-a-zA-Z_0-9]. In the above example, the non-terminal symbol name is
The non-terminal symbol is defined as:
non_terminal_name ::= rule (| rule)?
In the above example, the rule is
fraction. The example specifies that the numerator is a
my_terminal_name symbol and that
the denominator is also a
Rule continuations allow you to “pretty format” rule definitions by avoiding a repetition of target non-terminal symbol names.
Finally, your grammar must include the start symbol definition:
Finally, you must define the start symbol.
In the above example, we specify that the general mathematical expression form that will be recognized is
In other words, we expect the input digital ink to represent a fraction of digits.
Here is an example of a custom grammar:
A non-exhaustive list of supported math symbols and rules can be found here.
It is also possible to create a custom grammar resource, by constraining the recognition for particular use cases (integral calculus, vector calculus, finite element calculus, etc.).
The following table provides for each supported math rule its denomination in the grammar as well as the parameters it supports:
||Reuse a previously defined symbol in a rule clause|
||Ordered juxtaposition of the
|Partial fraction (numerator)||
||Only the numerator of the fraction is defined|
|Partial fraction (denominator)||
||Only the denominator of the fraction is defined|