MPPLanguageDetector
@interface MPPLanguageDetector : NSObject@brief Predicts the language of an input text.
This API expects a TFLite model with TFLite Model Metadatathat contains the mandatory (described below) input tensor, output tensor, and the language codes in an AssociatedFile.
Metadata is required for models with int32 input tensors because it contains the input process unit for the model’s Tokenizer. No metadata is required for models with string input tensors.
Input tensor
- One input tensor (
kTfLiteString) of shape[1]containing the input string.
Output tensor
- One output tensor (
kTfLiteFloat32) of shape[1 x N]whereNis the number of languages.
-
Creates a new instance of
LanguageDetectorfrom an absolute path to a TensorFlow Lite model file stored locally on the device and the defaultLanguageDetectorOptions.Declaration
Objective-C
- (nullable instancetype)initWithModelPath:(nonnull NSString *)modelPath error:(NSError *_Nullable *_Nullable)error;Parameters
modelPathAn absolute path to a TensorFlow Lite model file stored locally on the device.
errorAn optional error parameter populated when there is an error in initializing the language detector.
Return Value
A new instance of
LanguageDetectorwith the given model path.nilif there is an error in initializing the language detector. -
Creates a new instance of
LanguageDetectorfrom the givenLanguageDetectorOptions.Declaration
Objective-C
- (nullable instancetype)initWithOptions: (nonnull MPPLanguageDetectorOptions *)options error:(NSError *_Nullable *_Nullable)error;Parameters
optionsThe options of type
LanguageDetectorOptionsto use for configuring theLanguageDetector.errorAn optional error parameter populated when there is an error in initializing the language detector.
Return Value
A new instance of
LanguageDetectorwith the given options.nilif there is an error in initializing the language detector. -
Predicts the language of the input text.
Declaration
Objective-C
- (nullable MPPLanguageDetectorResult *) detectText:(nonnull NSString *)text error:(NSError *_Nullable *_Nullable)error;Parameters
textThe
NSStringfor which language is to be predicted.errorAn optional error parameter populated when there is an error in performing language prediction on the input text.
Return Value
A
LanguageDetectorResultobject that contains a list of language predictions. -
Undocumented
Declaration
Objective-C
- (instancetype)init NS_UNAVAILABLE; -
Undocumented
Declaration
Objective-C
+ (instancetype)new NS_UNAVAILABLE;