From 271b6ae4dbb5af0d543b6baf18887f9b9bc99ed5 Mon Sep 17 00:00:00 2001 From: Hiroyuki Komatsu Date: Thu, 18 Jan 2024 13:59:46 +0000 Subject: [PATCH] Remove user_args from DictionaryPredictor. #codehealth PiperOrigin-RevId: 599482977 --- src/engine/engine.cc | 4 +--- src/prediction/dictionary_prediction_aggregator.cc | 8 +++----- src/prediction/dictionary_prediction_aggregator.h | 6 ++---- .../dictionary_prediction_aggregator_test.cc | 10 ++++------ src/prediction/dictionary_predictor.cc | 7 +++---- src/prediction/dictionary_predictor.h | 5 ++--- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/engine/engine.cc b/src/engine/engine.cc index 3aa5c32b3..8c093d693 100644 --- a/src/engine/engine.cc +++ b/src/engine/engine.cc @@ -165,14 +165,12 @@ absl::Status Engine::Init( std::unique_ptr predictor; { - const void *user_arg = nullptr; - // Create a predictor with three sub-predictors, dictionary predictor, user // history predictor, and extra predictor. auto dictionary_predictor = std::make_unique( *data_manager, converter_.get(), immutable_converter_.get(), - modules_, user_arg); + modules_); RETURN_IF_NULL(dictionary_predictor); const bool enable_content_word_learning = is_mobile; diff --git a/src/prediction/dictionary_prediction_aggregator.cc b/src/prediction/dictionary_prediction_aggregator.cc index c04b917e2..5dc5f7cdb 100644 --- a/src/prediction/dictionary_prediction_aggregator.cc +++ b/src/prediction/dictionary_prediction_aggregator.cc @@ -555,12 +555,11 @@ DictionaryPredictionAggregator::DictionaryPredictionAggregator( const ImmutableConverterInterface *immutable_converter, const dictionary::DictionaryInterface *dictionary, const dictionary::DictionaryInterface *suffix_dictionary, - const dictionary::PosMatcher *pos_matcher, const void *user_arg) + const dictionary::PosMatcher *pos_matcher) : DictionaryPredictionAggregator( data_manager, converter, immutable_converter, dictionary, suffix_dictionary, pos_matcher, - std::make_unique(data_manager), - user_arg) {} + std::make_unique(data_manager)) {} DictionaryPredictionAggregator::DictionaryPredictionAggregator( const DataManagerInterface &data_manager, @@ -570,8 +569,7 @@ DictionaryPredictionAggregator::DictionaryPredictionAggregator( const dictionary::DictionaryInterface *suffix_dictionary, const dictionary::PosMatcher *pos_matcher, std::unique_ptr - single_kanji_prediction_aggregator, - const void *user_arg) + single_kanji_prediction_aggregator) : converter_(converter), immutable_converter_(immutable_converter), dictionary_(dictionary), diff --git a/src/prediction/dictionary_prediction_aggregator.h b/src/prediction/dictionary_prediction_aggregator.h index 903881199..b3a6cf0ec 100644 --- a/src/prediction/dictionary_prediction_aggregator.h +++ b/src/prediction/dictionary_prediction_aggregator.h @@ -76,8 +76,7 @@ class DictionaryPredictionAggregator : public PredictionAggregatorInterface { const ImmutableConverterInterface *immutable_converter, const dictionary::DictionaryInterface *dictionary, const dictionary::DictionaryInterface *suffix_dictionary, - const dictionary::PosMatcher *pos_matcher, - const void *user_arg = nullptr); + const dictionary::PosMatcher *pos_matcher); std::vector AggregateResults(const ConversionRequest &request, const Segments &segments) const override; @@ -120,8 +119,7 @@ class DictionaryPredictionAggregator : public PredictionAggregatorInterface { const dictionary::DictionaryInterface *suffix_dictionary, const dictionary::PosMatcher *pos_matcher, std::unique_ptr - single_kanji_prediction_aggregator, - const void *user_arg = nullptr); + single_kanji_prediction_aggregator); // Returns the bitfield that indicates what prediction subroutines // were used. NO_PREDICTION means that no prediction was made. diff --git a/src/prediction/dictionary_prediction_aggregator_test.cc b/src/prediction/dictionary_prediction_aggregator_test.cc index 55f06b832..c904b4ee9 100644 --- a/src/prediction/dictionary_prediction_aggregator_test.cc +++ b/src/prediction/dictionary_prediction_aggregator_test.cc @@ -89,11 +89,10 @@ class DictionaryPredictionAggregatorTestPeer { const dictionary::DictionaryInterface *suffix_dictionary, const dictionary::PosMatcher *pos_matcher, std::unique_ptr - single_kanji_prediction_aggregator, - const void *user_arg) + single_kanji_prediction_aggregator) : aggregator_(data_manager, converter, immutable_converter, dictionary, suffix_dictionary, pos_matcher, - std::move(single_kanji_prediction_aggregator), user_arg) {} + std::move(single_kanji_prediction_aggregator)) {} virtual ~DictionaryPredictionAggregatorTestPeer() = default; PredictionTypes AggregatePredictionForRequest( @@ -388,8 +387,7 @@ class MockDataAndAggregator { // nullptr is passed to the |suffix_dictionary|, MockDataManager's suffix // dictionary is used. // Note that |suffix_dictionary| is owned by this class. - void Init(const DictionaryInterface *suffix_dictionary = nullptr, - const void *user_arg = nullptr) { + void Init(const DictionaryInterface *suffix_dictionary = nullptr) { pos_matcher_.Set(data_manager_.GetPosMatcherData()); mock_dictionary_ = new MockDictionary; single_kanji_prediction_aggregator_ = @@ -406,7 +404,7 @@ class MockDataAndAggregator { aggregator_ = std::make_unique( data_manager_, &converter_, &mock_immutable_converter_, dictionary_.get(), suffix_dictionary_.get(), &pos_matcher_, - absl::WrapUnique(single_kanji_prediction_aggregator_), user_arg); + absl::WrapUnique(single_kanji_prediction_aggregator_)); } MockDictionary *mutable_dictionary() { return mock_dictionary_; } diff --git a/src/prediction/dictionary_predictor.cc b/src/prediction/dictionary_predictor.cc index 6721c0671..b728de7d7 100644 --- a/src/prediction/dictionary_predictor.cc +++ b/src/prediction/dictionary_predictor.cc @@ -270,8 +270,7 @@ DictionaryPredictor::DictionaryPredictor( const DataManagerInterface &data_manager, const ConverterInterface *converter, const ImmutableConverterInterface *immutable_converter, - const engine::Modules &modules, - const void *user_arg) + const engine::Modules &modules) : DictionaryPredictor( "DictionaryPredictor", std::make_unique( @@ -288,12 +287,12 @@ DictionaryPredictor::DictionaryPredictor( const DictionaryInterface *suffix_dictionary, const Connector &connector, const Segmenter *segmenter, const PosMatcher pos_matcher, const SuggestionFilter &suggestion_filter, - const prediction::RescorerInterface *rescorer, const void *user_arg) + const prediction::RescorerInterface *rescorer) : DictionaryPredictor( "DictionaryPredictor", std::make_unique( data_manager, converter, immutable_converter, dictionary, - suffix_dictionary, &pos_matcher, user_arg), + suffix_dictionary, &pos_matcher), data_manager, immutable_converter, connector, segmenter, pos_matcher, suggestion_filter, rescorer) {} diff --git a/src/prediction/dictionary_predictor.h b/src/prediction/dictionary_predictor.h index 6fb2c28c0..23f3d19d8 100644 --- a/src/prediction/dictionary_predictor.h +++ b/src/prediction/dictionary_predictor.h @@ -102,7 +102,7 @@ class DictionaryPredictor : public PredictorInterface { DictionaryPredictor(const DataManagerInterface &data_manager, const ConverterInterface *converter, const ImmutableConverterInterface *immutable_converter, - const engine::Modules &modules, const void *user_arg); + const engine::Modules &modules); // Initializes a predictor with given references to submodules. Note that // pointers are not owned by the class and to be deleted by the caller. @@ -114,8 +114,7 @@ class DictionaryPredictor : public PredictorInterface { const Connector &connector, const Segmenter *segmenter, dictionary::PosMatcher pos_matcher, const SuggestionFilter &suggestion_filter, - const prediction::RescorerInterface *rescorer = nullptr, - const void *user_arg = nullptr); + const prediction::RescorerInterface *rescorer = nullptr); DictionaryPredictor(const DictionaryPredictor &) = delete; DictionaryPredictor &operator=(const DictionaryPredictor &) = delete;