TextSummarizer
class TextSummarizer: NSObjectPerforms summarization on text.
This API expects a LiteRT-LM model asset bundle.
-
Creates a new instance of
MPPTextSummarizerfrom an absolute path to a model asset bundle stored locally on the device and the defaultMPPTextSummarizerOptions.Declaration
Swift
convenience init(modelPath: String) throwsParameters
modelPathAn absolute path to a model file stored locally on the device.
errorAn optional error parameter populated when there is an error in initializing the text summarizer.
Return Value
A new instance of
MPPTextSummarizerwith the given model path.nilif there is an error in initializing the text summarizer. -
Creates a new instance of
MPPTextSummarizerfrom the givenMPPTextSummarizerOptions.Declaration
Swift
init(options: TextSummarizerOptions) throwsParameters
optionsThe options of type
MPPTextSummarizerOptionsto use for configuring theMPPTextSummarizer.errorAn optional error parameter populated when there is an error in initializing the text summarizer.
Return Value
A new instance of
MPPTextSummarizerwith the given options.nilif there is an error in initializing the text summarizer. -
Shuts down the
MPPTextSummarizerwhen all the work is done.Declaration
Swift
func close() throwsParameters
errorAn optional error parameter populated when there is an error in shutting down the text summarizer.
Return Value
YESif theMPPTextSummarizerwas successfully closed,NOotherwise. -
Performs summarization on the input text.
Declaration
Swift
func summarize(text: String) throws -> TextSummarizerResultParameters
textThe
NSStringon which summarization is to be performed.errorAn optional error parameter populated when there is an error in performing summarization on the input text.
Return Value
A
MPPTextSummarizerResultobject that contains the complete summary result. -
Performs summarization on the input
textand returns the result incrementally via the callback.Declaration
Swift
func summarizeStreaming(text: String, completion completionHandler: @escaping (TextSummarizerStreamResult?, (any Error)?) -> Void) throwsParameters
textThe input text to be summarized.
completionHandlerThe completion handler invoked with the incremental summarization result or an error.
errorAn optional error parameter populated when there is an error in initiating the summarization on the input text.
Return Value
YESif the stream summarization was successfully initiated,NOotherwise.