MediaPipeTasksText Framework Reference

TextSummarizer

class TextSummarizer: NSObject

Performs summarization on text.

This API expects a LiteRT-LM model asset bundle.

  • Creates a new instance of MPPTextSummarizer from an absolute path to a model asset bundle stored locally on the device and the default MPPTextSummarizerOptions.

    Declaration

    Swift

    convenience init(modelPath: String) throws

    Parameters

    modelPath

    An absolute path to a model file stored locally on the device.

    error

    An optional error parameter populated when there is an error in initializing the text summarizer.

    Return Value

    A new instance of MPPTextSummarizer with the given model path. nil if there is an error in initializing the text summarizer.

  • Creates a new instance of MPPTextSummarizer from the given MPPTextSummarizerOptions.

    Declaration

    Swift

    init(options: TextSummarizerOptions) throws

    Parameters

    options

    The options of type MPPTextSummarizerOptions to use for configuring the MPPTextSummarizer.

    error

    An optional error parameter populated when there is an error in initializing the text summarizer.

    Return Value

    A new instance of MPPTextSummarizer with the given options. nil if there is an error in initializing the text summarizer.

  • Shuts down the MPPTextSummarizer when all the work is done.

    Declaration

    Swift

    func close() throws

    Parameters

    error

    An optional error parameter populated when there is an error in shutting down the text summarizer.

    Return Value

    YES if the MPPTextSummarizer was successfully closed, NO otherwise.

  • Performs summarization on the input text.

    Declaration

    Swift

    func summarize(text: String) throws -> TextSummarizerResult

    Parameters

    text

    The NSString on which summarization is to be performed.

    error

    An optional error parameter populated when there is an error in performing summarization on the input text.

    Return Value

    A MPPTextSummarizerResult object that contains the complete summary result.

  • Performs summarization on the input text and returns the result incrementally via the callback.

    Declaration

    Swift

    func summarizeStreaming(text: String, completion completionHandler: @escaping (TextSummarizerStreamResult?, (any Error)?) -> Void) throws

    Parameters

    text

    The input text to be summarized.

    completionHandler

    The completion handler invoked with the incremental summarization result or an error.

    error

    An optional error parameter populated when there is an error in initiating the summarization on the input text.

    Return Value

    YES if the stream summarization was successfully initiated, NO otherwise.