LanguageDetector

public final class LanguageDetector

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.
  • Output tensor
    • One output tensor (kTfLiteFloat32) of shape [1 x N] where N is the number of languages.

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
LanguageDetectorResult
detect(String inputText)
Predicts the language of the input text.

Inherited Methods

Public Methods

public void close ()

Closes and cleans up the LanguageDetector.

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)

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.