@@ -3434,78 +3434,72 @@ TEST_F(UserHistoryPredictorTest, GetInputKeyFromSegmentsKana) {
34343434}
34353435
34363436TEST_F (UserHistoryPredictorTest, RealtimeConversionInnerSegment) {
3437- for (bool cache_full_sentence : {true , false }) {
3438- for (bool mixed_conversion : {true , false }) {
3439- UserHistoryPredictor* predictor =
3440- GetUserHistoryPredictorWithClearedHistory ();
3441-
3442- SegmentsProxy segments_proxy;
3443- std::vector<Result> results;
3444-
3445- request_.set_mixed_conversion (mixed_conversion);
3446- request_.mutable_decoder_experiment_params ()
3447- ->set_user_history_cache_full_sentence (cache_full_sentence);
3448-
3449- const bool cache_full_sentence_expected =
3450- (!mixed_conversion || cache_full_sentence);
3451-
3452- {
3453- constexpr absl::string_view kKey = " わたしのなまえはなかのです" ;
3454- constexpr absl::string_view kValue = " 私の名前は中野です" ;
3455- const ConversionRequest convreq1 =
3456- SetUpInputForPrediction (kKey , &composer_, &segments_proxy);
3457- segments_proxy.AddCandidate (0 , kValue );
3458- // "わたしの, 私の", "わたし, 私"
3459- segments_proxy.PushBackInnerSegmentBoundary (0 , 0 , 12 , 6 , 9 , 3 );
3460- // "なまえは, 名前は", "なまえ, 名前"
3461- segments_proxy.PushBackInnerSegmentBoundary (0 , 0 , 12 , 9 , 9 , 6 );
3462- // "なかのです, 中野です", "なかの, 中野"
3463- segments_proxy.PushBackInnerSegmentBoundary (0 , 0 , 15 , 12 , 9 , 6 );
3464- predictor->Finish (convreq1, segments_proxy.MakeLearningResults (),
3465- kRevertId );
3437+ for (bool mixed_conversion : {true , false }) {
3438+ UserHistoryPredictor* predictor =
3439+ GetUserHistoryPredictorWithClearedHistory ();
34663440
3467- UserHistoryPredictorTestPeer predictor_peer (*predictor);
3468- auto * entry = predictor_peer.dic_ ()->MutableLookupWithoutInsert (
3469- UserHistoryPredictor::Fingerprint (kKey , kValue ));
3470- if (cache_full_sentence_expected) {
3471- EXPECT_TRUE (entry);
3472- } else {
3473- EXPECT_FALSE (entry);
3474- }
3475- }
3476- segments_proxy.Clear ();
3441+ SegmentsProxy segments_proxy;
3442+ std::vector<Result> results;
34773443
3478- const ConversionRequest convreq2 =
3479- SetUpInputForPrediction (" なかの" , &composer_, &segments_proxy);
3480- results = predictor->Predict (convreq2);
3481- EXPECT_FALSE (results.empty ());
3482- EXPECT_TRUE (FindCandidateByValue (" 中野" , results));
3483- EXPECT_FALSE (FindCandidateByValue (" 中野です" , results));
3484- segments_proxy.Clear ();
3444+ request_.set_mixed_conversion (mixed_conversion);
3445+ const bool cache_full_sentence_expected = !mixed_conversion;
34853446
3486- const ConversionRequest convreq3 =
3487- SetUpInputForPrediction (" なかので" , &composer_, &segments_proxy);
3488- results = predictor->Predict (convreq3);
3489- EXPECT_FALSE (results.empty ());
3490- EXPECT_TRUE (FindCandidateByValue (" 中野です" , results));
3447+ {
3448+ constexpr absl::string_view kKey = " わたしのなまえはなかのです" ;
3449+ constexpr absl::string_view kValue = " 私の名前は中野です" ;
3450+ const ConversionRequest convreq1 =
3451+ SetUpInputForPrediction (kKey , &composer_, &segments_proxy);
3452+ segments_proxy.AddCandidate (0 , kValue );
3453+ // "わたしの, 私の", "わたし, 私"
3454+ segments_proxy.PushBackInnerSegmentBoundary (0 , 0 , 12 , 6 , 9 , 3 );
3455+ // "なまえは, 名前は", "なまえ, 名前"
3456+ segments_proxy.PushBackInnerSegmentBoundary (0 , 0 , 12 , 9 , 9 , 6 );
3457+ // "なかのです, 中野です", "なかの, 中野"
3458+ segments_proxy.PushBackInnerSegmentBoundary (0 , 0 , 15 , 12 , 9 , 6 );
3459+ predictor->Finish (convreq1, segments_proxy.MakeLearningResults (),
3460+ kRevertId );
34913461
3492- segments_proxy.Clear ();
3493- const ConversionRequest convreq4 =
3494- SetUpInputForPrediction (" なまえ" , &composer_, &segments_proxy);
3495- results = predictor->Predict (convreq4);
3496- EXPECT_FALSE (results.empty ());
3497- EXPECT_TRUE (FindCandidateByValue (" 名前" , results));
3498- // Do not suggest the phrase ends with [content_word + function_word].
3499- EXPECT_FALSE (FindCandidateByValue (" 名前は" , results));
3500- EXPECT_FALSE (FindCandidateByValue (" 名前は中野です" , results));
3501- if (mixed_conversion) {
3502- // prefer exact match.
3503- EXPECT_FALSE (FindCandidateByValue (" 名前は中野" , results));
3462+ UserHistoryPredictorTestPeer predictor_peer (*predictor);
3463+ auto * entry = predictor_peer.dic_ ()->MutableLookupWithoutInsert (
3464+ UserHistoryPredictor::Fingerprint (kKey , kValue ));
3465+ if (cache_full_sentence_expected) {
3466+ EXPECT_TRUE (entry);
35043467 } else {
3505- // prefer prediction.
3506- EXPECT_TRUE (FindCandidateByValue (" 名前は中野" , results));
3468+ EXPECT_FALSE (entry);
35073469 }
35083470 }
3471+ segments_proxy.Clear ();
3472+
3473+ const ConversionRequest convreq2 =
3474+ SetUpInputForPrediction (" なかの" , &composer_, &segments_proxy);
3475+ results = predictor->Predict (convreq2);
3476+ EXPECT_FALSE (results.empty ());
3477+ EXPECT_TRUE (FindCandidateByValue (" 中野" , results));
3478+ EXPECT_FALSE (FindCandidateByValue (" 中野です" , results));
3479+ segments_proxy.Clear ();
3480+
3481+ const ConversionRequest convreq3 =
3482+ SetUpInputForPrediction (" なかので" , &composer_, &segments_proxy);
3483+ results = predictor->Predict (convreq3);
3484+ EXPECT_FALSE (results.empty ());
3485+ EXPECT_TRUE (FindCandidateByValue (" 中野です" , results));
3486+
3487+ segments_proxy.Clear ();
3488+ const ConversionRequest convreq4 =
3489+ SetUpInputForPrediction (" なまえ" , &composer_, &segments_proxy);
3490+ results = predictor->Predict (convreq4);
3491+ EXPECT_FALSE (results.empty ());
3492+ EXPECT_TRUE (FindCandidateByValue (" 名前" , results));
3493+ // Do not suggest the phrase ends with [content_word + function_word].
3494+ EXPECT_FALSE (FindCandidateByValue (" 名前は" , results));
3495+ EXPECT_FALSE (FindCandidateByValue (" 名前は中野です" , results));
3496+ if (mixed_conversion) {
3497+ // prefer exact match.
3498+ EXPECT_FALSE (FindCandidateByValue (" 名前は中野" , results));
3499+ } else {
3500+ // prefer prediction.
3501+ EXPECT_TRUE (FindCandidateByValue (" 名前は中野" , results));
3502+ }
35093503 }
35103504}
35113505
0 commit comments