# LanguageIdentifier

public interface **LanguageIdentifier** extends [Closeable](https://developer.android.com/reference/java/io/Closeable.html), [LifecycleObserver](https://developer.android.com/reference/androidx/lifecycle/LifecycleObserver.html), [OptionalModuleApi](https://developers.google.com/android/reference/com/google/android/gms/common/api/OptionalModuleApi) A `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentification`
client for identifying the language of a piece of text.

A `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier`
is created via `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentification#getClient(com.google.mlkit.nl.languageid.LanguageIdentificationOptions)` or `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentification#getClient()`
if you wish to use the default options. For example, the code below creates a `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier`
with default options.

Example:

    LanguageIdentifier languageIdentifier = LanguageIdentification.getClient();
     
This class can be used from any thread.

### Constant Summary

|---|---|---|
| float | [DEFAULT_IDENTIFY_LANGUAGE_CONFIDENCE_THRESHOLD](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#DEFAULT_IDENTIFY_LANGUAGE_CONFIDENCE_THRESHOLD) | The default confidence threshold for the `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#identifyLanguage(java.lang.String)` call. |
| float | [DEFAULT_IDENTIFY_POSSIBLE_LANGUAGES_CONFIDENCE_THRESHOLD](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#DEFAULT_IDENTIFY_POSSIBLE_LANGUAGES_CONFIDENCE_THRESHOLD) | The default confidence threshold for the `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#identifyPossibleLanguages(java.lang.String)` call. |
| [String](https://developer.android.com/reference/java/lang/String.html) | [UNDETERMINED_LANGUAGE_TAG](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#UNDETERMINED_LANGUAGE_TAG) | The [BCP 47 language tag](https://tools.ietf.org/rfc/bcp/bcp47.txt) for "undetermined language" |

### Public Method Summary

|---|---|
| abstract void | [close](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#close())() |
| abstract Task\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [identifyLanguage](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#identifyLanguage(java.lang.String))([String](https://developer.android.com/reference/java/lang/String.html) text) Identifies the language in a supplied `https://developer.android.com/reference/java/lang/String.html` and returns the most likely language. |
| abstract Task\<[List](https://developer.android.com/reference/java/util/List.html)\<[IdentifiedLanguage](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/IdentifiedLanguage)\>\> | [identifyPossibleLanguages](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#identifyPossibleLanguages(java.lang.String))([String](https://developer.android.com/reference/java/lang/String.html) text) Identifies the language in a supplied `https://developer.android.com/reference/java/lang/String.html` and returns a list of possible languages, cutting off any languages whose confidence score falls below the threshold which is set in `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentificationOptions.Builder#setConfidenceThreshold(float)`. |

### Inherited Method Summary

From interface java.io.Closeable

|---|---|
| abstract void | close() |

From interface java.lang.AutoCloseable

|---|---|
| abstract void | close() |

## Constants

#### public static final float
**DEFAULT_IDENTIFY_LANGUAGE_CONFIDENCE_THRESHOLD**

The default confidence threshold for the `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#identifyLanguage(java.lang.String)` call.
Constant Value: 0.5

#### public static final float
**DEFAULT_IDENTIFY_POSSIBLE_LANGUAGES_CONFIDENCE_THRESHOLD**

The default confidence threshold for the `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#identifyPossibleLanguages(java.lang.String)` call.
Constant Value: 0.01

#### public static final [String](https://developer.android.com/reference/java/lang/String.html)
**UNDETERMINED_LANGUAGE_TAG**

The [BCP 47 language tag](https://tools.ietf.org/rfc/bcp/bcp47.txt) for
"undetermined language"
Constant Value: "und"

## Public Methods

#### public abstract void **close** ()

#### public abstract Task\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**identifyLanguage** ([String](https://developer.android.com/reference/java/lang/String.html) text)

Identifies the language in a supplied `https://developer.android.com/reference/java/lang/String.html` and returns
the most likely language.

##### Parameters

| text | the text for which to identify the language. Inputs longer than 200 characters are truncated to 200 characters, as longer input does not improve the detection accuracy. |
|---|---|

##### Returns

- a `https://developers.google.com/android/reference/com/google/android/gms/tasks/Task` that returns a `https://developer.android.com/reference/java/lang/String.html` with the [BCP 47 language tag](https://tools.ietf.org/rfc/bcp/bcp47.txt) of the most likely language, or `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#UNDETERMINED_LANGUAGE_TAG` if the confidence was below the threshold specified in `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentificationOptions`

#### public abstract Task\<[List](https://developer.android.com/reference/java/util/List.html)\<[IdentifiedLanguage](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/IdentifiedLanguage)\>\>
**identifyPossibleLanguages** ([String](https://developer.android.com/reference/java/lang/String.html) text)

Identifies the language in a supplied `https://developer.android.com/reference/java/lang/String.html` and returns
a list of possible languages, cutting off any languages whose confidence score falls
below the threshold which is set in `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentificationOptions.Builder#setConfidenceThreshold(float)`.

Note that this API assumes the `text` is in a single language; the
returned list contains all estimations for what that language could be, along with a
confidence score for each possible language. The API does *not* detect multiple
languages in a single text.

##### Parameters

| text | the text for which to identify the language. Inputs longer than 200 characters are truncated to 200 characters, as longer input does not improve the detection accuracy. |
|---|---|

##### Returns

- a `https://developers.google.com/android/reference/com/google/android/gms/tasks/Task` that returns a `https://developer.android.com/reference/java/util/List.html` of `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/IdentifiedLanguage`s. The returned list will never be empty; if all languages have lower confidence scores than the threshold, the list will contain a single item with the `https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier#UNDETERMINED_LANGUAGE_TAG`.