class TextClassification


Information for generating a widget to handle classified text.

A TextClassification object contains icons, labels, and intents that may be used to build a widget that can be used to act on classified text.

e.g. building a menu that allows the user how to act on a piece of text:

  // Called preferably outside the UiThread.
  TextClassification classification = textClassifier.classifyText(allText, 10, 25);

  // Called on the UiThread.
  for (RemoteActionCompat action : classification.getActions()) {
      MenuItem item = menu.add(action.getTitle());
      item.setContentDescription(action.getContentDescription());
      item.setOnMenuItemClickListener(v -> action.getActionIntent().send());
      if (action.shouldShowIcon()) {
          item.setIcon(action.getIcon().loadDrawable(context));
      }
  }

Summary

Nested types

Builder for building TextClassification objects.

This class is deprecated.

Use android.view.textclassifier.TextClassification.Request instead.

This class is deprecated.

Use android.view.textclassifier.TextClassification.Builder instead.

Public functions

java-static TextClassification

Extracts a classification from a bundle that was added using toBundle.

(Mutable)List<RemoteActionCompat!>

Returns a list of actions that may be performed on the text.

@FloatRange(from = 0.0, to = 1.0) Float

Returns the confidence score for the specified entity.

String

Returns the entity type at the specified index.

@IntRange(from = 0) Int

Returns the number of entity types found in the classified text.

Bundle

Returns the extended, vendor specific data.

String?

Returns the id for this object.

CharSequence?

Gets the classified text.

Bundle

Adds this classification to a Bundle that can be read back with the same parameters to createFromBundle.

String!

Public functions

createFromBundle

java-static fun createFromBundle(bundle: Bundle): TextClassification

Extracts a classification from a bundle that was added using toBundle.

getActions

fun getActions(): (Mutable)List<RemoteActionCompat!>

Returns a list of actions that may be performed on the text. The list is ordered based on the likelihood that a user will use the action, with the most likely action appearing first.

getConfidenceScore

fun getConfidenceScore(entity: String!): @FloatRange(from = 0.0, to = 1.0) Float

Returns the confidence score for the specified entity. The value ranges from 0 (low confidence) to 1 (high confidence). 0 indicates that the entity was not found for the classified text.

getEntityType

fun getEntityType(index: Int): String

Returns the entity type at the specified index. Entities are ordered from high confidence to low confidence.

Throws
java.lang.IndexOutOfBoundsException

if the specified index is out of range.

See also
getEntityTypeCount

for the number of entities available.

getEntityTypeCount

fun getEntityTypeCount(): @IntRange(from = 0) Int

Returns the number of entity types found in the classified text.

getExtras

fun getExtras(): Bundle

Returns the extended, vendor specific data.

NOTE: Each call to this method returns a new bundle copy so clients should prefer to hold a reference to the returned bundle rather than frequently calling this method. Avoid updating the content of this bundle. On pre-O devices, the values in the Bundle are not deep copied.

getId

fun getId(): String?

Returns the id for this object.

getText

fun getText(): CharSequence?

Gets the classified text.

toBundle

fun toBundle(): Bundle

Adds this classification to a Bundle that can be read back with the same parameters to createFromBundle.

toString

fun toString(): String!