diff --git a/src/engine/BUILD.bazel b/src/engine/BUILD.bazel index d15f63a23..9baef7f94 100644 --- a/src/engine/BUILD.bazel +++ b/src/engine/BUILD.bazel @@ -187,7 +187,7 @@ mozc_cc_library( deps = [ ":data_loader", ":engine_interface", - ":minimal_engine", + ":minimal_converter", ":modules", ":supplemental_model_interface", "//base:vlog", @@ -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", ], diff --git a/src/engine/engine.cc b/src/engine/engine.cc index 1dc62f589..aa43238c0 100644 --- a/src/engine/engine.cc +++ b/src/engine/engine.cc @@ -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" @@ -96,6 +97,8 @@ std::unique_ptr Engine::CreateEngine() { return absl::WrapUnique(new Engine()); } +Engine::Engine() : minimal_converter_(CreateMinimalConverter()) {} + absl::Status Engine::ReloadModules(std::unique_ptr modules, bool is_mobile) { ReloadAndWait(); diff --git a/src/engine/engine.gyp b/src/engine/engine.gyp index 6fb20254b..62221b890 100644 --- a/src/engine/engine.gyp +++ b/src/engine/engine.gyp @@ -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', diff --git a/src/engine/engine.h b/src/engine/engine.h index 49cc0d5bc..80883b2cf 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -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" @@ -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 @@ -109,8 +110,9 @@ 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 @@ -118,9 +120,10 @@ class Engine : public EngineInterface { // Since the POS set may differ per LM, this function returns // available POS items. In practice, the POS items are rarely changed. std::vector 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. @@ -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 modules, bool is_mobile); - MinimalEngine minimal_engine_; DataLoader loader_; std::unique_ptr supplemental_model_; std::unique_ptr converter_; + std::unique_ptr minimal_converter_; std::unique_ptr loader_response_; bool always_wait_for_testing_ = false; }; diff --git a/src/engine/minimal_engine.cc b/src/engine/minimal_converter.cc similarity index 95% rename from src/engine/minimal_engine.cc rename to src/engine/minimal_converter.cc index 70f6eb2c7..491553291 100644 --- a/src/engine/minimal_engine.cc +++ b/src/engine/minimal_converter.cc @@ -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 #include @@ -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" @@ -152,11 +151,8 @@ class MinimalConverter : public ConverterInterface { }; } // namespace -MinimalEngine::MinimalEngine() - : converter_(std::make_unique()) {} - -ConverterInterface *MinimalEngine::GetConverter() const { - return converter_.get(); +std::unique_ptr CreateMinimalConverter() { + return std::make_unique(); } } // namespace mozc diff --git a/src/engine/minimal_engine.h b/src/engine/minimal_converter.h similarity index 62% rename from src/engine/minimal_engine.h rename to src/engine/minimal_converter.h index 449ee86bd..23eb09d2e 100644 --- a/src/engine/minimal_engine.h +++ b/src/engine/minimal_converter.h @@ -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 -#include -#include -#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 modules, - bool is_mobile) { - return absl::OkStatus(); - } - - private: - std::unique_ptr converter_; -}; +std::unique_ptr CreateMinimalConverter(); } // namespace mozc -#endif // MOZC_ENGINE_MINIMAL_ENGINE_H_ +#endif // MOZC_ENGINE_MINIMAL_CONVERTER_H_ diff --git a/src/ios/BUILD.bazel b/src/ios/BUILD.bazel index 807a5c760..5445fd7b7 100644 --- a/src/ios/BUILD.bazel +++ b/src/ios/BUILD.bazel @@ -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",