Register now for Android Dev Summit 2019!

TextClassifier

abstract class TextClassifier
kotlin.Any
   ↳ 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

Configuration object for specifying what entities to identify.

Constants

static String

Designates that the text in question is editable.

static String

Designates that the text in question is not editable.

static String

Identifies a physical address.

static String

Time reference that is no more specific than a date.

static String

Time reference that includes a specific time.

static String

Identifies an e-mail address.

static String

Flight number in IATA format.

static String

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

static String

Identifies a phone number.

static String

Signifies that the TextClassifier did not identify an entity.

static String

Identifies a URL.

static String

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

static String

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

static String

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

static String

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

static String

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

static String

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

static String

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

static String

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

static String

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

Public constructors

Interface for providing text classification related features.

Public methods

open TextClassification

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

open TextLinks
generateLinks(@NonNull request: TextLinks.Request)

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

open Int

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

open TextSelection

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

Properties

static TextClassifier!

No-op TextClassifier.

Constants

HINT_TEXT_IS_EDITABLE

static val HINT_TEXT_IS_EDITABLE: String

Designates that the text in question is editable.

Value: "android.text_is_editable"

HINT_TEXT_IS_NOT_EDITABLE

static val HINT_TEXT_IS_NOT_EDITABLE: String

Designates that the text in question is not editable.

Value: "android.text_is_not_editable"

TYPE_ADDRESS

static val TYPE_ADDRESS: String

Identifies a physical address.

Value: "address"

TYPE_DATE

static val TYPE_DATE: String

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

Value: "date"

TYPE_DATE_TIME

static val TYPE_DATE_TIME: String

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

Value: "datetime"

TYPE_EMAIL

static val TYPE_EMAIL: String

Identifies an e-mail address.

Value: "email"

TYPE_FLIGHT_NUMBER

static val TYPE_FLIGHT_NUMBER: String

Flight number in IATA format.

Value: "flight"

TYPE_OTHER

static val TYPE_OTHER: String

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

Value: "other"

TYPE_PHONE

static val TYPE_PHONE: String

Identifies a phone number.

Value: "phone"

TYPE_UNKNOWN

static val TYPE_UNKNOWN: String

Signifies that the TextClassifier did not identify an entity.

Value: ""

TYPE_URL

static val TYPE_URL: String

Identifies a URL.

Value: "url"

WIDGET_TYPE_CUSTOM_EDITTEXT

static val WIDGET_TYPE_CUSTOM_EDITTEXT: String

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

Value: "customedit"

WIDGET_TYPE_CUSTOM_TEXTVIEW

static val WIDGET_TYPE_CUSTOM_TEXTVIEW: String

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

Value: "customview"

WIDGET_TYPE_CUSTOM_UNSELECTABLE_TEXTVIEW

static val WIDGET_TYPE_CUSTOM_UNSELECTABLE_TEXTVIEW: String

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

Value: "nosel-customview"

WIDGET_TYPE_EDITTEXT

static val WIDGET_TYPE_EDITTEXT: String

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

Value: "edittext"

WIDGET_TYPE_EDIT_WEBVIEW

static val WIDGET_TYPE_EDIT_WEBVIEW: String

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

Value: "edit-webview"

WIDGET_TYPE_TEXTVIEW

static val WIDGET_TYPE_TEXTVIEW: String

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

Value: "textview"

WIDGET_TYPE_UNKNOWN

static val WIDGET_TYPE_UNKNOWN: String

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

Value: "unknown"

WIDGET_TYPE_UNSELECTABLE_TEXTVIEW

static val WIDGET_TYPE_UNSELECTABLE_TEXTVIEW: String

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

Value: "nosel-textview"

WIDGET_TYPE_WEBVIEW

static val WIDGET_TYPE_WEBVIEW: String

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

Value: "webview"

Public constructors

<init>

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.

Public methods

classifyText

@WorkerThread @NonNull open fun classifyText(@NonNull request: TextClassification.Request): TextClassification

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

generateLinks

@WorkerThread @NonNull open fun generateLinks(@NonNull request: TextLinks.Request): TextLinks

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

getMaxGenerateLinksTextLength

open fun getMaxGenerateLinksTextLength(): Int

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

suggestSelection

@WorkerThread @NonNull open fun suggestSelection(@NonNull request: TextSelection.Request): TextSelection

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

Properties

NO_OP

static val NO_OP: TextClassifier!

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