Skip to content

Commit

Permalink
Removed MimimalEngine and introduced MinimalConverter. We've already …
Browse files Browse the repository at this point in the history
…removed the dependency to MinimalEngine.

PiperOrigin-RevId: 709514761
  • Loading branch information
taku910 authored and hiroyuki-komatsu committed Dec 25, 2024
1 parent 29c3581 commit f3f2929
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 58 deletions.
12 changes: 4 additions & 8 deletions src/engine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mozc_cc_library(
deps = [
":data_loader",
":engine_interface",
":minimal_engine",
":minimal_converter",
":modules",
":supplemental_model_interface",
"//base:vlog",
Expand Down Expand Up @@ -358,19 +358,15 @@ mozc_cc_library(
)

mozc_cc_library(
name = "minimal_engine",
srcs = ["minimal_engine.cc"],
hdrs = ["minimal_engine.h"],
name = "minimal_converter",
srcs = ["minimal_converter.cc"],
hdrs = ["minimal_converter.h"],
deps = [
":engine_interface",
":modules",
"//base/strings:assign",
"//composer",
"//converter:converter_interface",
"//converter:segments",
"//request:conversion_request",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
],
Expand Down
3 changes: 3 additions & 0 deletions src/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "converter/immutable_converter_interface.h"
#include "data_manager/data_manager.h"
#include "engine/data_loader.h"
#include "engine/minimal_converter.h"
#include "engine/modules.h"
#include "engine/supplemental_model_interface.h"
#include "prediction/dictionary_predictor.h"
Expand Down Expand Up @@ -96,6 +97,8 @@ std::unique_ptr<Engine> Engine::CreateEngine() {
return absl::WrapUnique(new Engine());
}

Engine::Engine() : minimal_converter_(CreateMinimalConverter()) {}

absl::Status Engine::ReloadModules(std::unique_ptr<engine::Modules> modules,
bool is_mobile) {
ReloadAndWait();
Expand Down
4 changes: 2 additions & 2 deletions src/engine/engine.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@
],
},
{
'target_name': 'minimal_engine',
'target_name': 'minimal_converter',
'type': 'static_library',
'sources': [
'<(gen_out_dir)/../dictionary/pos_matcher_impl.inc',
'minimal_engine.cc',
'minimal_converter.cc',
],
'dependencies': [
'<(mozc_oss_src_dir)/composer/composer.gyp:composer',
Expand Down
21 changes: 12 additions & 9 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "data_manager/data_manager.h"
#include "engine/data_loader.h"
#include "engine/engine_interface.h"
#include "engine/minimal_engine.h"
#include "engine/minimal_converter.h"
#include "engine/modules.h"
#include "engine/supplemental_model_interface.h"
#include "prediction/predictor_interface.h"
Expand Down Expand Up @@ -86,12 +86,13 @@ class Engine : public EngineInterface {
// TODO(taku): Avoid returning pointer, as converter_ may be updated
// dynamically and return value will become a dangling pointer.
ConverterInterface *GetConverter() const override {
return converter_ ? converter_.get() : minimal_engine_.GetConverter();
return converter_ ? converter_.get() : minimal_converter_.get();
}

absl::string_view GetPredictorName() const override {
static absl::string_view kDefaultPredictorName = "MinimalPredictor";
return converter_ ? converter_->predictor()->GetPredictorName()
: minimal_engine_.GetPredictorName();
: kDefaultPredictorName;
}

// Functions for Reload, Sync, Wait return true if successfully operated
Expand All @@ -109,18 +110,20 @@ class Engine : public EngineInterface {
bool is_mobile);

absl::string_view GetDataVersion() const override {
static absl::string_view kDefaultDataVersion = "0.0.0";
return converter_ ? converter_->modules()->GetDataManager().GetDataVersion()
: minimal_engine_.GetDataVersion();
: kDefaultDataVersion;
}

// Returns a list of part-of-speech (e.g. "名詞", "動詞一段") to be used for
// the user dictionary GUI tool.
// Since the POS set may differ per LM, this function returns
// available POS items. In practice, the POS items are rarely changed.
std::vector<std::string> GetPosList() const override {
return converter_ && converter_->modules()->GetUserDictionary()
? converter_->modules()->GetUserDictionary()->GetPosList()
: minimal_engine_.GetPosList();
if (converter_ && converter_->modules()->GetUserDictionary()) {
return converter_->modules()->GetUserDictionary()->GetPosList();
}
return {};
}

// For testing only.
Expand All @@ -137,17 +140,17 @@ class Engine : public EngineInterface {
void SetAlwaysWaitForTesting(bool value) { always_wait_for_testing_ = value; }

private:
Engine() = default;
Engine();

// Initializes the engine object by the given modules and is_mobile flag.
// The is_mobile flag is used to select DefaultPredictor and MobilePredictor.
absl::Status Init(std::unique_ptr<engine::Modules> modules, bool is_mobile);

MinimalEngine minimal_engine_;
DataLoader loader_;

std::unique_ptr<engine::SupplementalModelInterface> supplemental_model_;
std::unique_ptr<Converter> converter_;
std::unique_ptr<ConverterInterface> minimal_converter_;
std::unique_ptr<DataLoader::Response> loader_response_;
bool always_wait_for_testing_ = false;
};
Expand Down
10 changes: 3 additions & 7 deletions src/engine/minimal_engine.cc → src/engine/minimal_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "engine/minimal_engine.h"
#include "engine/minimal_converter.h"

#include <cstddef>
#include <cstdint>
Expand All @@ -39,7 +39,6 @@
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "base/strings/assign.h"
#include "composer/composer.h"
#include "converter/converter_interface.h"
#include "converter/segments.h"
#include "request/conversion_request.h"
Expand Down Expand Up @@ -152,11 +151,8 @@ class MinimalConverter : public ConverterInterface {
};
} // namespace

MinimalEngine::MinimalEngine()
: converter_(std::make_unique<MinimalConverter>()) {}

ConverterInterface *MinimalEngine::GetConverter() const {
return converter_.get();
std::unique_ptr<ConverterInterface> CreateMinimalConverter() {
return std::make_unique<MinimalConverter>();
}

} // namespace mozc
35 changes: 4 additions & 31 deletions src/engine/minimal_engine.h → src/engine/minimal_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef MOZC_ENGINE_MINIMAL_ENGINE_H_
#define MOZC_ENGINE_MINIMAL_ENGINE_H_
#ifndef MOZC_ENGINE_MINIMAL_CONVERTER_H_
#define MOZC_ENGINE_MINIMAL_CONVERTER_H_

#include <memory>
#include <string>
#include <vector>

#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "converter/converter_interface.h"
#include "engine/engine_interface.h"
#include "engine/modules.h"

namespace mozc {

// A minimal implementation of EngineInterface, which copies input key to the
// first candidate.
class MinimalEngine : public EngineInterface {
public:
MinimalEngine();
MinimalEngine(const MinimalEngine &) = delete;
MinimalEngine &operator=(const MinimalEngine &) = delete;

ConverterInterface *GetConverter() const override;
absl::string_view GetPredictorName() const override {
return "MinimalPredictor";
}
absl::string_view GetDataVersion() const override { return "0.0.0"; }

absl::Status ReloadModules(std::unique_ptr<engine::Modules> modules,
bool is_mobile) {
return absl::OkStatus();
}

private:
std::unique_ptr<ConverterInterface> converter_;
};
std::unique_ptr<ConverterInterface> CreateMinimalConverter();

} // namespace mozc

#endif // MOZC_ENGINE_MINIMAL_ENGINE_H_
#endif // MOZC_ENGINE_MINIMAL_CONVERTER_H_
1 change: 0 additions & 1 deletion src/ios/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ mozc_cc_library(
"//data_manager",
"//engine",
"//engine:engine_interface",
"//engine:minimal_engine",
"//protocol:commands_cc_proto",
"//protocol:config_cc_proto",
"//protocol:user_dictionary_storage_cc_proto",
Expand Down

0 comments on commit f3f2929

Please sign in to comment.