• Home
  • Raw
  • Download

Lines Matching +full:actions +full:- +full:builder

8  *      http://www.apache.org/licenses/LICENSE-2.0
17 #include "actions/actions-suggestions.h"
24 #include "actions/actions_model_generated.h"
25 #include "actions/test-utils.h"
26 #include "actions/zlib-utils.h"
32 #include "utils/grammar/utils/locale-shard-map.h"
35 #include "utils/jvm-test-utils.h"
36 #include "utils/test-data-test-utils.h"
76 std::string GetModelPath() { return GetTestDataPath("actions/test_data/"); } in GetModelPath()
110 actions_suggestions->SuggestActions( in TEST_F()
115 EXPECT_THAT(response.actions, IsEmpty()); in TEST_F()
123 actions_suggestions->SuggestActions( in TEST_F()
125 "(857) 225-3556 \xed\xa0\x80\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80", in TEST_F()
129 EXPECT_THAT(response.actions, IsEmpty()); in TEST_F()
136 actions_suggestions->SuggestActions( in TEST_F()
140 EXPECT_EQ(response.actions.size(), 3 /* share_location + 2 smart replies*/); in TEST_F()
147 actions_suggestions->SuggestActions( in TEST_F()
151 EXPECT_THAT(response.actions, testing::IsEmpty()); in TEST_F()
161 actions_suggestions->SuggestActions( in TEST_F()
167 ASSERT_GE(response.actions.size(), 1); in TEST_F()
168 EXPECT_EQ(response.actions.front().type, "view_map"); in TEST_F()
169 EXPECT_EQ(response.actions.front().score, 1.0); in TEST_F()
179 // Set custom actions from annotations config. in TEST_F()
180 actions_model->annotation_actions_spec->annotation_mapping.clear(); in TEST_F()
181 actions_model->annotation_actions_spec->annotation_mapping.emplace_back( in TEST_F()
184 actions_model->annotation_actions_spec->annotation_mapping.back().get(); in TEST_F()
185 mapping->annotation_collection = "address"; in TEST_F()
186 mapping->action.reset(new ActionSuggestionSpecT); in TEST_F()
187 mapping->action->type = "save_location"; in TEST_F()
188 mapping->action->score = 1.0; in TEST_F()
189 mapping->action->priority_score = 2.0; in TEST_F()
190 mapping->entity_field.reset(new FlatbufferFieldPathT); in TEST_F()
191 mapping->entity_field->field.emplace_back(new FlatbufferFieldT); in TEST_F()
192 mapping->entity_field->field.back()->field_name = "location"; in TEST_F()
194 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
195 FinishActionsModelBuffer(builder, in TEST_F()
196 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
199 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
200 builder.GetSize(), unilib_.get()); in TEST_F()
206 actions_suggestions->SuggestActions( in TEST_F()
212 ASSERT_GE(response.actions.size(), 1); in TEST_F()
213 EXPECT_EQ(response.actions.front().type, "save_location"); in TEST_F()
214 EXPECT_EQ(response.actions.front().score, 1.0); in TEST_F()
220 response.actions.front().serialized_entity_data.data())); in TEST_F()
221 EXPECT_EQ(entity->GetPointer<const flatbuffers::String*>(/*field=*/6)->str(), in TEST_F()
233 // Set custom actions from annotations config. in TEST_F()
234 actions_model->annotation_actions_spec->annotation_mapping.clear(); in TEST_F()
235 actions_model->annotation_actions_spec->annotation_mapping.emplace_back( in TEST_F()
238 actions_model->annotation_actions_spec->annotation_mapping.back().get(); in TEST_F()
239 mapping->annotation_collection = "address"; in TEST_F()
240 mapping->action.reset(new ActionSuggestionSpecT); in TEST_F()
241 mapping->action->type = "save_location"; in TEST_F()
242 mapping->action->score = 1.0; in TEST_F()
243 mapping->action->priority_score = 2.0; in TEST_F()
244 mapping->entity_field.reset(new FlatbufferFieldPathT); in TEST_F()
245 mapping->entity_field->field.emplace_back(new FlatbufferFieldT); in TEST_F()
246 mapping->entity_field->field.back()->field_name = "location"; in TEST_F()
247 mapping->normalization_options.reset(new NormalizationOptionsT); in TEST_F()
248 mapping->normalization_options->codepointwise_normalization = in TEST_F()
251 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
252 FinishActionsModelBuffer(builder, in TEST_F()
253 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
256 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
257 builder.GetSize(), unilib_.get()); in TEST_F()
263 actions_suggestions->SuggestActions( in TEST_F()
269 ASSERT_GE(response.actions.size(), 1); in TEST_F()
270 EXPECT_EQ(response.actions.front().type, "save_location"); in TEST_F()
271 EXPECT_EQ(response.actions.front().score, 1.0); in TEST_F()
277 response.actions.front().serialized_entity_data.data())); in TEST_F()
278 EXPECT_EQ(entity->GetPointer<const flatbuffers::String*>(/*field=*/6)->str(), in TEST_F()
296 actions_suggestions->SuggestActions( in TEST_F()
305 ASSERT_GE(response.actions.size(), 2); in TEST_F()
306 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
307 EXPECT_EQ(response.actions[0].score, 3.0); in TEST_F()
308 EXPECT_EQ(response.actions[1].type, "send_email"); in TEST_F()
309 EXPECT_EQ(response.actions[1].score, 2.0); in TEST_F()
318 actions_model->annotation_actions_spec->deduplicate_annotations = false; in TEST_F()
319 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
320 FinishActionsModelBuffer(builder, in TEST_F()
321 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
324 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
325 builder.GetSize(), unilib_.get()); in TEST_F()
337 actions_suggestions->SuggestActions( in TEST_F()
346 ASSERT_GE(response.actions.size(), 3); in TEST_F()
347 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
348 EXPECT_EQ(response.actions[0].score, 3.0); in TEST_F()
349 EXPECT_EQ(response.actions[1].type, "track_flight"); in TEST_F()
350 EXPECT_EQ(response.actions[1].score, 2.5); in TEST_F()
351 EXPECT_EQ(response.actions[2].type, "send_email"); in TEST_F()
352 EXPECT_EQ(response.actions[2].score, 2.0); in TEST_F()
367 actions_model->preconditions->min_smart_reply_triggering_score = 1.0; in TestSuggestActionsFromAnnotations()
369 flatbuffers::FlatBufferBuilder builder; in TestSuggestActionsFromAnnotations() local
370 FinishActionsModelBuffer(builder, in TestSuggestActionsFromAnnotations()
371 ActionsModel::Pack(builder, actions_model.get())); in TestSuggestActionsFromAnnotations()
374 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TestSuggestActionsFromAnnotations()
375 builder.GetSize(), unilib); in TestSuggestActionsFromAnnotations()
384 return actions_suggestions->SuggestActions( in TestSuggestActionsFromAnnotations()
418 actions_model->annotation_actions_spec->include_local_user_messages = in TEST_F()
420 actions_model->annotation_actions_spec->only_until_last_sent = true; in TEST_F()
421 actions_model->annotation_actions_spec->max_history_from_any_person = 1; in TEST_F()
422 actions_model->annotation_actions_spec->max_history_from_last_person = in TEST_F()
426 EXPECT_THAT(response.actions, SizeIs(1)); in TEST_F()
427 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
433 actions_model->annotation_actions_spec->include_local_user_messages = in TEST_F()
435 actions_model->annotation_actions_spec->only_until_last_sent = true; in TEST_F()
436 actions_model->annotation_actions_spec->max_history_from_any_person = 1; in TEST_F()
437 actions_model->annotation_actions_spec->max_history_from_last_person = in TEST_F()
441 EXPECT_THAT(response.actions, SizeIs(2)); in TEST_F()
442 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
443 EXPECT_EQ(response.actions[1].type, "send_email"); in TEST_F()
449 actions_model->annotation_actions_spec->include_local_user_messages = in TEST_F()
451 actions_model->annotation_actions_spec->only_until_last_sent = true; in TEST_F()
452 actions_model->annotation_actions_spec->max_history_from_any_person = 2; in TEST_F()
453 actions_model->annotation_actions_spec->max_history_from_last_person = in TEST_F()
457 EXPECT_THAT(response.actions, SizeIs(2)); in TEST_F()
458 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
459 EXPECT_EQ(response.actions[1].type, "send_email"); in TEST_F()
466 actions_model->annotation_actions_spec->include_local_user_messages = in TEST_F()
468 actions_model->annotation_actions_spec->only_until_last_sent = true; in TEST_F()
469 actions_model->annotation_actions_spec->max_history_from_any_person = 3; in TEST_F()
470 actions_model->annotation_actions_spec->max_history_from_last_person = in TEST_F()
474 EXPECT_THAT(response.actions, SizeIs(3)); in TEST_F()
475 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
476 EXPECT_EQ(response.actions[1].type, "send_email"); in TEST_F()
477 EXPECT_EQ(response.actions[2].type, "send_email"); in TEST_F()
484 actions_model->annotation_actions_spec->include_local_user_messages = in TEST_F()
486 actions_model->annotation_actions_spec->only_until_last_sent = true; in TEST_F()
487 actions_model->annotation_actions_spec->max_history_from_any_person = 5; in TEST_F()
488 actions_model->annotation_actions_spec->max_history_from_last_person = in TEST_F()
492 EXPECT_THAT(response.actions, SizeIs(3)); in TEST_F()
493 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
494 EXPECT_EQ(response.actions[1].type, "send_email"); in TEST_F()
495 EXPECT_EQ(response.actions[2].type, "send_email"); in TEST_F()
502 actions_model->annotation_actions_spec->include_local_user_messages = in TEST_F()
504 actions_model->annotation_actions_spec->only_until_last_sent = false; in TEST_F()
505 actions_model->annotation_actions_spec->max_history_from_any_person = 5; in TEST_F()
506 actions_model->annotation_actions_spec->max_history_from_last_person = in TEST_F()
510 EXPECT_THAT(response.actions, SizeIs(4)); in TEST_F()
511 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
512 EXPECT_EQ(response.actions[1].type, "send_email"); in TEST_F()
513 EXPECT_EQ(response.actions[2].type, "send_email"); in TEST_F()
514 EXPECT_EQ(response.actions[3].type, "send_email"); in TEST_F()
526 flatbuffers::FlatBufferBuilder builder; in TestSuggestActionsWithThreshold() local
527 FinishActionsModelBuffer(builder, in TestSuggestActionsWithThreshold()
528 ActionsModel::Pack(builder, actions_model.get())); in TestSuggestActionsWithThreshold()
531 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TestSuggestActionsWithThreshold()
532 builder.GetSize(), unilib, preconditions_overwrite); in TestSuggestActionsWithThreshold()
535 actions_suggestions->SuggestActions( in TestSuggestActionsWithThreshold()
536 {{{/*user_id=*/1, "I have the low-ground. Where are you?", in TestSuggestActionsWithThreshold()
540 EXPECT_LE(response.actions.size(), expected_size); in TestSuggestActionsWithThreshold()
546 actions_model->preconditions->min_smart_reply_triggering_score = 1.0; in TEST_F()
549 /*expected_size=*/1 /*no smart reply, only actions*/ in TEST_F()
556 actions_model->preconditions->min_reply_score_threshold = 1.0; in TEST_F()
559 /*expected_size=*/1 /*no smart reply, only actions*/ in TEST_F()
566 actions_model->preconditions->max_sensitive_topic_score = 0.0; in TEST_F()
575 actions_model->preconditions->max_input_length = 0; in TEST_F()
583 actions_model->preconditions->min_input_length = 100; in TEST_F()
591 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
592 builder.Finish( in TEST_F()
593 TriggeringPreconditions::Pack(builder, &preconditions_overwrite)); in TEST_F()
598 std::string(reinterpret_cast<const char*>(builder.GetBufferPointer()), in TEST_F()
599 builder.GetSize())); in TEST_F()
606 actions_model->preconditions->suppress_on_low_confidence_input = true; in TEST_F()
607 actions_model->low_confidence_rules.reset(new RulesModelT); in TEST_F()
608 actions_model->low_confidence_rules->regex_rule.emplace_back( in TEST_F()
610 actions_model->low_confidence_rules->regex_rule.back()->pattern = in TEST_F()
611 "low-ground"; in TEST_F()
622 actions_model->rules.reset(new RulesModelT()); in TEST_F()
623 actions_model->rules->regex_rule.emplace_back(new RulesModel_::RegexRuleT); in TEST_F()
624 RulesModel_::RegexRuleT* rule = actions_model->rules->regex_rule.back().get(); in TEST_F()
625 rule->pattern = "^(?i:hello\\s(there))$"; in TEST_F()
629 rule_action->action.reset(new ActionSuggestionSpecT); in TEST_F()
630 rule_action->action->type = "text_reply"; in TEST_F()
631 rule_action->action->response_text = "General Desaster!"; in TEST_F()
632 rule_action->action->score = 1.0f; in TEST_F()
633 rule_action->action->priority_score = 1.0f; in TEST_F()
634 rule->actions.push_back(std::move(rule_action)); in TEST_F()
639 rule_action->action.reset(new ActionSuggestionSpecT); in TEST_F()
640 rule_action->action->type = "text_reply"; in TEST_F()
641 rule_action->action->response_text = "General Kenobi!"; in TEST_F()
642 rule_action->action->score = 1.0f; in TEST_F()
643 rule_action->action->priority_score = 1.0f; in TEST_F()
644 rule->actions.push_back(std::move(rule_action)); in TEST_F()
647 // Add input-output low confidence rule. in TEST_F()
648 actions_model->preconditions->suppress_on_low_confidence_input = true; in TEST_F()
649 actions_model->low_confidence_rules.reset(new RulesModelT); in TEST_F()
650 actions_model->low_confidence_rules->regex_rule.emplace_back( in TEST_F()
652 actions_model->low_confidence_rules->regex_rule.back()->pattern = "hello"; in TEST_F()
653 actions_model->low_confidence_rules->regex_rule.back()->output_pattern = in TEST_F()
656 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
657 FinishActionsModelBuffer(builder, in TEST_F()
658 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
661 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
662 builder.GetSize(), unilib_.get()); in TEST_F()
665 actions_suggestions->SuggestActions( in TEST_F()
670 ASSERT_GE(response.actions.size(), 1); in TEST_F()
671 EXPECT_EQ(response.actions[0].response_text, "General Kenobi!"); in TEST_F()
680 actions_model->low_confidence_rules.reset(); in TEST_F()
683 actions_model->rules.reset(new RulesModelT()); in TEST_F()
684 actions_model->rules->regex_rule.emplace_back(new RulesModel_::RegexRuleT); in TEST_F()
685 RulesModel_::RegexRuleT* rule = actions_model->rules->regex_rule.back().get(); in TEST_F()
686 rule->pattern = "^(?i:hello\\s(there))$"; in TEST_F()
690 rule_action->action.reset(new ActionSuggestionSpecT); in TEST_F()
691 rule_action->action->type = "text_reply"; in TEST_F()
692 rule_action->action->response_text = "General Desaster!"; in TEST_F()
693 rule_action->action->score = 1.0f; in TEST_F()
694 rule_action->action->priority_score = 1.0f; in TEST_F()
695 rule->actions.push_back(std::move(rule_action)); in TEST_F()
700 rule_action->action.reset(new ActionSuggestionSpecT); in TEST_F()
701 rule_action->action->type = "text_reply"; in TEST_F()
702 rule_action->action->response_text = "General Kenobi!"; in TEST_F()
703 rule_action->action->score = 1.0f; in TEST_F()
704 rule_action->action->priority_score = 1.0f; in TEST_F()
705 rule->actions.push_back(std::move(rule_action)); in TEST_F()
709 actions_model->preconditions->low_confidence_rules.reset(); in TEST_F()
713 preconditions.low_confidence_rules->regex_rule.emplace_back( in TEST_F()
715 preconditions.low_confidence_rules->regex_rule.back()->pattern = "hello"; in TEST_F()
716 preconditions.low_confidence_rules->regex_rule.back()->output_pattern = in TEST_F()
725 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
726 FinishActionsModelBuffer(builder, in TEST_F()
727 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
730 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
731 builder.GetSize(), unilib_.get(), serialize_preconditions); in TEST_F()
735 actions_suggestions->SuggestActions( in TEST_F()
740 ASSERT_GE(response.actions.size(), 1); in TEST_F()
741 EXPECT_EQ(response.actions[0].response_text, "General Kenobi!"); in TEST_F()
752 if (actions_model->tflite_model_spec->output_sensitive_topic_score < 0) { in TEST_F()
756 actions_model->preconditions->max_sensitive_topic_score = 0.0; in TEST_F()
757 actions_model->preconditions->suppress_on_sensitive_topic = true; in TEST_F()
758 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
759 FinishActionsModelBuffer(builder, in TEST_F()
760 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
763 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
764 builder.GetSize(), unilib_.get()); in TEST_F()
770 actions_suggestions->SuggestActions( in TEST_F()
776 EXPECT_THAT(response.actions, testing::IsEmpty()); in TEST_F()
786 actions_model->max_conversation_history_length = 10; in TEST_F()
788 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
789 FinishActionsModelBuffer(builder, in TEST_F()
790 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
793 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
794 builder.GetSize(), unilib_.get()); in TEST_F()
800 actions_suggestions->SuggestActions( in TEST_F()
810 ASSERT_GE(response.actions.size(), 1); in TEST_F()
811 EXPECT_EQ(response.actions[0].type, "view_map"); in TEST_F()
812 EXPECT_EQ(response.actions[0].score, 1.0); in TEST_F()
819 actions_suggestions->SuggestActions( in TEST_F()
825 EXPECT_EQ(response.actions.size(), 4); in TEST_F()
826 EXPECT_EQ(response.actions[0].response_text, "Okay"); in TEST_F()
827 EXPECT_EQ(response.actions[0].type, "REPLY_SUGGESTION"); in TEST_F()
828 EXPECT_EQ(response.actions[3].type, "TEST_CLASSIFIER_INTENT"); in TEST_F()
838 actions_suggestions->SuggestActions( in TEST_F()
844 ASSERT_GE(response.actions.size(), 1); in TEST_F()
845 EXPECT_EQ(response.actions.front().type, "call_phone"); in TEST_F()
846 EXPECT_EQ(response.actions.front().score, 0.0); in TEST_F()
847 EXPECT_EQ(response.actions.front().priority_score, 0.0); in TEST_F()
848 EXPECT_EQ(response.actions.front().annotations.size(), 1); in TEST_F()
849 EXPECT_EQ(response.actions.front().annotations.front().span.span.first, 15); in TEST_F()
850 EXPECT_EQ(response.actions.front().annotations.front().span.span.second, 20); in TEST_F()
862 actions_suggestions->SuggestActions( in TEST_F()
869 ASSERT_GE(response.actions.size(), 2); in TEST_F()
870 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
871 EXPECT_EQ(response.actions[0].score, 1.0); in TEST_F()
872 EXPECT_THAT(response.actions[0].annotations, SizeIs(1)); in TEST_F()
873 EXPECT_EQ(response.actions[0].annotations[0].span.message_index, 0); in TEST_F()
874 EXPECT_EQ(response.actions[0].annotations[0].span.span, annotation.span); in TEST_F()
885 actions_model->rules.reset(new RulesModelT()); in TEST_F()
886 actions_model->rules->regex_rule.emplace_back(new RulesModel_::RegexRuleT); in TEST_F()
887 RulesModel_::RegexRuleT* rule = actions_model->rules->regex_rule.back().get(); in TEST_F()
888 rule->pattern = "^(?i:hello\\s(there))$"; in TEST_F()
889 rule->actions.emplace_back(new RulesModel_::RuleActionSpecT); in TEST_F()
890 rule->actions.back()->action.reset(new ActionSuggestionSpecT); in TEST_F()
891 ActionSuggestionSpecT* action = rule->actions.back()->action.get(); in TEST_F()
892 action->type = "text_reply"; in TEST_F()
893 action->response_text = "General Kenobi!"; in TEST_F()
894 action->score = 1.0f; in TEST_F()
895 action->priority_score = 1.0f; in TEST_F()
898 rule->actions.back()->capturing_group.emplace_back( in TEST_F()
901 rule->actions.back()->capturing_group.back().get(); in TEST_F()
902 greeting_group->group_id = 0; in TEST_F()
903 greeting_group->entity_field.reset(new FlatbufferFieldPathT); in TEST_F()
904 greeting_group->entity_field->field.emplace_back(new FlatbufferFieldT); in TEST_F()
905 greeting_group->entity_field->field.back()->field_name = "greeting"; in TEST_F()
906 rule->actions.back()->capturing_group.emplace_back( in TEST_F()
909 rule->actions.back()->capturing_group.back().get(); in TEST_F()
910 location_group->group_id = 1; in TEST_F()
911 location_group->entity_field.reset(new FlatbufferFieldPathT); in TEST_F()
912 location_group->entity_field->field.emplace_back(new FlatbufferFieldT); in TEST_F()
913 location_group->entity_field->field.back()->field_name = "location"; in TEST_F()
921 actions_model->actions_entity_data_schema.data())); in TEST_F()
924 entity_data->Set("person", "Kenobi"); in TEST_F()
925 action->serialized_entity_data = entity_data->Serialize(); in TEST_F()
927 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
928 FinishActionsModelBuffer(builder, in TEST_F()
929 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
932 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
933 builder.GetSize(), unilib_.get()); in TEST_F()
936 actions_suggestions->SuggestActions( in TEST_F()
940 EXPECT_GE(response.actions.size(), 1); in TEST_F()
941 EXPECT_EQ(response.actions[0].response_text, "General Kenobi!"); in TEST_F()
946 response.actions[0].serialized_entity_data.data())); in TEST_F()
947 EXPECT_EQ(entity->GetPointer<const flatbuffers::String*>(/*field=*/4)->str(), in TEST_F()
949 EXPECT_EQ(entity->GetPointer<const flatbuffers::String*>(/*field=*/6)->str(), in TEST_F()
951 EXPECT_EQ(entity->GetPointer<const flatbuffers::String*>(/*field=*/8)->str(), in TEST_F()
962 actions_model->rules.reset(new RulesModelT()); in TEST_F()
963 actions_model->rules->regex_rule.emplace_back(new RulesModel_::RegexRuleT); in TEST_F()
964 RulesModel_::RegexRuleT* rule = actions_model->rules->regex_rule.back().get(); in TEST_F()
965 rule->pattern = "^(?i:hello\\sthere)$"; in TEST_F()
966 rule->actions.emplace_back(new RulesModel_::RuleActionSpecT); in TEST_F()
967 rule->actions.back()->action.reset(new ActionSuggestionSpecT); in TEST_F()
968 ActionSuggestionSpecT* action = rule->actions.back()->action.get(); in TEST_F()
969 action->type = "text_reply"; in TEST_F()
970 action->response_text = "General Kenobi!"; in TEST_F()
971 action->score = 1.0f; in TEST_F()
972 action->priority_score = 1.0f; in TEST_F()
975 rule->actions.back()->capturing_group.emplace_back( in TEST_F()
978 rule->actions.back()->capturing_group.back().get(); in TEST_F()
979 greeting_group->group_id = 0; in TEST_F()
980 greeting_group->entity_field.reset(new FlatbufferFieldPathT); in TEST_F()
981 greeting_group->entity_field->field.emplace_back(new FlatbufferFieldT); in TEST_F()
982 greeting_group->entity_field->field.back()->field_name = "greeting"; in TEST_F()
983 greeting_group->normalization_options.reset(new NormalizationOptionsT); in TEST_F()
984 greeting_group->normalization_options->codepointwise_normalization = in TEST_F()
991 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
992 FinishActionsModelBuffer(builder, in TEST_F()
993 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
996 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
997 builder.GetSize(), unilib_.get()); in TEST_F()
1000 actions_suggestions->SuggestActions( in TEST_F()
1004 EXPECT_GE(response.actions.size(), 1); in TEST_F()
1005 EXPECT_EQ(response.actions[0].response_text, "General Kenobi!"); in TEST_F()
1010 response.actions[0].serialized_entity_data.data())); in TEST_F()
1011 EXPECT_EQ(entity->GetPointer<const flatbuffers::String*>(/*field=*/4)->str(), in TEST_F()
1022 actions_model->rules.reset(new RulesModelT()); in TEST_F()
1023 actions_model->rules->regex_rule.emplace_back(new RulesModel_::RegexRuleT); in TEST_F()
1024 RulesModel_::RegexRuleT* rule = actions_model->rules->regex_rule.back().get(); in TEST_F()
1025 rule->pattern = "(?i:reply (stop|quit|end) (?:to|for) )"; in TEST_F()
1026 rule->actions.emplace_back(new RulesModel_::RuleActionSpecT); in TEST_F()
1029 rule->actions.back()->capturing_group.emplace_back( in TEST_F()
1032 rule->actions.back()->capturing_group.back().get(); in TEST_F()
1033 code_group->group_id = 1; in TEST_F()
1034 code_group->text_reply.reset(new ActionSuggestionSpecT); in TEST_F()
1035 code_group->text_reply->score = 1.0f; in TEST_F()
1036 code_group->text_reply->priority_score = 1.0f; in TEST_F()
1037 code_group->normalization_options.reset(new NormalizationOptionsT); in TEST_F()
1038 code_group->normalization_options->codepointwise_normalization = in TEST_F()
1041 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
1042 FinishActionsModelBuffer(builder, in TEST_F()
1043 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
1046 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
1047 builder.GetSize(), unilib_.get()); in TEST_F()
1050 actions_suggestions->SuggestActions( in TEST_F()
1056 EXPECT_GE(response.actions.size(), 1); in TEST_F()
1057 EXPECT_EQ(response.actions[0].response_text, "stop"); in TEST_F()
1067 actions_model->rules->grammar_rules.reset(new RulesModel_::GrammarRulesT); in TEST_F()
1071 actions_model->rules->grammar_rules.get(); in TEST_F()
1072 action_grammar_rules->tokenizer_options.reset(new ActionsTokenizerOptionsT); in TEST_F()
1073 action_grammar_rules->tokenizer_options->type = TokenizationType_ICU; in TEST_F()
1074 action_grammar_rules->tokenizer_options->icu_preserve_whitespace_tokens = in TEST_F()
1078 action_grammar_rules->rules.reset(new grammar::RulesSetT); in TEST_F()
1088 action_grammar_rules->rules.get()); in TEST_F()
1089 action_grammar_rules->actions.emplace_back(new RulesModel_::RuleActionSpecT); in TEST_F()
1091 action_grammar_rules->actions.back().get(); in TEST_F()
1092 actions_spec->action.reset(new ActionSuggestionSpecT); in TEST_F()
1093 actions_spec->action->response_text = "Yes, Satan?"; in TEST_F()
1094 actions_spec->action->priority_score = 1.0; in TEST_F()
1095 actions_spec->action->score = 1.0; in TEST_F()
1096 actions_spec->action->type = "text_reply"; in TEST_F()
1097 action_grammar_rules->rule_match.emplace_back( in TEST_F()
1099 action_grammar_rules->rule_match.back()->action_id.push_back(0); in TEST_F()
1101 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
1102 FinishActionsModelBuffer(builder, in TEST_F()
1103 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
1106 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
1107 builder.GetSize(), unilib_.get()); in TEST_F()
1110 actions_suggestions->SuggestActions( in TEST_F()
1116 EXPECT_THAT(response.actions, ElementsAre(IsSmartReply("Yes, Satan?"))); in TEST_F()
1129 actions_model->rules->grammar_rules.reset(new RulesModel_::GrammarRulesT); in TEST_F()
1133 actions_model->rules->grammar_rules.get(); in TEST_F()
1134 action_grammar_rules->tokenizer_options.reset(new ActionsTokenizerOptionsT); in TEST_F()
1135 action_grammar_rules->tokenizer_options->type = TokenizationType_ICU; in TEST_F()
1136 action_grammar_rules->tokenizer_options->icu_preserve_whitespace_tokens = in TEST_F()
1140 action_grammar_rules->rules.reset(new grammar::RulesSetT); in TEST_F()
1152 action_grammar_rules->rules.get()); in TEST_F()
1153 action_grammar_rules->actions.emplace_back(new RulesModel_::RuleActionSpecT); in TEST_F()
1155 action_grammar_rules->actions.back().get(); in TEST_F()
1156 actions_spec->action.reset(new ActionSuggestionSpecT); in TEST_F()
1157 actions_spec->action->priority_score = 1.0; in TEST_F()
1158 actions_spec->action->score = 1.0; in TEST_F()
1159 actions_spec->action->type = "create_event"; in TEST_F()
1160 action_grammar_rules->rule_match.emplace_back( in TEST_F()
1162 action_grammar_rules->rule_match.back()->action_id.push_back(0); in TEST_F()
1164 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
1165 FinishActionsModelBuffer(builder, in TEST_F()
1166 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
1169 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
1170 builder.GetSize(), unilib_.get()); in TEST_F()
1173 actions_suggestions->SuggestActions( in TEST_F()
1180 EXPECT_THAT(response.actions, ElementsAre(IsActionOfType("create_event"))); in TEST_F()
1187 ActionsSuggestionsResponse response = actions_suggestions->SuggestActions( in TEST_F()
1194 for (const ActionSuggestion& action : response.actions) { in TEST_F()
1201 const int num_actions = response.actions.size(); in TEST_F()
1210 actions_model->rules.reset(new RulesModelT()); in TEST_F()
1211 actions_model->rules->regex_rule.emplace_back(new RulesModel_::RegexRuleT); in TEST_F()
1212 actions_model->rules->regex_rule.back()->pattern = in TEST_F()
1214 actions_model->rules->regex_rule.back()->actions.emplace_back( in TEST_F()
1216 actions_model->rules->regex_rule.back()->actions.back()->action.reset( in TEST_F()
1219 actions_model->rules->regex_rule.back()->actions.back()->action.get(); in TEST_F()
1220 action->score = 1.0f; in TEST_F()
1221 action->type = ActionsSuggestionsTypes::ShareLocation(); in TEST_F()
1223 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
1224 FinishActionsModelBuffer(builder, in TEST_F()
1225 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
1227 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
1228 builder.GetSize(), unilib_.get()); in TEST_F()
1230 response = actions_suggestions->SuggestActions( in TEST_F()
1234 EXPECT_THAT(response.actions, SizeIs(num_actions)); in TEST_F()
1244 ActionsSuggestionsResponse response = actions_suggestions->SuggestActions( in TEST_F()
1251 // Check that the phone actions are present. in TEST_F()
1252 EXPECT_GE(response.actions.size(), 1); in TEST_F()
1253 EXPECT_EQ(response.actions[0].type, "track_flight"); in TEST_F()
1262 actions_model->rules.reset(new RulesModelT()); in TEST_F()
1263 actions_model->rules->regex_rule.emplace_back(new RulesModel_::RegexRuleT); in TEST_F()
1264 RulesModel_::RegexRuleT* rule = actions_model->rules->regex_rule.back().get(); in TEST_F()
1265 rule->pattern = "^(?i:I'm on ([a-z0-9]+))$"; in TEST_F()
1266 rule->actions.emplace_back(new RulesModel_::RuleActionSpecT); in TEST_F()
1267 rule->actions.back()->action.reset(new ActionSuggestionSpecT); in TEST_F()
1268 ActionSuggestionSpecT* action = rule->actions.back()->action.get(); in TEST_F()
1269 action->score = 1.0f; in TEST_F()
1270 action->priority_score = 2.0f; in TEST_F()
1271 action->type = "test_code"; in TEST_F()
1272 rule->actions.back()->capturing_group.emplace_back( in TEST_F()
1275 rule->actions.back()->capturing_group.back().get(); in TEST_F()
1276 code_group->group_id = 1; in TEST_F()
1277 code_group->annotation_name = "code"; in TEST_F()
1278 code_group->annotation_type = "code"; in TEST_F()
1280 flatbuffers::FlatBufferBuilder builder; in TEST_F() local
1281 FinishActionsModelBuffer(builder, in TEST_F()
1282 ActionsModel::Pack(builder, actions_model.get())); in TEST_F()
1284 reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), in TEST_F()
1285 builder.GetSize(), unilib_.get()); in TEST_F()
1287 response = actions_suggestions->SuggestActions( in TEST_F()
1293 EXPECT_GE(response.actions.size(), 1); in TEST_F()
1294 EXPECT_EQ(response.actions[0].type, "test_code"); in TEST_F()
1307 actions_suggestions->SuggestActions( in TEST_F()
1313 EXPECT_GE(response.actions.size(), 2); in TEST_F()
1314 EXPECT_EQ(response.actions[0].type, "view_map"); in TEST_F()
1315 EXPECT_EQ(response.actions[0].score, 2.0); in TEST_F()
1316 EXPECT_EQ(response.actions[1].type, "view_map"); in TEST_F()
1317 EXPECT_EQ(response.actions[1].score, 1.0); in TEST_F()
1343 actions_suggestions->SuggestActions( in TEST_F()
1349 EXPECT_THAT(response.actions, testing::IsEmpty()); in TEST_F()
1353 actions_suggestions->SuggestActions( in TEST_F()
1360 response.actions, in TEST_F()
1365 actions_suggestions->SuggestActions( in TEST_F()
1372 response.actions, in TEST_F()
1406 model->feature_processor_options(); in TestingMessageEmbedder()
1410 EmbedTokenId(options->padding_token_id(), &embedded_padding_token_)); in TestingMessageEmbedder()
1411 EXPECT_TRUE(EmbedTokenId(options->start_token_id(), &embedded_start_token_)); in TestingMessageEmbedder()
1412 EXPECT_TRUE(EmbedTokenId(options->end_token_id(), &embedded_end_token_)); in TestingMessageEmbedder()
1413 token_embedding_size_ = feature_processor_->GetTokenEmbeddingSize(); in TestingMessageEmbedder()
1423 options_->chargram_orders = {1}; in EmbeddingTest()
1424 options_->num_buckets = 1000; in EmbeddingTest()
1425 options_->embedding_size = 1; in EmbeddingTest()
1426 options_->start_token_id = 0; in EmbeddingTest()
1427 options_->end_token_id = 1; in EmbeddingTest()
1428 options_->padding_token_id = 2; in EmbeddingTest()
1429 options_->tokenizer_options.reset(new ActionsTokenizerOptionsT); in EmbeddingTest()
1433 flatbuffers::FlatBufferBuilder builder; in CreateTestingMessageEmbedder() local
1434 FinishActionsModelBuffer(builder, ActionsModel::Pack(builder, &model_)); in CreateTestingMessageEmbedder()
1435 buffer_ = builder.Release(); in CreateTestingMessageEmbedder()
1458 options_->num_buckets)); in TEST_F()
1460 options_->num_buckets)); in TEST_F()
1462 options_->num_buckets)); in TEST_F()
1466 options_->min_num_tokens_per_message = 5; in TEST_F()
1479 options_->num_buckets)); in TEST_F()
1481 options_->num_buckets)); in TEST_F()
1483 options_->num_buckets)); in TEST_F()
1484 EXPECT_THAT(embeddings[3], FloatEq(options_->padding_token_id)); in TEST_F()
1485 EXPECT_THAT(embeddings[4], FloatEq(options_->padding_token_id)); in TEST_F()
1489 options_->max_num_tokens_per_message = 2; in TEST_F()
1502 options_->num_buckets)); in TEST_F()
1504 options_->num_buckets)); in TEST_F()
1520 options_->num_buckets)); in TEST_F()
1522 options_->num_buckets)); in TEST_F()
1524 options_->num_buckets)); in TEST_F()
1526 options_->num_buckets)); in TEST_F()
1528 options_->num_buckets)); in TEST_F()
1529 EXPECT_THAT(embeddings[5], FloatEq(options_->padding_token_id)); in TEST_F()
1544 EXPECT_THAT(embeddings[0], FloatEq(options_->start_token_id)); in TEST_F()
1546 options_->num_buckets)); in TEST_F()
1548 options_->num_buckets)); in TEST_F()
1550 options_->num_buckets)); in TEST_F()
1551 EXPECT_THAT(embeddings[4], FloatEq(options_->end_token_id)); in TEST_F()
1555 options_->min_num_total_tokens = 7; in TEST_F()
1567 EXPECT_THAT(embeddings[0], FloatEq(options_->start_token_id)); in TEST_F()
1569 options_->num_buckets)); in TEST_F()
1571 options_->num_buckets)); in TEST_F()
1573 options_->num_buckets)); in TEST_F()
1574 EXPECT_THAT(embeddings[4], FloatEq(options_->end_token_id)); in TEST_F()
1575 EXPECT_THAT(embeddings[5], FloatEq(options_->padding_token_id)); in TEST_F()
1576 EXPECT_THAT(embeddings[6], FloatEq(options_->padding_token_id)); in TEST_F()
1580 options_->max_num_total_tokens = 3; in TEST_F()
1593 options_->num_buckets)); in TEST_F()
1595 options_->num_buckets)); in TEST_F()
1596 EXPECT_THAT(embeddings[2], FloatEq(options_->end_token_id)); in TEST_F()
1612 EXPECT_THAT(embeddings[0], FloatEq(options_->start_token_id)); in TEST_F()
1614 options_->num_buckets)); in TEST_F()
1616 options_->num_buckets)); in TEST_F()
1618 options_->num_buckets)); in TEST_F()
1619 EXPECT_THAT(embeddings[4], FloatEq(options_->end_token_id)); in TEST_F()
1620 EXPECT_THAT(embeddings[5], FloatEq(options_->start_token_id)); in TEST_F()
1622 options_->num_buckets)); in TEST_F()
1624 options_->num_buckets)); in TEST_F()
1625 EXPECT_THAT(embeddings[8], FloatEq(options_->end_token_id)); in TEST_F()
1630 options_->max_num_total_tokens = 7; in TEST_F()
1644 options_->num_buckets)); in TEST_F()
1645 EXPECT_THAT(embeddings[1], FloatEq(options_->end_token_id)); in TEST_F()
1646 EXPECT_THAT(embeddings[2], FloatEq(options_->start_token_id)); in TEST_F()
1648 options_->num_buckets)); in TEST_F()
1650 options_->num_buckets)); in TEST_F()
1652 options_->num_buckets)); in TEST_F()
1653 EXPECT_THAT(embeddings[6], FloatEq(options_->end_token_id)); in TEST_F()
1660 actions_suggestions->SuggestActions( in TEST_F()
1664 EXPECT_EQ(response.actions.size(), in TEST_F()
1710 actions_suggestions->SuggestActions( in TEST_F()
1715 EXPECT_THAT(response.actions, in TEST_F()
1718 EXPECT_EQ(response.actions.size(), 3 /*3 smart replies*/); in TEST_F()
1743 actions_suggestions->SuggestActions( in TEST_F()
1748 EXPECT_EQ(response.actions.size(), 3 /*3 smart replies*/); in TEST_F()
1761 actions_suggestions->SuggestActions( in TEST_F()
1767 response.actions, in TEST_F()
1770 EXPECT_EQ(response.actions.size(), 4 /*1 location share + 3 smart replies*/); in TEST_F()
1786 actions_suggestions->SuggestActions( in TEST_F()
1792 response.actions, in TEST_F()
1797 EXPECT_EQ(response.actions.size(), 5 /*1 location share + 3 smart replies*/); in TEST_F()
1805 actions_suggestions->SuggestActions( in TEST_F()
1811 EXPECT_EQ(response.actions.size(), 5); in TEST_F()
1812 EXPECT_EQ(response.actions[0].response_text, "��"); in TEST_F()
1813 EXPECT_EQ(response.actions[0].type, "text_reply"); in TEST_F()
1814 EXPECT_EQ(response.actions[1].response_text, "��"); in TEST_F()
1815 EXPECT_EQ(response.actions[1].type, "text_reply"); in TEST_F()
1816 EXPECT_EQ(response.actions[2].response_text, "Yes"); in TEST_F()
1817 EXPECT_EQ(response.actions[2].type, "text_reply"); in TEST_F()
1825 actions_suggestions->SuggestActions( in TEST_F()
1831 EXPECT_EQ(response.actions.size(), 3); in TEST_F()
1832 EXPECT_EQ(response.actions[0].response_text, "��"); in TEST_F()
1833 EXPECT_EQ(response.actions[0].type, "text_reply"); in TEST_F()
1834 EXPECT_EQ(response.actions[1].response_text, "��"); in TEST_F()
1835 EXPECT_EQ(response.actions[1].type, "text_reply"); in TEST_F()
1836 EXPECT_EQ(response.actions[2].response_text, "Okay"); in TEST_F()
1837 EXPECT_EQ(response.actions[2].type, "text_reply"); in TEST_F()
1845 actions_suggestions->SuggestActions( in TEST_F()
1854 response.actions[0].response_text) != in TEST_F()
1856 EXPECT_EQ(response.actions[0].type, "emoji_reply"); in TEST_F()
1863 actions_suggestions->SuggestActions( in TEST_F()
1869 EXPECT_EQ(response.actions.size(), 3); in TEST_F()
1870 EXPECT_EQ(response.actions[0].response_text, "Hi how are you doing"); in TEST_F()
1871 EXPECT_EQ(response.actions[0].type, "text_reply"); in TEST_F()
1872 EXPECT_EQ(response.actions[1].response_text, "Hi whats up"); in TEST_F()
1873 EXPECT_EQ(response.actions[1].type, "text_reply"); in TEST_F()
1880 actions_suggestions->SuggestActions( in TEST_F()
1886 EXPECT_EQ(response.actions.size(), 0); in TEST_F()