Skip to content

Commit

Permalink
Remove user_args from DictionaryPredictor.
Browse files Browse the repository at this point in the history
#codehealth

PiperOrigin-RevId: 599482977
  • Loading branch information
hiroyuki-komatsu committed Jan 18, 2024
1 parent c16f2ab commit 271b6ae
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,12 @@ absl::Status Engine::Init(

std::unique_ptr<PredictorInterface> 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<prediction::DictionaryPredictor>(
*data_manager, converter_.get(), immutable_converter_.get(),
modules_, user_arg);
modules_);
RETURN_IF_NULL(dictionary_predictor);

const bool enable_content_word_learning = is_mobile;
Expand Down
8 changes: 3 additions & 5 deletions src/prediction/dictionary_prediction_aggregator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SingleKanjiPredictionAggregator>(data_manager),
user_arg) {}
std::make_unique<SingleKanjiPredictionAggregator>(data_manager)) {}

DictionaryPredictionAggregator::DictionaryPredictionAggregator(
const DataManagerInterface &data_manager,
Expand All @@ -570,8 +569,7 @@ DictionaryPredictionAggregator::DictionaryPredictionAggregator(
const dictionary::DictionaryInterface *suffix_dictionary,
const dictionary::PosMatcher *pos_matcher,
std::unique_ptr<PredictionAggregatorInterface>
single_kanji_prediction_aggregator,
const void *user_arg)
single_kanji_prediction_aggregator)
: converter_(converter),
immutable_converter_(immutable_converter),
dictionary_(dictionary),
Expand Down
6 changes: 2 additions & 4 deletions src/prediction/dictionary_prediction_aggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result> AggregateResults(const ConversionRequest &request,
const Segments &segments) const override;
Expand Down Expand Up @@ -120,8 +119,7 @@ class DictionaryPredictionAggregator : public PredictionAggregatorInterface {
const dictionary::DictionaryInterface *suffix_dictionary,
const dictionary::PosMatcher *pos_matcher,
std::unique_ptr<PredictionAggregatorInterface>
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.
Expand Down
10 changes: 4 additions & 6 deletions src/prediction/dictionary_prediction_aggregator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ class DictionaryPredictionAggregatorTestPeer {
const dictionary::DictionaryInterface *suffix_dictionary,
const dictionary::PosMatcher *pos_matcher,
std::unique_ptr<PredictionAggregatorInterface>
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(
Expand Down Expand Up @@ -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_ =
Expand All @@ -406,7 +404,7 @@ class MockDataAndAggregator {
aggregator_ = std::make_unique<DictionaryPredictionAggregatorTestPeer>(
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_; }
Expand Down
7 changes: 3 additions & 4 deletions src/prediction/dictionary_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<prediction::DictionaryPredictionAggregator>(
Expand All @@ -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<prediction::DictionaryPredictionAggregator>(
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) {}

Expand Down
5 changes: 2 additions & 3 deletions src/prediction/dictionary_predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down

0 comments on commit 271b6ae

Please sign in to comment.