TextClassifier
interface TextClassifier
android.view.textclassifier.TextClassifier |
Interface for providing text classification related features.
The TextClassifier may be used to understand the meaning of text, as well as generating predicted next actions based on the text.
NOTE: Unless otherwise stated, methods of this interface are blocking operations. Call on a worker thread.
Summary
Nested classes | |
---|---|
Configuration object for specifying what entity types to identify. |
Constants | |
---|---|
static String |
Extra that is included on activity intents coming from a TextClassifier when it suggests actions to its caller. |
static String |
Designates that the text in question is editable. |
static String |
Designates that the text in question is not editable. |
static String |
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 |
E-mail address (e.g. "noreply@android.com"). |
static String |
Flight number in IATA format. |
static String |
The classifier ran, but didn't recognize a known entity. |
static String |
Phone number (e.g. "555-123 456"). |
static String |
The TextClassifier failed to run. |
static String |
Web URL. |
static String |
The text classification context is for use with the system clipboard. |
static String |
The widget involved in the text classification context is a custom editable text widget. |
static String |
The widget involved in the text classification context is a custom text widget. |
static String |
The widget involved in the text classification context is a custom non-selectable text widget. |
static String |
The widget involved in the text classification context is a standard |
static String |
The widget involved in the text classification context is a standard editable |
static String |
The widget involved in the text classification context is a notification |
static String |
The widget involved in the text classification context is a standard |
static String |
The widget involved in the text classification context is of an unknown/unspecified type. |
static String |
The widget involved in the text classification context is a standard non-selectable |
static String |
The widget involved in the text classification context is a standard |
Public methods | |
---|---|
open TextClassification |
classifyText(request: TextClassification.Request) Classifies the specified text and returns a |
open TextClassification |
classifyText(text: CharSequence, startIndex: Int, endIndex: Int, defaultLocales: LocaleList?) Classifies the specified text and returns a |
open Unit |
destroy() Destroys this TextClassifier. |
open TextLanguage |
detectLanguage(request: TextLanguage.Request) Detects the language of the text in the given request. |
open TextLinks |
generateLinks(request: TextLinks.Request) Generates and returns a |
open Int |
Returns the maximal length of text that can be processed by generateLinks. |
open Boolean |
Returns whether or not this TextClassifier has been destroyed. |
open Unit |
onSelectionEvent(event: SelectionEvent) NOTE: Use |
open Unit |
Reports a text classifier event. |
open ConversationActions |
Suggests and returns a list of actions according to the given conversation. |
open TextSelection |
suggestSelection(request: TextSelection.Request) Returns suggested text selection start and end indices, recognized entity types, and their associated confidence scores. |
open TextSelection |
suggestSelection(text: CharSequence, selectionStartIndex: Int, selectionEndIndex: Int, defaultLocales: LocaleList?) Returns suggested text selection start and end indices, recognized entity types, and their associated confidence scores. |
Properties | |
---|---|
static TextClassifier! |
No-op TextClassifier. |
Constants
EXTRA_FROM_TEXT_CLASSIFIER
static val EXTRA_FROM_TEXT_CLASSIFIER: String
Extra that is included on activity intents coming from a TextClassifier when it suggests actions to its caller.
All TextClassifier
implementations should make sure this extra exists in their generated intents.
Value: "android.view.textclassifier.extra.FROM_TEXT_CLASSIFIER"
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
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
E-mail address (e.g. "noreply@android.com").
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
The classifier ran, but didn't recognize a known entity.
Value: "other"
TYPE_PHONE
static val TYPE_PHONE: String
Phone number (e.g. "555-123 456").
Value: "phone"
TYPE_UNKNOWN
static val TYPE_UNKNOWN: String
The TextClassifier failed to run.
Value: ""
WIDGET_TYPE_CLIPBOARD
static val WIDGET_TYPE_CLIPBOARD: String
The text classification context is for use with the system clipboard.
Value: "clipboard"
WIDGET_TYPE_CUSTOM_EDITTEXT
static val WIDGET_TYPE_CUSTOM_EDITTEXT: String
The widget involved in the text classification context 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 context 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 context 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 context 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 context is a standard editable android.webkit.WebView
.
Value: "edit-webview"
WIDGET_TYPE_NOTIFICATION
static val WIDGET_TYPE_NOTIFICATION: String
The widget involved in the text classification context is a notification
Value: "notification"
WIDGET_TYPE_TEXTVIEW
static val WIDGET_TYPE_TEXTVIEW: String
The widget involved in the text classification context is a standard android.widget.TextView
.
Value: "textview"
WIDGET_TYPE_UNKNOWN
static val WIDGET_TYPE_UNKNOWN: String
The widget involved in the text classification context 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 context 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 context is a standard android.webkit.WebView
.
Value: "webview"
Public methods
classifyText
open fun classifyText(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.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
request |
TextClassification.Request: the text classification request This value cannot be null . |
Return | |
---|---|
TextClassification |
This value cannot be null . |
classifyText
open fun classifyText(
text: CharSequence,
startIndex: Int,
endIndex: Int,
defaultLocales: LocaleList?
): 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.
NOTE: Do not implement. The default implementation of this method calls classifyText(android.view.textclassifier.TextClassification.Request)
. If that method calls this method, a stack overflow error will happen.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
text |
CharSequence: text providing context for the text to classify (which is specified by the sub sequence starting at startIndex and ending at endIndex) This value cannot be null . |
startIndex |
Int: start index of the text to classify Value is 0 or greater |
endIndex |
Int: end index of the text to classify Value is 0 or greater |
defaultLocales |
LocaleList?: ordered list of locale preferences that may be used to disambiguate the provided text. If no locale preferences exist, set this to null or an empty locale list. |
Return | |
---|---|
TextClassification |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if text is null; startIndex is negative; endIndex is greater than text.length() or not greater than startIndex |
destroy
open fun destroy(): Unit
Destroys this TextClassifier.
NOTE: If a TextClassifier has been destroyed, calls to its methods should throw an IllegalStateException
. See isDestroyed()
.
Subsequent calls to this method are no-ops.
detectLanguage
open fun detectLanguage(request: TextLanguage.Request): TextLanguage
Detects the language of the text in the given request.
NOTE: Call on a worker thread.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
request |
TextLanguage.Request: the TextLanguage request. This value cannot be null . |
Return | |
---|---|
TextLanguage |
the TextLanguage result. This value cannot be null . |
generateLinks
open fun generateLinks(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.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
request |
TextLinks.Request: the text links request This value cannot be null . |
Return | |
---|---|
TextLinks |
This value cannot be null . |
See Also
getMaxGenerateLinksTextLength
open fun getMaxGenerateLinksTextLength(): Int
Returns the maximal length of text that can be processed by generateLinks.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
This method may take several seconds to complete, so it should only be called from a worker thread.
See Also
isDestroyed
open fun isDestroyed(): Boolean
Returns whether or not this TextClassifier has been destroyed.
NOTE: If a TextClassifier has been destroyed, caller should not interact with the classifier and an attempt to do so would throw an IllegalStateException
. However, this method should never throw an IllegalStateException
.
See Also
onSelectionEvent
open fun onSelectionEvent(event: SelectionEvent): Unit
NOTE: Use onTextClassifierEvent(android.view.textclassifier.TextClassifierEvent)
instead.
Reports a selection event.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
Parameters | |
---|---|
event |
SelectionEvent: This value cannot be null . |
onTextClassifierEvent
open fun onTextClassifierEvent(event: TextClassifierEvent): Unit
Reports a text classifier event.
NOTE: Call on a worker thread.
Parameters | |
---|---|
event |
TextClassifierEvent: This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if this TextClassifier has been destroyed. |
See Also
suggestConversationActions
open fun suggestConversationActions(request: ConversationActions.Request): ConversationActions
Suggests and returns a list of actions according to the given conversation.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
request |
ConversationActions.Request: This value cannot be null . |
Return | |
---|---|
ConversationActions |
This value cannot be null . |
suggestSelection
open fun suggestSelection(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.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
request |
TextSelection.Request: the text selection request This value cannot be null . |
Return | |
---|---|
TextSelection |
This value cannot be null . |
suggestSelection
open fun suggestSelection(
text: CharSequence,
selectionStartIndex: Int,
selectionEndIndex: Int,
defaultLocales: LocaleList?
): 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.
NOTE: If a TextClassifier has been destroyed, calls to this method should throw an IllegalStateException
. See isDestroyed()
.
NOTE: Do not implement. The default implementation of this method calls suggestSelection(android.view.textclassifier.TextSelection.Request)
. If that method calls this method, a stack overflow error will happen.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
text |
CharSequence: text providing context for the selected text (which is specified by the sub sequence starting at selectionStartIndex and ending at selectionEndIndex) This value cannot be null . |
selectionStartIndex |
Int: start index of the selected part of text Value is 0 or greater |
selectionEndIndex |
Int: end index of the selected part of text Value is 0 or greater |
defaultLocales |
LocaleList?: ordered list of locale preferences that may be used to disambiguate the provided text. If no locale preferences exist, set this to null or an empty locale list. |
Return | |
---|---|
TextSelection |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if text is null; selectionStartIndex is negative; selectionEndIndex is greater than text.length() or not greater than selectionStartIndex |
Properties
NO_OP
static val NO_OP: TextClassifier!
No-op TextClassifier. This may be used to turn off TextClassifier features.