public final class LanguageIdentifier

  1. Object
  2. LanguageIdentifier
Identifies possible languages entirely on device. Results are ranked by descending backend confidence and filtered by LanguageOptions.getMinimumConfidence().

Nested types

class LanguageIdentifier.SessionReusable owner of a native language-identification backend.

Methods

public static boolean isSupported()
public static boolean isSupported(LanguageOptions options)
public static LanguageIdentifier.Session open(LanguageOptions options)Opens a reusable language-identification session.
public static AsyncResource<LanguageCandidate[]> identify(String text, LanguageOptions options)Identifies possible languages off the EDT without uploading text.

Inherited methods

Method details

isSupported

public static boolean isSupported()

Returns

whether automatic language identification is available

isSupported

public static boolean isSupported(LanguageOptions options)

Parameters

options LanguageOptions
backend selection, or null for defaults

Returns

whether the selected backend is available on this target

open

public static LanguageIdentifier.Session open(LanguageOptions options)
Opens a reusable language-identification session. Reusing a session avoids repeatedly creating the native recognizer when classifying many strings. Close it when no more identifications are pending.

Parameters

options LanguageOptions
backend and confidence options, or null

Returns

a reusable session that owns one native language backend

Throws

UnsupportedOperationException
if the selected backend is absent

identify

public static AsyncResource<LanguageCandidate[]> identify(String text, LanguageOptions options)
Identifies possible languages off the EDT without uploading text. The option values are copied before the backend starts, so later mutations of the supplied object cannot alter the pending identification. Cancelling the returned resource suppresses late result callbacks; the temporary backend is released after its pending native work settles.

Parameters

text String
non-null text to classify
options LanguageOptions
backend and confidence options, or null

Returns

asynchronous ranked candidates; may be empty for undetermined text