TextClassifier
public
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 | |
---|---|
class |
TextClassifier.EntityConfig
Configuration object for specifying what entity types to identify. |
Constants | |
---|---|
String |
EXTRA_FROM_TEXT_CLASSIFIER
Extra that is included on activity intents coming from a TextClassifier when it suggests actions to its caller. |
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
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
E-mail address (e.g. "noreply@android.com"). |
String |
TYPE_FLIGHT_NUMBER
Flight number in IATA format. |
String |
TYPE_OTHER
The classifier ran, but didn't recognize a known entity. |
String |
TYPE_PHONE
Phone number (e.g. "555-123 456"). |
String |
TYPE_UNKNOWN
The TextClassifier failed to run. |
String |
TYPE_URL
Web URL. |
String |
WIDGET_TYPE_CLIPBOARD
The text classification context is for use with the system clipboard. |
String |
WIDGET_TYPE_CUSTOM_EDITTEXT
The widget involved in the text classification context is a custom editable text widget. |
String |
WIDGET_TYPE_CUSTOM_TEXTVIEW
The widget involved in the text classification context is a custom text widget. |
String |
WIDGET_TYPE_CUSTOM_UNSELECTABLE_TEXTVIEW
The widget involved in the text classification context is a custom non-selectable text widget. |
String |
WIDGET_TYPE_EDITTEXT
The widget involved in the text classification context is a standard
|
String |
WIDGET_TYPE_EDIT_WEBVIEW
The widget involved in the text classification context is a standard editable
|
String |
WIDGET_TYPE_NOTIFICATION
The widget involved in the text classification context is a notification |
String |
WIDGET_TYPE_TEXTVIEW
The widget involved in the text classification context is a standard
|
String |
WIDGET_TYPE_UNKNOWN
The widget involved in the text classification context is of an unknown/unspecified type. |
String |
WIDGET_TYPE_UNSELECTABLE_TEXTVIEW
The widget involved in the text classification context is a standard non-selectable
|
String |
WIDGET_TYPE_WEBVIEW
The widget involved in the text classification context is a standard
|
Fields | |
---|---|
public
static
final
TextClassifier |
NO_OP
No-op TextClassifier. |
Public methods | |
---|---|
default
TextClassification
|
classifyText(TextClassification.Request request)
Classifies the specified text and returns a |
default
TextClassification
|
classifyText(CharSequence text, int startIndex, int endIndex, LocaleList defaultLocales)
Classifies the specified text and returns a |
default
void
|
destroy()
Destroys this TextClassifier. |
default
TextLanguage
|
detectLanguage(TextLanguage.Request request)
Detects the language of the text in the given request. |
default
TextLinks
|
generateLinks(TextLinks.Request request)
Generates and returns a |
default
int
|
getMaxGenerateLinksTextLength()
Returns the maximal length of text that can be processed by generateLinks. |
default
boolean
|
isDestroyed()
Returns whether or not this TextClassifier has been destroyed. |
default
void
|
onSelectionEvent(SelectionEvent event)
NOTE: Use |
default
void
|
onTextClassifierEvent(TextClassifierEvent event)
Reports a text classifier event. |
default
ConversationActions
|
suggestConversationActions(ConversationActions.Request request)
Suggests and returns a list of actions according to the given conversation. |
default
TextSelection
|
suggestSelection(CharSequence text, int selectionStartIndex, int selectionEndIndex, LocaleList defaultLocales)
Returns suggested text selection start and end indices, recognized entity types, and their associated confidence scores. |
default
TextSelection
|
suggestSelection(TextSelection.Request request)
Returns suggested text selection start and end indices, recognized entity types, and their associated confidence scores. |
Constants
EXTRA_FROM_TEXT_CLASSIFIER
public static final String EXTRA_FROM_TEXT_CLASSIFIER
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.
Constant Value: "android.view.textclassifier.extra.FROM_TEXT_CLASSIFIER"
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
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
E-mail address (e.g. "noreply@android.com").
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
The classifier ran, but didn't recognize a known entity.
Constant Value: "other"
TYPE_PHONE
public static final String TYPE_PHONE
Phone number (e.g. "555-123 456").
Constant Value: "phone"
TYPE_UNKNOWN
public static final String TYPE_UNKNOWN
The TextClassifier failed to run.
Constant Value: ""
WIDGET_TYPE_CLIPBOARD
public static final String WIDGET_TYPE_CLIPBOARD
The text classification context is for use with the system clipboard.
Constant Value: "clipboard"
WIDGET_TYPE_CUSTOM_EDITTEXT
public static final String WIDGET_TYPE_CUSTOM_EDITTEXT
The widget involved in the text classification context 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 context 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 context 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 context 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 context is a standard editable
WebView
.
Constant Value: "edit-webview"
WIDGET_TYPE_NOTIFICATION
public static final String WIDGET_TYPE_NOTIFICATION
The widget involved in the text classification context is a notification
Constant Value: "notification"
WIDGET_TYPE_TEXTVIEW
public static final String WIDGET_TYPE_TEXTVIEW
The widget involved in the text classification context is a standard
TextView
.
Constant Value: "textview"
WIDGET_TYPE_UNKNOWN
public static final String WIDGET_TYPE_UNKNOWN
The widget involved in the text classification context 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 context 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 context 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 TextClassifier features.
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.
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 . |
Returns | |
---|---|
TextClassification |
This value cannot be null . |
classifyText
public TextClassification classifyText (CharSequence text, int startIndex, int endIndex, LocaleList defaultLocales)
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. |
Returns | |
---|---|
TextClassification |
This value cannot be null . |
Throws | |
---|---|
IllegalArgumentException |
if text is null; startIndex is negative; endIndex is greater than text.length() or not greater than startIndex |
See also:
destroy
public void destroy ()
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
public TextLanguage detectLanguage (TextLanguage.Request request)
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 . |
Returns | |
---|---|
TextLanguage |
the TextLanguage result.
This value cannot be null . |
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.
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 . |
Returns | |
---|---|
TextLinks |
This value cannot be null . |
See also:
getMaxGenerateLinksTextLength
public int getMaxGenerateLinksTextLength ()
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.
Returns | |
---|---|
int |
See also:
isDestroyed
public boolean isDestroyed ()
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
.
Returns | |
---|---|
boolean |
See also:
onSelectionEvent
public void onSelectionEvent (SelectionEvent event)
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
public void onTextClassifierEvent (TextClassifierEvent event)
Reports a text classifier event.
NOTE: Call on a worker thread.
Parameters | |
---|---|
event |
TextClassifierEvent : This value cannot be null . |
Throws | |
---|---|
IllegalStateException |
if this TextClassifier has been destroyed. |
See also:
suggestConversationActions
public ConversationActions suggestConversationActions (ConversationActions.Request request)
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 . |
Returns | |
---|---|
ConversationActions |
This value cannot be null . |
suggestSelection
public TextSelection suggestSelection (CharSequence text, int selectionStartIndex, int selectionEndIndex, LocaleList defaultLocales)
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. |
Returns | |
---|---|
TextSelection |
This value cannot be null . |
Throws | |
---|---|
IllegalArgumentException |
if text is null; selectionStartIndex is negative; selectionEndIndex is greater than text.length() or not greater than selectionStartIndex |
See also:
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.
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 . |
Returns | |
---|---|
TextSelection |
This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.