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]
whereN
is the number of languages.
-
Creates a new instance of
LanguageDetector
from 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
modelPath
An absolute path to a TensorFlow Lite model file stored locally on the device.
error
An optional error parameter populated when there is an error in initializing the language detector.
Return Value
A new instance of
LanguageDetector
with the given model path.nil
if there is an error in initializing the language detector. -
Creates a new instance of
LanguageDetector
from the givenLanguageDetectorOptions
.Declaration
Objective-C
- (nullable instancetype)initWithOptions: (nonnull MPPLanguageDetectorOptions *)options error:(NSError *_Nullable *_Nullable)error;
Parameters
options
The options of type
LanguageDetectorOptions
to use for configuring theLanguageDetector
.error
An optional error parameter populated when there is an error in initializing the language detector.
Return Value
A new instance of
LanguageDetector
with the given options.nil
if 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
text
The
NSString
for which language is to be predicted.error
An optional error parameter populated when there is an error in performing language prediction on the input text.
Return Value
A
LanguageDetectorResult
object that contains a list of language predictions. -
Undocumented
Declaration
Objective-C
- (instancetype)init NS_UNAVAILABLE;
-
Undocumented
Declaration
Objective-C
+ (instancetype)new NS_UNAVAILABLE;