Predicts the language of an input text.
This API expects a TFLite model with TFLite Model Metadata that contains the mandatory (described below) input tensors, output tensor, and the language codes in an AssociatedFile.
- Input tensor
       - One input tensor (kTfLiteString) of shape [1] containing the input string.
 
- One input tensor (
- Output tensor
       - One output tensor (kTfLiteFloat32) of shape[1 x N]whereNis the number of languages.
 
- One output tensor (
Nested Classes
| class | LanguageDetector.LanguageDetectorOptions | Options for setting up a LanguageDetector. | |
Public Methods
| void | 
close()
                
                   Closes and cleans up the  LanguageDetector. | 
| static LanguageDetector | 
createFromFile(Context context, String modelPath)
                
                   Creates a  LanguageDetectorinstance from a model file and the defaultLanguageDetector.LanguageDetectorOptions. | 
| static LanguageDetector | 
createFromFile(Context context, File modelFile)
                
                   Creates a  LanguageDetectorinstance from a model file and the defaultLanguageDetector.LanguageDetectorOptions. | 
| static LanguageDetector | 
createFromOptions(Context context, LanguageDetector.LanguageDetectorOptions options)
                
                   Creates a  LanguageDetectorinstance fromLanguageDetector.LanguageDetectorOptions. | 
| LanguageDetectorResult | 
Inherited Methods
Public Methods
public static LanguageDetector createFromFile (Context context, String modelPath)
Creates a LanguageDetector instance from a model file and the default LanguageDetector.LanguageDetectorOptions.
Parameters
| context | an Android ERROR(/Context). | 
|---|---|
| modelPath | path to the text model with metadata in the assets. | 
Throws
| if there is is an error during LanguageDetectorcreation. | 
public static LanguageDetector createFromFile (Context context, File modelFile)
Creates a LanguageDetector instance from a model file and the default LanguageDetector.LanguageDetectorOptions.
Parameters
| context | an Android ERROR(/Context). | 
|---|---|
| modelFile | the text model Fileinstance. | 
Throws
| IOException | if an I/O error occurs when opening the tflite model file. | 
|---|---|
| if there is an error during LanguageDetectorcreation. | 
public static LanguageDetector createFromOptions (Context context, LanguageDetector.LanguageDetectorOptions options)
Creates a LanguageDetector instance from LanguageDetector.LanguageDetectorOptions.
Parameters
| context | an Android ERROR(/Context). | 
|---|---|
| options | a LanguageDetector.LanguageDetectorOptionsinstance. | 
Throws
| if there is an error during LanguageDetectorcreation. | 
public LanguageDetectorResult detect (String inputText)
Predicts the language of the input text.
Parameters
| inputText | a Stringfor processing. | 
|---|