MLKitDigitalInkRecognition Framework Reference

Stay organized with collections Save and categorize content based on your preferences.

MLKDigitalInkRecognitionContext


@interface MLKDigitalInkRecognitionContext : NSObject

Information about the context in which an ink has been drawn.

Pass this object to a DigitalInkRecognizer alongside an ink to improve the recognition quality.

  • Characters immediately before the position where the recognized text should be inserted.

    This information is used by the recognizer’s language model to improve recognition.

    Example: a text field contains “hello”, with the cursor right after “o”. The user handwrites something that looks like “world”. If the pre-context is set to “hello”, the recognizer will be able to output “ world”, with a leading space.

    If the text field contains “hello” with the cursor between “e” and the first “l”, then the pre-context must be set to “he”.

    A good rule of thumb for pre-context length is: as many characters as possible, including spaces, until around 20. The optimal number depends on the exact recognition model that is used. Getting the best speed/accuracy tradeoff may require a bit of tuning.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) NSString *preContext;
  • Size of the writing area.

    This is used by some recognition models to disambiguate some cases. Example: lowercase vs. uppercase (“o” vs. “O”).

    See also WritingArea.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) MLKWritingArea *writingArea;
  • Unavailable. Use init(preContext:writingArea:) instead.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Creates a DigitalInkRecognitionContext object.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithPreContext:(nullable NSString *)preContext
                                   writingArea:
                                       (nullable MLKWritingArea *)writingArea;

    Parameters

    preContext

    Characters immediately before the position where the recognized text should be inserted. See the description of the property with the same name for more details.

    writingArea

    Properties of the region of the canvas where the ink has been drawn. See the description of the property with the same name for more details.