summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-03-15 19:03:06 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-03-15 19:03:09 +0000
commita20bdb130b6d557dbb077faa20b2038b67b38932 (patch)
tree02a325094c2bcc0c06ad4d1b755be035a5a66484
parent5fff20cac1da9a6105673fb1e4fc49e2e3f269e9 (diff)
parent7d9b297f8cb4a02e6cdddbbe1bc380e5412e511c (diff)
Merge "Fix selected entity type."
-rw-r--r--core/java/android/view/textclassifier/TextClassifierImpl.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/core/java/android/view/textclassifier/TextClassifierImpl.java b/core/java/android/view/textclassifier/TextClassifierImpl.java
index c95a1fb966f5..06ac8699f864 100644
--- a/core/java/android/view/textclassifier/TextClassifierImpl.java
+++ b/core/java/android/view/textclassifier/TextClassifierImpl.java
@@ -121,8 +121,8 @@ final class TextClassifierImpl implements TextClassifier {
.classifyText(text.toString(), startIndex, endIndex);
if (results.length > 0) {
// TODO: Added this log for debug only. Remove before release.
- Log.d(LOG_TAG,
- String.format("Classification type: %s", results[0].mCollection));
+ Log.d(LOG_TAG, String.format(
+ "Classification type: %s", getHighestScoringType(results)));
return createClassificationResult(results, classified);
}
}
@@ -188,7 +188,7 @@ final class TextClassifierImpl implements TextClassifier {
builder.setEntityType(classifications[i].mCollection, classifications[i].mScore);
}
- final String type = classifications[0].mCollection;
+ final String type = getHighestScoringType(classifications);
final Intent intent = IntentFactory.create(mContext, type, text.toString());
final PackageManager pm;
final ResolveInfo resolveInfo;
@@ -226,6 +226,23 @@ final class TextClassifierImpl implements TextClassifier {
return builder.build();
}
+ private static String getHighestScoringType(SmartSelection.ClassificationResult[] types) {
+ if (types.length < 1) {
+ return "";
+ }
+
+ String type = types[0].mCollection;
+ float highestScore = types[0].mScore;
+ final int size = types.length;
+ for (int i = 1; i < size; i++) {
+ if (types[i].mScore > highestScore) {
+ type = types[i].mCollection;
+ highestScore = types[i].mScore;
+ }
+ }
+ return type;
+ }
+
/**
* @throws IllegalArgumentException if text is null; startIndex is negative;
* endIndex is greater than text.length() or is not greater than startIndex
@@ -265,7 +282,7 @@ final class TextClassifierImpl implements TextClassifier {
final SmartSelection.ClassificationResult[] results =
smartSelection.classifyText(text, selectionStart, selectionEnd);
if (results.length > 0) {
- final String type = results[0].mCollection;
+ final String type = getHighestScoringType(results);
if (matches(type, linkMask)) {
final Intent intent = IntentFactory.create(
context, type, text.substring(selectionStart, selectionEnd));