summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorAbodunrinwa Toki <toki@google.com>2017-03-14 21:56:31 +0000
committerAbodunrinwa Toki <toki@google.com>2017-03-15 17:17:36 +0000
commit7d9b297f8cb4a02e6cdddbbe1bc380e5412e511c (patch)
tree8446fead07f9cb7fbfc0fdbc3b55d92c1e692c31 /core/java/android
parentf33a0379070b567f33269a879c9ba9a7aa279d5d (diff)
Fix selected entity type.
This should be the highest scoring one, not the first one. Test: cts-tradefed run cts-dev -m CtsViewTestCases -t android.view.textclassifier.cts.TextClassificationManagerTest Change-Id: Ib790d8aa4aeccdd7a7972eaa6c04ed4fc69ad00e
Diffstat (limited to 'core/java/android')
-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));