Skip to content

Commit

Permalink
Remove DataManagerInterface because it is introduced only for testing…
Browse files Browse the repository at this point in the history
… (mock), not polymorphism.

PiperOrigin-RevId: 709273265
  • Loading branch information
taku910 authored and hiroyuki-komatsu committed Dec 24, 2024
1 parent 990c417 commit 3cb22a7
Show file tree
Hide file tree
Showing 55 changed files with 155 additions and 337 deletions.
6 changes: 3 additions & 3 deletions src/converter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mozc_cc_library(
srcs = ["connector.cc"],
hdrs = ["connector.h"],
deps = [
"//data_manager:data_manager_interface",
"//data_manager",
"//storage/louds:simple_succinct_bit_vector_index",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base:core_headers",
Expand Down Expand Up @@ -280,7 +280,7 @@ mozc_cc_library(
deps = [
":node",
"//base/container:bitarray",
"//data_manager:data_manager_interface",
"//data_manager",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/types:span",
],
Expand Down Expand Up @@ -465,7 +465,7 @@ mozc_cc_test(
"//composer",
"//composer:table",
"//config:config_handler",
"//data_manager:data_manager_interface",
"//data_manager",
"//data_manager/testing:mock_data_manager",
"//dictionary:dictionary_interface",
"//dictionary:dictionary_mock",
Expand Down
4 changes: 2 additions & 2 deletions src/converter/connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "data_manager/data_manager_interface.h"
#include "data_manager/data_manager.h"
#include "storage/louds/simple_succinct_bit_vector_index.h"


Expand Down Expand Up @@ -173,7 +173,7 @@ std::optional<uint16_t> Connector::Row::GetValue(uint16_t index) const {
}

absl::StatusOr<Connector> Connector::CreateFromDataManager(
const DataManagerInterface &data_manager) {
const DataManager &data_manager) {
#ifdef __ANDROID__
constexpr int kCacheSize = 256;
#else // __ANDROID__
Expand Down
4 changes: 2 additions & 2 deletions src/converter/connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "data_manager/data_manager_interface.h"
#include "data_manager/data_manager.h"
#include "storage/louds/simple_succinct_bit_vector_index.h"

namespace mozc {
Expand All @@ -47,7 +47,7 @@ class Connector final {
static constexpr int16_t kInvalidCost = 30000;

static absl::StatusOr<Connector> CreateFromDataManager(
const DataManagerInterface &data_manager);
const DataManager &data_manager);

static absl::StatusOr<Connector> Create(absl::string_view connection_data,
int cache_size);
Expand Down
6 changes: 3 additions & 3 deletions src/converter/converter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include "converter/immutable_converter_interface.h"
#include "converter/segments.h"
#include "converter/segments_matchers.h"
#include "data_manager/data_manager_interface.h"
#include "data_manager/data_manager.h"
#include "data_manager/testing/mock_data_manager.h"
#include "dictionary/dictionary_interface.h"
#include "dictionary/dictionary_mock.h"
Expand Down Expand Up @@ -193,8 +193,8 @@ class ResizeSegmentsRewriter : public RewriterInterface {
}

RewriterInterface::ResizeSegmentsRequest resize_request = {
.segment_index = segment_index_,
.segment_sizes = segment_sizes_,
.segment_index = segment_index_,
.segment_sizes = segment_sizes_,
};
return resize_request;
}
Expand Down
4 changes: 2 additions & 2 deletions src/converter/segmenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
#include "absl/types/span.h"
#include "base/container/bitarray.h"
#include "converter/node.h"
#include "data_manager/data_manager_interface.h"
#include "data_manager/data_manager.h"

namespace mozc {

std::unique_ptr<Segmenter> Segmenter::CreateFromDataManager(
const DataManagerInterface &data_manager) {
const DataManager &data_manager) {
size_t l_num_elements = 0;
size_t r_num_elements = 0;
absl::Span<const uint16_t> l_table, r_table, boundary_data;
Expand Down
4 changes: 2 additions & 2 deletions src/converter/segmenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
#include <memory>

#include "converter/node.h"
#include "data_manager/data_manager_interface.h"
#include "data_manager/data_manager.h"

namespace mozc {

class Segmenter {
public:
static std::unique_ptr<Segmenter> CreateFromDataManager(
const DataManagerInterface &data_manager);
const DataManager &data_manager);

// This class does not take the ownership of pointer parameters.
Segmenter(size_t l_num_elements, size_t r_num_elements,
Expand Down
12 changes: 1 addition & 11 deletions src/data_manager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,13 @@ load("//bazel:stubs.bzl", "bzl_library")

package(default_visibility = ["//visibility:public"])

mozc_cc_library(
name = "data_manager_interface",
hdrs = ["data_manager_interface.h"],
deps = [
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
],
)

mozc_cc_library(
name = "data_manager",
srcs = [
"data_manager.cc",
],
hdrs = ["data_manager.h"],
deps = [
":data_manager_interface",
":dataset_reader",
":serialized_dictionary",
"//base:mmap",
Expand All @@ -85,7 +75,7 @@ mozc_cc_library(
hdrs = ["data_manager_test_base.h"],
deps = [
":connection_file_reader",
":data_manager_interface",
":data_manager",
"//base:file_stream",
"//base:util",
"//base/container:serialized_string_array",
Expand Down
71 changes: 35 additions & 36 deletions src/data_manager/data_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "base/mmap.h"
#include "data_manager/data_manager_interface.h"

namespace mozc {

Expand All @@ -54,7 +53,7 @@ class DataSetReader; // Forward-declare this as it is used privately.
// (dictionary, LM, etc.).
// TODO(noriyukit): Migrate all the embedded data managers, such as
// oss/oss_data_manager.h, to this one.
class DataManager : public DataManagerInterface {
class DataManager {
public:
// Return status for initialization.
enum class Status {
Expand All @@ -79,6 +78,7 @@ class DataManager : public DataManagerInterface {
DataManager() = default;
DataManager(const DataManager &) = delete;
DataManager &operator=(const DataManager &) = delete;
virtual ~DataManager() = default;

// Parses |array| and extracts byte blocks of data set. The |array| must
// outlive this instance. The second version specifies a custom magic number
Expand All @@ -104,66 +104,65 @@ class DataManager : public DataManagerInterface {
absl::string_view magic);

// Implementation of DataManagerInterface.
std::optional<std::string> GetFilename() const override { return filename_; }
absl::Span<const uint16_t> GetPosMatcherData() const override;
void GetUserPosData(absl::string_view *token_array_data,
absl::string_view *string_array_data) const override;
absl::string_view GetConnectorData() const override;
absl::string_view GetSystemDictionaryData() const override;
absl::Span<const uint32_t> GetCollocationData() const override;
absl::Span<const uint32_t> GetCollocationSuppressionData() const override;
absl::Span<const uint32_t> GetSuggestionFilterData() const override;
absl::Span<const uint8_t> GetPosGroupData() const override;
void GetSegmenterData(
virtual std::optional<std::string> GetFilename() const { return filename_; }
virtual absl::Span<const uint16_t> GetPosMatcherData() const;
virtual void GetUserPosData(absl::string_view *token_array_data,
absl::string_view *string_array_data) const;
virtual absl::string_view GetConnectorData() const;
virtual absl::string_view GetSystemDictionaryData() const;
virtual absl::Span<const uint32_t> GetCollocationData() const;
virtual absl::Span<const uint32_t> GetCollocationSuppressionData() const;
virtual absl::Span<const uint32_t> GetSuggestionFilterData() const;
virtual absl::Span<const uint8_t> GetPosGroupData() const;
virtual void GetSegmenterData(
size_t *l_num_elements, size_t *r_num_elements,
absl::Span<const uint16_t> *l_table, absl::Span<const uint16_t> *r_table,
absl::Span<const char> *bitarray_data,
absl::Span<const uint16_t> *boundary_data) const override;
absl::Span<const uint16_t> *boundary_data) const;
absl::string_view GetCounterSuffixSortedArray() const;
void GetSuffixDictionaryData(
virtual void GetSuffixDictionaryData(
absl::string_view *key_array, absl::string_view *value_array,
absl::Span<const uint32_t> *token_array) const override;
void GetReadingCorrectionData(
absl::Span<const uint32_t> *token_array) const;
virtual void GetReadingCorrectionData(
absl::string_view *value_array_data, absl::string_view *error_array_data,
absl::string_view *correction_array_data) const override;
void GetSymbolRewriterData(
absl::string_view *correction_array_data) const;
virtual void GetSymbolRewriterData(
absl::string_view *token_array_data,
absl::string_view *string_array_data) const override;
void GetEmoticonRewriterData(
absl::string_view *string_array_data) const;
virtual void GetEmoticonRewriterData(
absl::string_view *token_array_data,
absl::string_view *string_array_data) const override;
void GetEmojiRewriterData(
absl::string_view *token_array_data,
absl::string_view *string_array_data) const override;
void GetSingleKanjiRewriterData(
absl::string_view *string_array_data) const;
virtual void GetEmojiRewriterData(absl::string_view *token_array_data,
absl::string_view *string_array_data) const;
virtual void GetSingleKanjiRewriterData(
absl::string_view *token_array_data, absl::string_view *string_array_data,
absl::string_view *variant_type_array_data,
absl::string_view *variant_token_array_data,
absl::string_view *variant_string_array_data,
absl::string_view *noun_prefix_token_array_data,
absl::string_view *noun_prefix_string_array_data) const override;
void GetA11yDescriptionRewriterData(
absl::string_view *noun_prefix_string_array_data) const;
virtual void GetA11yDescriptionRewriterData(
absl::string_view *token_array_data,
absl::string_view *string_array_data) const override;
void GetZeroQueryData(
absl::string_view *string_array_data) const;
virtual void GetZeroQueryData(
absl::string_view *zero_query_token_array_data,
absl::string_view *zero_query_string_array_data,
absl::string_view *zero_query_number_token_array_data,
absl::string_view *zero_query_number_string_array_data) const override;
absl::string_view *zero_query_number_string_array_data) const;

#ifndef NO_USAGE_REWRITER
void GetUsageRewriterData(
virtual void GetUsageRewriterData(
absl::string_view *base_conjugation_suffix_data,
absl::string_view *conjugation_suffix_data,
absl::string_view *conjugation_index_data,
absl::string_view *usage_items_data,
absl::string_view *string_array_data) const override;
absl::string_view *string_array_data) const;
#endif // NO_USAGE_REWRITER

absl::string_view GetDataVersion() const override;
virtual absl::string_view GetDataVersion() const;

std::optional<std::pair<size_t, size_t>> GetOffsetAndSize(
absl::string_view name) const override;
virtual std::optional<std::pair<size_t, size_t>> GetOffsetAndSize(
absl::string_view name) const;

private:
Status InitFromReader(const DataSetReader &reader);
Expand Down
Loading

0 comments on commit 3cb22a7

Please sign in to comment.