mirror of
https://github.com/mii443/mozc.git
synced 2025-08-22 16:15:46 +00:00
Remove composer/internal/converter.
This module is internal and only used by mozc_transliterator. Moves the logic to mozc_transliterator to reduce the maintenance cost. PiperOrigin-RevId: 726396597
This commit is contained in:
committed by
Hiroyuki Komatsu
parent
4a65062698
commit
b5e10e1507
@ -42,7 +42,6 @@
|
||||
'internal/char_chunk.cc',
|
||||
'internal/composition.cc',
|
||||
'internal/composition_input.cc',
|
||||
'internal/converter.cc',
|
||||
'internal/mode_switching_handler.cc',
|
||||
'internal/special_key.cc',
|
||||
'internal/transliterators.cc',
|
||||
|
@ -37,7 +37,6 @@
|
||||
'internal/char_chunk_test.cc',
|
||||
'internal/composition_input_test.cc',
|
||||
'internal/composition_test.cc',
|
||||
'internal/converter_test.cc',
|
||||
'internal/mode_switching_handler_test.cc',
|
||||
'internal/special_key_test.cc',
|
||||
'internal/transliterators_test.cc',
|
||||
|
@ -192,29 +192,6 @@ mozc_cc_binary(
|
||||
],
|
||||
)
|
||||
|
||||
mozc_cc_library(
|
||||
name = "converter",
|
||||
srcs = ["converter.cc"],
|
||||
hdrs = ["converter.h"],
|
||||
visibility = [
|
||||
], # for mozc_transliterator
|
||||
deps = [
|
||||
"//composer:table",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
mozc_cc_test(
|
||||
name = "converter_test",
|
||||
size = "small",
|
||||
srcs = ["converter_test.cc"],
|
||||
deps = [
|
||||
":converter",
|
||||
"//composer:table",
|
||||
"//testing:gunit_main",
|
||||
],
|
||||
)
|
||||
|
||||
mozc_cc_library(
|
||||
name = "mode_switching_handler",
|
||||
srcs = ["mode_switching_handler.cc"],
|
||||
@ -238,17 +215,6 @@ mozc_cc_test(
|
||||
],
|
||||
)
|
||||
|
||||
mozc_cc_binary(
|
||||
name = "converter_main",
|
||||
srcs = ["converter_main.cc"],
|
||||
deps = [
|
||||
":converter",
|
||||
"//base:init_mozc",
|
||||
"//composer:table",
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
],
|
||||
)
|
||||
|
||||
mozc_cc_library(
|
||||
name = "special_key",
|
||||
srcs = ["special_key.cc"],
|
||||
|
@ -1,67 +0,0 @@
|
||||
// Copyright 2010-2021, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Converter from a Roman string to a Hiragana string
|
||||
|
||||
#include "composer/internal/converter.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "composer/table.h"
|
||||
|
||||
namespace mozc {
|
||||
namespace composer {
|
||||
|
||||
// ========================================
|
||||
// Converter
|
||||
// ========================================
|
||||
|
||||
void Converter::Convert(const absl::string_view input,
|
||||
std::string* output) const {
|
||||
std::string key(input);
|
||||
output->clear(); // equivalent to output->assign("")
|
||||
while (!key.empty()) {
|
||||
size_t key_length;
|
||||
bool fixed;
|
||||
const Entry* entry = table_.LookUpPrefix(key, &key_length, &fixed);
|
||||
if (entry == nullptr) {
|
||||
output->append(key, 0, 1);
|
||||
key.erase(0, 1);
|
||||
} else {
|
||||
output->append(entry->result());
|
||||
key = absl::StrCat(entry->pending(), key.substr(key_length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace composer
|
||||
} // namespace mozc
|
@ -1,60 +0,0 @@
|
||||
// Copyright 2010-2021, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Converter from a Roman string to a Hiragana string
|
||||
|
||||
#ifndef MOZC_COMPOSER_INTERNAL_CONVERTER_H_
|
||||
#define MOZC_COMPOSER_INTERNAL_CONVERTER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace mozc {
|
||||
namespace composer {
|
||||
|
||||
class Table;
|
||||
|
||||
class Converter {
|
||||
public:
|
||||
explicit Converter(const Table& table) : table_(table) {}
|
||||
|
||||
Converter(const Converter&) = delete;
|
||||
Converter& operator=(const Converter&) = delete;
|
||||
|
||||
void Convert(absl::string_view input, std::string* output) const;
|
||||
|
||||
private:
|
||||
const Table& table_;
|
||||
};
|
||||
|
||||
} // namespace composer
|
||||
} // namespace mozc
|
||||
|
||||
#endif // MOZC_COMPOSER_INTERNAL_CONVERTER_H_
|
@ -1,56 +0,0 @@
|
||||
// Copyright 2010-2021, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (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 <iostream> // NOLINT
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "base/init_mozc.h"
|
||||
#include "composer/internal/converter.h"
|
||||
#include "composer/table.h"
|
||||
|
||||
ABSL_FLAG(std::string, table, "system://romanji-hiragana.tsv",
|
||||
"preedit conversion table file.");
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
mozc::InitMozc(argv[0], &argc, &argv);
|
||||
|
||||
mozc::composer::Table table;
|
||||
table.LoadFromFile(absl::GetFlag(FLAGS_table).c_str());
|
||||
|
||||
mozc::composer::Converter converter(table);
|
||||
|
||||
std::string command;
|
||||
std::string result;
|
||||
while (std::getline(std::cin, command)) {
|
||||
converter.Convert(command, &result);
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
// Copyright 2010-2021, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (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 "composer/internal/converter.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
#include "composer/table.h"
|
||||
#include "testing/gunit.h"
|
||||
|
||||
namespace mozc {
|
||||
namespace {
|
||||
|
||||
void InitTable(mozc::composer::Table *table) {
|
||||
table->AddRule("a", "あ", "");
|
||||
table->AddRule("i", "い", "");
|
||||
table->AddRule("ka", "か", "");
|
||||
table->AddRule("ki", "き", "");
|
||||
table->AddRule("ku", "く", "");
|
||||
table->AddRule("ke", "け", "");
|
||||
table->AddRule("ko", "こ", "");
|
||||
table->AddRule("kk", "っ", "k");
|
||||
table->AddRule("na", "な", "");
|
||||
table->AddRule("ni", "に", "");
|
||||
table->AddRule("n", "ん", "");
|
||||
table->AddRule("nn", "ん", "");
|
||||
}
|
||||
|
||||
TEST(ConverterTest, Converter) {
|
||||
static const struct TestCase {
|
||||
const char *input;
|
||||
const char *expected_output;
|
||||
} test_cases[] = {
|
||||
{"a", "あ"},
|
||||
{"ka", "か"},
|
||||
{"ki", "き"},
|
||||
{"ku", "く"},
|
||||
{"kk", "っk"},
|
||||
{"aka", "あか"},
|
||||
{"kakizkka", "かきzっか"},
|
||||
{"nankanai?", "なんかない?"},
|
||||
{"nannkanain?", "なんかないん?"},
|
||||
{"nannkanain", "なんかないん"},
|
||||
};
|
||||
static const int size = std::size(test_cases);
|
||||
|
||||
mozc::composer::Table table;
|
||||
InitTable(&table);
|
||||
mozc::composer::Converter converter(table);
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
const TestCase &test = test_cases[i];
|
||||
std::string output;
|
||||
converter.Convert(test.input, &output);
|
||||
EXPECT_EQ(output, test.expected_output);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mozc
|
Reference in New Issue
Block a user