diff --git a/src/converter/converter.cc b/src/converter/converter.cc index 9ff075739..8e03cd872 100644 --- a/src/converter/converter.cc +++ b/src/converter/converter.cc @@ -455,37 +455,6 @@ bool Converter::StartPrediction(const ConversionRequest &request, return Predict(request, segments); } -bool Converter::StartSuggestion(const ConversionRequest &original_request, - Segments *segments) const { - const ConversionRequest request = CreateConversionRequestWithType( - original_request, ConversionRequest::SUGGESTION); - return Predict(request, segments); -} - -bool Converter::StartPartialSuggestion( - const ConversionRequest &original_request, Segments *segments) const { - const size_t cursor = original_request.composer().GetCursor(); - if (cursor == 0 || cursor == original_request.composer().GetLength()) { - return StartSuggestion(original_request, segments); - } - - const ConversionRequest request = CreateConversionRequestWithType( - original_request, ConversionRequest::PARTIAL_SUGGESTION); - return Predict(request, segments); -} - -bool Converter::StartPartialPrediction( - const ConversionRequest &original_request, Segments *segments) const { - const size_t cursor = original_request.composer().GetCursor(); - if (cursor == 0 || cursor == original_request.composer().GetLength()) { - return StartPrediction(original_request, segments); - } - - const ConversionRequest request = CreateConversionRequestWithType( - original_request, ConversionRequest::PARTIAL_PREDICTION); - return Predict(request, segments); -} - void Converter::FinishConversion(const ConversionRequest &request, Segments *segments) const { CommitUsageStats(segments, segments->history_segments_size(), diff --git a/src/converter/converter.h b/src/converter/converter.h index e7233117d..e83fe4580 100644 --- a/src/converter/converter.h +++ b/src/converter/converter.h @@ -71,15 +71,6 @@ class Converter final : public ConverterInterface { ABSL_MUST_USE_RESULT bool StartPrediction(const ConversionRequest &request, Segments *segments) const override; - ABSL_MUST_USE_RESULT - bool StartSuggestion(const ConversionRequest &request, - Segments *segments) const override; - ABSL_MUST_USE_RESULT - bool StartPartialPrediction(const ConversionRequest &request, - Segments *segments) const override; - ABSL_MUST_USE_RESULT - bool StartPartialSuggestion(const ConversionRequest &request, - Segments *segments) const override; void FinishConversion(const ConversionRequest &request, Segments *segments) const override; diff --git a/src/converter/converter_interface.h b/src/converter/converter_interface.h index 919b3c097..703a35d20 100644 --- a/src/converter/converter_interface.h +++ b/src/converter/converter_interface.h @@ -68,21 +68,6 @@ class ConverterInterface { virtual bool StartPrediction(const ConversionRequest &request, Segments *segments) const = 0; - // Starts suggestion for given request. - ABSL_MUST_USE_RESULT - virtual bool StartSuggestion(const ConversionRequest &request, - Segments *segments) const = 0; - - // Starts partial prediction for given request. - ABSL_MUST_USE_RESULT - virtual bool StartPartialPrediction(const ConversionRequest &request, - Segments *segments) const = 0; - - // Starts partial suggestion for given request. - ABSL_MUST_USE_RESULT - virtual bool StartPartialSuggestion(const ConversionRequest &request, - Segments *segments) const = 0; - // Finish conversion. // Segments are cleared. Context is not cleared virtual void FinishConversion(const ConversionRequest &request, diff --git a/src/converter/converter_main.cc b/src/converter/converter_main.cc index 65ecb343d..bfec77486 100644 --- a/src/converter/converter_main.cc +++ b/src/converter/converter_main.cc @@ -300,11 +300,12 @@ bool ExecCommand(const ConverterInterface &converter, const std::string &line, absl::GetFlag(FLAGS_max_conversion_candidates_size), .create_partial_candidates = request.auto_partial_suggestion(), }; - const ConversionRequest conversion_request = ConversionRequest( - composer, request, context, *config, std::move(options)); const std::string &func = fields[0]; if (func == "startconversion" || func == "start" || func == "s") { + options.request_type = ConversionRequest::CONVERSION; + const ConversionRequest conversion_request = ConversionRequest( + composer, request, context, *config, std::move(options)); CHECK_FIELDS_LENGTH(2); composer.SetPreeditTextForTestOnly(fields[1]); return converter.StartConversion(conversion_request, segments); @@ -325,6 +326,9 @@ bool ExecCommand(const ConverterInterface &converter, const std::string &line, CHECK_FIELDS_LENGTH(2); return converter.StartReverseConversion(segments, fields[1]); } else if (func == "startprediction" || func == "predict" || func == "p") { + options.request_type = ConversionRequest::PREDICTION; + const ConversionRequest conversion_request = ConversionRequest( + composer, request, context, *config, std::move(options)); if (fields.size() >= 2) { composer.SetPreeditTextForTestOnly(fields[1]); return converter.StartPrediction(conversion_request, segments); @@ -332,13 +336,19 @@ bool ExecCommand(const ConverterInterface &converter, const std::string &line, return converter.StartPrediction(conversion_request, segments); } } else if (func == "startsuggestion" || func == "suggest") { + options.request_type = ConversionRequest::SUGGESTION; + const ConversionRequest conversion_request = ConversionRequest( + composer, request, context, *config, std::move(options)); if (fields.size() >= 2) { composer.SetPreeditTextForTestOnly(fields[1]); - return converter.StartSuggestion(conversion_request, segments); + return converter.StartPrediction(conversion_request, segments); } else { - return converter.StartSuggestion(conversion_request, segments); + return converter.StartPrediction(conversion_request, segments); } } else if (func == "finishconversion" || func == "finish") { + options.request_type = ConversionRequest::CONVERSION; + const ConversionRequest conversion_request = ConversionRequest( + composer, request, context, *config, std::move(options)); converter.FinishConversion(conversion_request, segments); return true; } else if (func == "resetconversion" || func == "reset") { @@ -359,6 +369,9 @@ bool ExecCommand(const ConverterInterface &converter, const std::string &line, if (!(converter.CommitSegmentValue(segments, i, 0))) return false; } } + options.request_type = ConversionRequest::CONVERSION; + const ConversionRequest conversion_request = ConversionRequest( + composer, request, context, *config, std::move(options)); converter.FinishConversion(conversion_request, segments); return true; } else if (func == "focussegmentvalue" || func == "focus") { @@ -372,6 +385,9 @@ bool ExecCommand(const ConverterInterface &converter, const std::string &line, singleton_vector.push_back(NumberUtil::SimpleAtoi(fields[1])); return converter.CommitSegments(segments, singleton_vector); } else if (func == "resizesegment" || func == "resize") { + options.request_type = ConversionRequest::CONVERSION; + const ConversionRequest conversion_request = ConversionRequest( + composer, request, context, *config, std::move(options)); if (fields.size() == 3) { return converter.ResizeSegment(segments, conversion_request, NumberUtil::SimpleAtoi(fields[1]), diff --git a/src/converter/converter_mock.h b/src/converter/converter_mock.h index 9512571f8..cfd6cee57 100644 --- a/src/converter/converter_mock.h +++ b/src/converter/converter_mock.h @@ -55,15 +55,6 @@ class StrictMockConverter : public ConverterInterface { MOCK_METHOD(bool, StartPrediction, (const ConversionRequest &request, Segments *segments), (const, override)); - MOCK_METHOD(bool, StartSuggestion, - (const ConversionRequest &request, Segments *segments), - (const, override)); - MOCK_METHOD(bool, StartPartialPrediction, - (const ConversionRequest &request, Segments *segments), - (const, override)); - MOCK_METHOD(bool, StartPartialSuggestion, - (const ConversionRequest &request, Segments *segments), - (const, override)); MOCK_METHOD(void, FinishConversion, (const ConversionRequest &request, Segments *segments), (const, override)); diff --git a/src/converter/converter_test.cc b/src/converter/converter_test.cc index 490334653..728af7098 100644 --- a/src/converter/converter_test.cc +++ b/src/converter/converter_test.cc @@ -1022,7 +1022,7 @@ TEST_F(ConverterTest, StartSuggestion) { std::move(options)); Segments segments; - EXPECT_TRUE(converter->StartSuggestion(request, &segments)); + EXPECT_TRUE(converter->StartPrediction(request, &segments)); EXPECT_EQ(segments.segments_size(), 1); ASSERT_TRUE(segments.segment(0).meta_candidates_size() >= transliteration::HALF_ASCII); @@ -1043,7 +1043,7 @@ TEST_F(ConverterTest, StartSuggestion) { std::move(options)); Segments segments; - EXPECT_TRUE(converter->StartSuggestion(request, &segments)); + EXPECT_TRUE(converter->StartPrediction(request, &segments)); EXPECT_EQ(segments.segments_size(), 1); ASSERT_TRUE(segments.segment(0).meta_candidates_size() >= transliteration::HALF_ASCII); @@ -1059,7 +1059,7 @@ TEST_F(ConverterTest, StartPartialPrediction) { ConverterInterface *converter = engine->GetConverter(); CHECK(converter); Segments segments; - EXPECT_TRUE(converter->StartPartialPrediction( + EXPECT_TRUE(converter->StartPrediction( ConvReq("わたしは", ConversionRequest::PARTIAL_PREDICTION), &segments)); EXPECT_EQ(segments.segments_size(), 1); EXPECT_EQ(segments.segment(0).candidate(0).key, "わたしは"); @@ -1072,7 +1072,7 @@ TEST_F(ConverterTest, StartPartialSuggestion) { ConverterInterface *converter = engine->GetConverter(); CHECK(converter); Segments segments; - EXPECT_TRUE(converter->StartPartialSuggestion( + EXPECT_TRUE(converter->StartPrediction( ConvReq("わたしは", ConversionRequest::PARTIAL_SUGGESTION), &segments)); EXPECT_EQ(segments.segments_size(), 1); EXPECT_EQ(segments.segment(0).candidate(0).key, "わたしは"); @@ -1084,7 +1084,7 @@ TEST_F(ConverterTest, StartPartialPredictionMobile) { ConverterInterface *converter = engine->GetConverter(); CHECK(converter); Segments segments; - EXPECT_TRUE(converter->StartPartialPrediction( + EXPECT_TRUE(converter->StartPrediction( ConvReq("わたしは", ConversionRequest::PARTIAL_PREDICTION), &segments)); EXPECT_EQ(segments.segments_size(), 1); EXPECT_EQ(segments.segment(0).candidate(0).key, "わたしは"); @@ -1096,7 +1096,7 @@ TEST_F(ConverterTest, StartPartialSuggestionMobile) { ConverterInterface *converter = engine->GetConverter(); CHECK(converter); Segments segments; - EXPECT_TRUE(converter->StartPartialSuggestion( + EXPECT_TRUE(converter->StartPrediction( ConvReq("わたしは", ConversionRequest::PARTIAL_SUGGESTION), &segments)); EXPECT_EQ(segments.segments_size(), 1); EXPECT_EQ(segments.segment(0).candidate(0).key, "わたしは"); @@ -1245,7 +1245,7 @@ TEST_F(ConverterTest, VariantExpansionForSuggestion) { Segments segments; { // Dictionary suggestion - EXPECT_TRUE(converter.StartSuggestion( + EXPECT_TRUE(converter.StartPrediction( ConvReq("てすと", ConversionRequest::SUGGESTION), &segments)); EXPECT_EQ(segments.conversion_segments_size(), 1); EXPECT_LE(1, segments.conversion_segment(0).candidates_size()); @@ -1256,7 +1256,7 @@ TEST_F(ConverterTest, VariantExpansionForSuggestion) { { // Realtime conversion segments.Clear(); - EXPECT_TRUE(converter.StartSuggestion( + EXPECT_TRUE(converter.StartPrediction( ConvReq("てすとの", ConversionRequest::SUGGESTION), &segments)); EXPECT_EQ(segments.conversion_segments_size(), 1); EXPECT_LE(1, segments.conversion_segment(0).candidates_size()); diff --git a/src/converter/quality_regression_util.cc b/src/converter/quality_regression_util.cc index e8dc63b79..a930f6231 100644 --- a/src/converter/quality_regression_util.cc +++ b/src/converter/quality_regression_util.cc @@ -283,9 +283,9 @@ absl::StatusOr QualityRegressionUtil::ConvertAndTest( const ConversionRequest conv_req( composer, request_, context, config_, {.request_type = ConversionRequest::SUGGESTION}); - if (!converter_->StartSuggestion(conv_req, &segments_)) { - return absl::UnknownError( - absl::StrCat("StartSuggestion failed: ", item.OutputAsTSV())); + if (!converter_->StartPrediction(conv_req, &segments_)) { + return absl::UnknownError(absl::StrCat( + "StartPrediction for suggestion failed: ", item.OutputAsTSV())); } } else if (command == kZeroQueryExpect || command == kZeroQueryNotExpect) { commands::Request request = request_; @@ -298,9 +298,9 @@ absl::StatusOr QualityRegressionUtil::ConvertAndTest( composer, request, context, config_, {.request_type = ConversionRequest::SUGGESTION, .max_conversion_candidates_size = 10}); - if (!converter_->StartSuggestion(conv_req, &segments_)) { - return absl::UnknownError( - absl::StrCat("StartSuggestion failed: ", item.OutputAsTSV())); + if (!converter_->StartPrediction(conv_req, &segments_)) { + return absl::UnknownError(absl::StrCat( + "StartSuggestion for suggestion failed: ", item.OutputAsTSV())); } if (!converter_->CommitSegmentValue(&segments_, 0, 0)) { return absl::UnknownError( diff --git a/src/engine/minimal_engine.cc b/src/engine/minimal_engine.cc index bed3aaa3f..b5c9bdce5 100644 --- a/src/engine/minimal_engine.cc +++ b/src/engine/minimal_engine.cc @@ -116,21 +116,6 @@ class MinimalConverter : public ConverterInterface { return AddAsIsCandidate(request, segments); } - bool StartSuggestion(const ConversionRequest &request, - Segments *segments) const override { - return AddAsIsCandidate(request, segments); - } - - bool StartPartialPrediction(const ConversionRequest &request, - Segments *segments) const override { - return false; - } - - bool StartPartialSuggestion(const ConversionRequest &request, - Segments *segments) const override { - return false; - } - void FinishConversion(const ConversionRequest &request, Segments *segments) const override {}