Commit b3076f00 authored by Li Lin's avatar Li Lin Committed by Commit Bot

Allow extra chars for definition intent selection.

Also changed to check the threshold with character size instead of byte
size.

Bug: b/160639930
Test: unit tests
Change-Id: I0cefba23ef46ce7bda7ccb57adf3c46481f0d389
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285509Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Li Lin <llin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786340}
parent 6ac319a0
......@@ -27,7 +27,7 @@ using machine_learning::mojom::TextClassifier;
// TODO(llin): Finalize on the threshold based on user feedback.
constexpr int kUnitConversionIntentAndSelectionLengthDiffThreshold = 5;
constexpr int kTranslationTextLengthThreshold = 50;
constexpr int kDefinitionIntentAndSelectionLengthDiffThreshold = 0;
constexpr int kDefinitionIntentAndSelectionLengthDiffThreshold = 2;
const std::map<std::string, IntentType>& GetIntentTypeMap() {
static base::NoDestructor<std::map<std::string, IntentType>> kIntentTypeMap(
......@@ -65,8 +65,8 @@ IntentType RewriteIntent(const std::string& selected_text,
const std::string& entity_str,
const IntentType intent) {
int intent_and_selection_length_diff =
selected_text.length() - entity_str.length();
base::UTF8ToUTF16(selected_text).length() -
base::UTF8ToUTF16(entity_str).length();
if ((intent == IntentType::kUnit &&
intent_and_selection_length_diff >
kUnitConversionIntentAndSelectionLengthDiffThreshold) ||
......
......@@ -203,7 +203,38 @@ TEST_F(IntentGeneratorTest, TextAnnotationDefinitionIntent) {
EXPECT_EQ("unfathomable", intent_text_);
}
TEST_F(IntentGeneratorTest, TextAnnotationDefinitionIntentExtraChars) {
TEST_F(IntentGeneratorTest,
TextAnnotationDefinitionIntentExtraCharsBelowThreshold) {
std::unique_ptr<QuickAnswersRequest> quick_answers_request =
std::make_unique<QuickAnswersRequest>();
quick_answers_request->selected_text = "“unfathomable”";
// Create the test annotations.
std::vector<TextEntityPtr> entities;
entities.emplace_back(
TextEntity::New("dictionary", // Entity name.
1.0, // Confidence score.
TextEntityData::New())); // Data extracted.
auto dictionary_annotation = TextAnnotation::New(1, // Start offset.
13, // End offset.
std::move(entities));
std::vector<TextAnnotationPtr> annotations;
annotations.push_back(dictionary_annotation->Clone());
UseFakeServiceConnection(annotations);
intent_generator_->GenerateIntent(*quick_answers_request);
task_environment_.RunUntilIdle();
EXPECT_EQ(IntentType::kDictionary, intent_type_);
EXPECT_EQ("unfathomable", intent_text_);
}
TEST_F(IntentGeneratorTest,
TextAnnotationDefinitionIntentExtraCharsAboveThreshold) {
std::unique_ptr<QuickAnswersRequest> quick_answers_request =
std::make_unique<QuickAnswersRequest>();
quick_answers_request->selected_text = "the unfathomable";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment