MLKitDigitalInkRecognition Framework Reference

DigitalInkRecognitionContext

class DigitalInkRecognitionContext : 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

    Swift

    var preContext: String? { get }
  • 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

    Swift

    var writingArea: MLKWritingArea? { get }
  • Unavailable. Use init(preContext:writingArea:) instead.

  • Creates a DigitalInkRecognitionContext object.

    Declaration

    Swift

    init(preContext: String?, writingArea: MLKWritingArea?)

    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.