Skip to content

Commit

Permalink
Use engine::Modules for ConverterImpl::Init.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 604221782
  • Loading branch information
hiroyuki-komatsu committed Feb 5, 2024
1 parent a90cb18 commit f22255d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/converter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ mozc_cc_library(
"//composer",
"//dictionary:pos_matcher",
"//dictionary:suppression_dictionary",
"//engine:modules",
"//prediction:predictor_interface",
"//protocol:commands_cc_proto",
"//request:conversion_request",
Expand Down
8 changes: 4 additions & 4 deletions src/converter/converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "converter/segments.h"
#include "dictionary/pos_matcher.h"
#include "dictionary/suppression_dictionary.h"
#include "engine/modules.h"
#include "prediction/predictor_interface.h"
#include "protocol/commands.pb.h"
#include "request/conversion_request.h"
Expand Down Expand Up @@ -261,14 +262,13 @@ ConversionRequest CreateConversionRequestWithType(

} // namespace

void Converter::Init(const PosMatcher *pos_matcher,
const SuppressionDictionary *suppression_dictionary,
void Converter::Init(const engine::Modules &modules,
std::unique_ptr<PredictorInterface> predictor,
std::unique_ptr<RewriterInterface> rewriter,
ImmutableConverterInterface *immutable_converter) {
// Initializes in order of declaration.
pos_matcher_ = pos_matcher;
suppression_dictionary_ = suppression_dictionary;
pos_matcher_ = modules.GetPosMatcher();
suppression_dictionary_ = modules.GetSuppressionDictionary();
predictor_ = std::move(predictor);
rewriter_ = std::move(rewriter);
immutable_converter_ = immutable_converter;
Expand Down
4 changes: 2 additions & 2 deletions src/converter/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "converter/segments.h"
#include "dictionary/pos_matcher.h"
#include "dictionary/suppression_dictionary.h"
#include "engine/modules.h"
#include "prediction/predictor_interface.h"
#include "request/conversion_request.h"
#include "rewriter/rewriter_interface.h"
Expand All @@ -57,8 +58,7 @@ class Converter final : public ConverterInterface {
Converter() = default;

// Lazily initializes the internal members. Must be called before the use.
void Init(const dictionary::PosMatcher *pos_matcher,
const dictionary::SuppressionDictionary *suppression_dictionary,
void Init(const engine::Modules &modules,
std::unique_ptr<prediction::PredictorInterface> predictor,
std::unique_ptr<RewriterInterface> rewriter,
ImmutableConverterInterface *immutable_converter);
Expand Down
5 changes: 2 additions & 3 deletions src/converter/converter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ class ConverterTest : public testing::TestWithTempUserProfile {
auto predictor = CreatePredictor(predictor_type, modules.GetPosMatcher(),
*converter_and_data);
converter_and_data->converter->Init(
modules.GetPosMatcher(), modules.GetSuppressionDictionary(),
std::move(predictor), std::move(rewriter),
modules, std::move(predictor), std::move(rewriter),
converter_and_data->immutable_converter.get());
}

Expand Down Expand Up @@ -1183,7 +1182,7 @@ TEST_F(ConverterTest, VariantExpansionForSuggestion) {
Converter converter;
const DictionaryInterface *kNullDictionary = nullptr;
converter.Init(
modules.GetPosMatcher(), modules.GetSuppressionDictionary(),
modules,
DefaultPredictor::CreateDefaultPredictor(
std::make_unique<DictionaryPredictor>(
data_manager, &converter, immutable_converter.get(), modules),
Expand Down
5 changes: 2 additions & 3 deletions src/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ absl::Status Engine::Init(
RETURN_IF_NULL(rewriter);
rewriter_ = rewriter.get(); // Keep the reference

converter_->Init(modules_.GetPosMatcher(),
modules_.GetSuppressionDictionary(), std::move(predictor),
std::move(rewriter), immutable_converter_.get());
converter_->Init(modules_, std::move(predictor), std::move(rewriter),
immutable_converter_.get());

user_data_manager_ = std::make_unique<UserDataManager>(predictor_, rewriter_);

Expand Down

0 comments on commit f22255d

Please sign in to comment.