Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

TextClassifier

public abstract class TextClassifier
extends Object

java.lang.Object
   ↳ androidx.textclassifier.TextClassifier


Interface for providing text classification related features. TextClassifier acts as a proxy to either the system provided TextClassifier, or an equivalent implementation provided by an app. Each instance of the class therefore represents one connection to the classifier implementation.

Unless otherwise stated, methods of this interface are blocking operations. Avoid calling them on the UI thread.

Summary

Nested classes

class TextClassifier.EntityConfig

Configuration object for specifying what entities to identify. 

Constants

String HINT_TEXT_IS_EDITABLE

Designates that the text in question is editable.

String HINT_TEXT_IS_NOT_EDITABLE

Designates that the text in question is not editable.

String TYPE_ADDRESS

Identifies a physical address.

String TYPE_DATE

Time reference that is no more specific than a date.

String TYPE_DATE_TIME

Time reference that includes a specific time.

String TYPE_EMAIL

Identifies an e-mail address.

String TYPE_FLIGHT_NUMBER

Flight number in IATA format.

String TYPE_OTHER

Signifies that the classifier ran, but didn't recognize a know entity.

String TYPE_PHONE

Identifies a phone number.

String TYPE_UNKNOWN

Signifies that the TextClassifier did not identify an entity.

String TYPE_URL

Identifies a URL.

String WIDGET_TYPE_CUSTOM_EDITTEXT

The widget involved in the text classification session is a custom editable text widget.

String WIDGET_TYPE_CUSTOM_TEXTVIEW

The widget involved in the text classification session is a custom text widget.

String WIDGET_TYPE_CUSTOM_UNSELECTABLE_TEXTVIEW

The widget involved in the text classification session is a custom non-selectable text widget.

String WIDGET_TYPE_EDITTEXT

The widget involved in the text classification session is a standard EditText.

String WIDGET_TYPE_EDIT_WEBVIEW

The widget involved in the text classification session is a standard editable WebView.

String WIDGET_TYPE_TEXTVIEW

The widget involved in the text classification session is a standard TextView.

String WIDGET_TYPE_UNKNOWN

The widget involved in the text classification session is of an unknown/unspecified type.

String WIDGET_TYPE_UNSELECTABLE_TEXTVIEW

The widget involved in the text classification session is a standard non-selectable TextView.

String WIDGET_TYPE_WEBVIEW

The widget involved in the text classification session is a standard WebView.

Fields

public static final TextClassifier NO_OP

No-op TextClassifier.

Public constructors

TextClassifier()

Public methods

TextClassification classifyText(TextClassification.Request request)

Classifies the specified text and returns a TextClassification object that can be used to generate a widget for handling the classified text.

TextLinks generateLinks(TextLinks.Request request)

Generates and returns a TextLinks that may be applied to the text to annotate it with links information.

int getMaxGenerateLinksTextLength()

Returns the maximal length of text that can be processed by generateLinks.

TextSelection suggestSelection(TextSelection.Request request)

Returns suggested text selection start and end indices, recognized entity types, and their associated confidence scores.

Inherited methods

Constants

HINT_TEXT_IS_EDITABLE

public static final String HINT_TEXT_IS_EDITABLE

Designates that the text in question is editable.

Constant Value: "android.text_is_editable"

HINT_TEXT_IS_NOT_EDITABLE

public static final String HINT_TEXT_IS_NOT_EDITABLE

Designates that the text in question is not editable.

Constant Value: "android.text_is_not_editable"

TYPE_ADDRESS

public static final String TYPE_ADDRESS

Identifies a physical address.

Constant Value: "address"

TYPE_DATE

public static final String TYPE_DATE

Time reference that is no more specific than a date. May be absolute such as "01/01/2000" or relative like "tomorrow".

Constant Value: "date"

TYPE_DATE_TIME

public static final String TYPE_DATE_TIME

Time reference that includes a specific time. May be absolute such as "01/01/2000 5:30pm" or relative like "tomorrow at 5:30pm".

Constant Value: "datetime"

TYPE_EMAIL

public static final String TYPE_EMAIL

Identifies an e-mail address.

Constant Value: "email"

TYPE_FLIGHT_NUMBER

public static final String TYPE_FLIGHT_NUMBER

Flight number in IATA format.

Constant Value: "flight"

TYPE_OTHER

public static final String TYPE_OTHER

Signifies that the classifier ran, but didn't recognize a know entity.

Constant Value: "other"

TYPE_PHONE

public static final String TYPE_PHONE

Identifies a phone number.

Constant Value: "phone"

TYPE_UNKNOWN

public static final String TYPE_UNKNOWN

Signifies that the TextClassifier did not identify an entity.

Constant Value: ""

TYPE_URL

public static final String TYPE_URL

Identifies a URL.

Constant Value: "url"

WIDGET_TYPE_CUSTOM_EDITTEXT

public static final String WIDGET_TYPE_CUSTOM_EDITTEXT

The widget involved in the text classification session is a custom editable text widget.

Constant Value: "customedit"

WIDGET_TYPE_CUSTOM_TEXTVIEW

public static final String WIDGET_TYPE_CUSTOM_TEXTVIEW

The widget involved in the text classification session is a custom text widget.

Constant Value: "customview"

WIDGET_TYPE_CUSTOM_UNSELECTABLE_TEXTVIEW

public static final String WIDGET_TYPE_CUSTOM_UNSELECTABLE_TEXTVIEW

The widget involved in the text classification session is a custom non-selectable text widget.

Constant Value: "nosel-customview"

WIDGET_TYPE_EDITTEXT

public static final String WIDGET_TYPE_EDITTEXT

The widget involved in the text classification session is a standard EditText.

Constant Value: "edittext"

WIDGET_TYPE_EDIT_WEBVIEW

public static final String WIDGET_TYPE_EDIT_WEBVIEW

The widget involved in the text classification session is a standard editable WebView.

Constant Value: "edit-webview"

WIDGET_TYPE_TEXTVIEW

public static final String WIDGET_TYPE_TEXTVIEW

The widget involved in the text classification session is a standard TextView.

Constant Value: "textview"

WIDGET_TYPE_UNKNOWN

public static final String WIDGET_TYPE_UNKNOWN

The widget involved in the text classification session is of an unknown/unspecified type.

Constant Value: "unknown"

WIDGET_TYPE_UNSELECTABLE_TEXTVIEW

public static final String WIDGET_TYPE_UNSELECTABLE_TEXTVIEW

The widget involved in the text classification session is a standard non-selectable TextView.

Constant Value: "nosel-textview"

WIDGET_TYPE_WEBVIEW

public static final String WIDGET_TYPE_WEBVIEW

The widget involved in the text classification session is a standard WebView.

Constant Value: "webview"

Fields

NO_OP

public static final TextClassifier NO_OP

No-op TextClassifier. This may be used to turn off text classifier features.

Public constructors

TextClassifier

public TextClassifier ()

Public methods

classifyText

public TextClassification classifyText (TextClassification.Request request)

Classifies the specified text and returns a TextClassification object that can be used to generate a widget for handling the classified text.

NOTE: Call on a worker thread.

Parameters
request TextClassification.Request: the text classification request

Returns
TextClassification

generateLinks

public TextLinks generateLinks (TextLinks.Request request)

Generates and returns a TextLinks that may be applied to the text to annotate it with links information.

NOTE: Call on a worker thread.

Parameters
request TextLinks.Request: the text links request

Returns
TextLinks

getMaxGenerateLinksTextLength

public int getMaxGenerateLinksTextLength ()

Returns the maximal length of text that can be processed by generateLinks.

Returns
int

suggestSelection

public TextSelection suggestSelection (TextSelection.Request request)

Returns suggested text selection start and end indices, recognized entity types, and their associated confidence scores. The entity types are ordered from highest to lowest scoring.

NOTE: Call on a worker thread.

Parameters
request TextSelection.Request: the text selection request

Returns
TextSelection