diff --git a/src/converter/converter.cc b/src/converter/converter.cc index 8e03cd872..06954283e 100644 --- a/src/converter/converter.cc +++ b/src/converter/converter.cc @@ -373,6 +373,27 @@ void Converter::MaybeSetConsumedKeySizeToSegment(size_t consumed_key_size, } namespace { +bool ValidateConversionRequestForPrediction(const ConversionRequest &request) { + switch (request.request_type()) { + case ConversionRequest::CONVERSION: + // Conversion request is not for prediction. + return false; + case ConversionRequest::PREDICTION: + case ConversionRequest::SUGGESTION: + // Typical use case. + return true; + case ConversionRequest::PARTIAL_PREDICTION: + case ConversionRequest::PARTIAL_SUGGESTION: { + // Partial prediction/suggestion request is applicable only if the + // cursor is in the middle of the composer. + const size_t cursor = request.composer().GetCursor(); + return cursor != 0 || cursor != request.composer().GetLength(); + } + default: + ABSL_UNREACHABLE(); + } +} + std::string GetPredictionKey(const ConversionRequest &request) { switch (request.request_type()) { case ConversionRequest::PREDICTION: @@ -391,8 +412,10 @@ std::string GetPredictionKey(const ConversionRequest &request) { } } // namespace -bool Converter::Predict(const ConversionRequest &request, - Segments *segments) const { +bool Converter::StartPrediction(const ConversionRequest &request, + Segments *segments) const { + DCHECK(ValidateConversionRequestForPrediction(request)); + const std::string key = GetPredictionKey(request); if (ShouldSetKeyForPrediction(key, *segments)) { SetKey(segments, key); @@ -426,35 +449,6 @@ bool Converter::Predict(const ConversionRequest &request, return IsValidSegments(request, *segments); } -namespace { -bool ValidateConversionRequestForPrediction(const ConversionRequest &request) { - switch (request.request_type()) { - case ConversionRequest::CONVERSION: - // Conversion request is not for prediction. - return false; - case ConversionRequest::PREDICTION: - case ConversionRequest::SUGGESTION: - // Typical use case. - return true; - case ConversionRequest::PARTIAL_PREDICTION: - case ConversionRequest::PARTIAL_SUGGESTION: { - // Partial prediction/suggestion request is applicable only if the - // cursor is in the middle of the composer. - const size_t cursor = request.composer().GetCursor(); - return cursor != 0 || cursor != request.composer().GetLength(); - } - default: - ABSL_UNREACHABLE(); - } -} -} // namespace - -bool Converter::StartPrediction(const ConversionRequest &request, - Segments *segments) const { - DCHECK(ValidateConversionRequestForPrediction(request)); - 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 e83fe4580..b38153be2 100644 --- a/src/converter/converter.h +++ b/src/converter/converter.h @@ -158,9 +158,6 @@ class Converter final : public ConverterInterface { bool GetLastConnectivePart(absl::string_view preceding_text, std::string *key, std::string *value, uint16_t *id) const; - ABSL_MUST_USE_RESULT bool Predict(const ConversionRequest &request, - Segments *segments) const; - const dictionary::PosMatcher *pos_matcher_ = nullptr; const dictionary::SuppressionDictionary *suppression_dictionary_; std::unique_ptr predictor_; diff --git a/src/converter/converter_test.cc b/src/converter/converter_test.cc index 728af7098..7b426a52f 100644 --- a/src/converter/converter_test.cc +++ b/src/converter/converter_test.cc @@ -1182,7 +1182,7 @@ TEST_F(ConverterTest, PredictSetKey) { .SetComposer(composer) .SetRequestType(ConversionRequest::PREDICTION) .Build(); - ASSERT_TRUE(converter->Predict(request, &segments)); + ASSERT_TRUE(converter->StartPrediction(request, &segments)); ASSERT_EQ(segments.conversion_segments_size(), 1); EXPECT_EQ(segments.conversion_segment(0).key(), kPredictionKey);