# 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.md.txt) A `LanguageIdentification`
client for identifying the language of a piece of text.

A `LanguageIdentifier`
is created via `
LanguageIdentification.getClient(LanguageIdentificationOptions)` or `LanguageIdentification.getClient()`
if you wish to use the default options. For example, the code below creates a `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.md.txt#DEFAULT_IDENTIFY_LANGUAGE_CONFIDENCE_THRESHOLD) | The default confidence threshold for the ` identifyLanguage(String)` call. |
| float | [DEFAULT_IDENTIFY_POSSIBLE_LANGUAGES_CONFIDENCE_THRESHOLD](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier.md.txt#DEFAULT_IDENTIFY_POSSIBLE_LANGUAGES_CONFIDENCE_THRESHOLD) | The default confidence threshold for the ` identifyPossibleLanguages(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.md.txt#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.md.txt#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.md.txt#identifyLanguage(java.lang.String))([String](https://developer.android.com/reference/java/lang/String.html) text) Identifies the language in a supplied `String` 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.md.txt)\>\> | [identifyPossibleLanguages](https://developers.google.com/android/reference/com/google/mlkit/nl/languageid/LanguageIdentifier.md.txt#identifyPossibleLanguages(java.lang.String))([String](https://developer.android.com/reference/java/lang/String.html) text) Identifies the language in a supplied `String` and returns a list of possible languages, cutting off any languages whose confidence score falls below the threshold which is set in ` 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 `
identifyLanguage(String)` call.
Constant Value: 0.5

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

The default confidence threshold for the `
identifyPossibleLanguages(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 `String` 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 `Task` that returns a `String` with the [BCP 47 language tag](https://tools.ietf.org/rfc/bcp/bcp47.txt) of the most likely language, or `
  UNDETERMINED_LANGUAGE_TAG` if the confidence was below the threshold specified in `
  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.md.txt)\>\>
**identifyPossibleLanguages** ([String](https://developer.android.com/reference/java/lang/String.html) text)

Identifies the language in a supplied `String` and returns
a list of possible languages, cutting off any languages whose confidence score falls
below the threshold which is set in `
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 `Task` that returns a `List` of `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 `
  UNDETERMINED_LANGUAGE_TAG`.