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]
whereN
is 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
LanguageDetector instance from a model file and the default LanguageDetector.LanguageDetectorOptions . |
static LanguageDetector |
createFromFile(Context context, File modelFile)
Creates a
LanguageDetector instance from a model file and the default LanguageDetector.LanguageDetectorOptions . |
static LanguageDetector |
createFromOptions(Context context, LanguageDetector.LanguageDetectorOptions options)
Creates a
LanguageDetector instance from LanguageDetector.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 LanguageDetector creation.
|
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 File instance. |
Throws
IOException | if an I/O error occurs when opening the tflite model file. |
---|---|
if there is an error during LanguageDetector creation.
|
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.LanguageDetectorOptions instance. |
Throws
if there is an error during LanguageDetector creation.
|
public LanguageDetectorResult detect (String inputText)
Predicts the language of the input text.
Parameters
inputText | a String for processing.
|
---|