Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ Rules:
* `s2tw.json` **Simplified Chinese** to **Traditional Chinese (Taiwan Standard)** / **簡體** 到 **台灣正體**
* `tw2s.json` **Traditional Chinese (Taiwan Standard)** to **Simplified Chinese** / **台灣正體** 到 **簡體**
* `s2hk.json` **Simplified Chinese** to **Traditional Chinese (Hong Kong variant)** / **簡體** 到 **香港繁體**
* `s2hkp.json` **Simplified Chinese** to **Traditional Chinese (Hong Kong variant, with Hong Kong Phrases)** / **簡體** 到 **香港繁體(香港常用詞彙)**
* `hk2s.json` **Traditional Chinese (Hong Kong variant)** to **Simplified Chinese** / **香港繁體** 到 **簡體**
* `hk2sp.json` **Traditional Chinese (Hong Kong variant)** to **Simplified Chinese (Mainland China Phrases)** / **香港繁體** 到 **簡體(含中國大陸常用詞彙)**
* `s2twp.json` **Simplified Chinese** to **Traditional Chinese (Taiwan Standard, with Taiwan Phrases)** / **簡體** 到 **台灣正體(含台灣常用詞彙)**
* `tw2sp.json` **Traditional Chinese (Taiwan Standard)** to **Simplified Chinese (Mainland China Phrases)** / **台灣正體** 到 **簡體(含中國大陸常用詞彙)**
* `t2tw.json` **Traditional Chinese (OpenCC Standard)** to **Traditional Chinese (Taiwan Standard)** / **OpenCC 標準繁體** 到 **台灣正體**
Expand Down
4 changes: 4 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ set(
HKVariantsPhrases
HKVariants
HKVariantsRevPhrases
HKPhrases
HKPhrasesRev
JPVariants
JPShinjitaiCharacters
JPShinjitaiPhrases
Expand Down Expand Up @@ -157,9 +159,11 @@ endforeach(DICT)

set(CONFIG_FILES
config/hk2s.json
config/hk2sp.json
config/hk2t.json
config/jp2t.json
config/s2hk.json
config/s2hkp.json
config/s2t.json
config/s2tw.json
config/s2twp.json
Expand Down
33 changes: 33 additions & 0 deletions data/config/hk2sp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "Traditional Chinese (Hong Kong variant) to Simplified Chinese (with phrases)",
"segmentation": {
"type": "mmseg",
"dict": { "type": "ocd2", "file": "TSPhrases.ocd2" }
},
"conversion_chain": [
{
"dict": {
"type": "group",
"dicts": [
{ "type": "ocd2", "file": "HKPhrasesRev.ocd2" },
{ "type": "ocd2", "file": "HKVariantsRevPhrases.ocd2" },
{ "type": "ocd2", "file": "HKVariantsRev.ocd2" }
]
}
},
{
"dict": {
"type": "group",
"dicts": [
{ "type": "ocd2", "file": "TSPhrases.ocd2" },
{
"type": "ocd2",
"file": "TSCharactersExt.ocd2",
"may_output_tofu": true
},
{ "type": "ocd2", "file": "TSCharacters.ocd2" }
]
}
}
]
}
28 changes: 28 additions & 0 deletions data/config/s2hkp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Simplified Chinese to Traditional Chinese (Hong Kong variant, with phrases)",
"segmentation": {
"type": "mmseg",
"dict": { "type": "ocd2", "file": "STPhrases.ocd2" }
},
"conversion_chain": [
{
"dict": {
"type": "group",
"dicts": [
{ "type": "ocd2", "file": "STPhrases.ocd2" },
{ "type": "ocd2", "file": "STCharacters.ocd2" }
]
}
},
{
"dict": {
"type": "group",
"dicts": [
{ "type": "ocd2", "file": "HKPhrases.ocd2" },
{ "type": "ocd2", "file": "HKVariantsPhrases.ocd2" },
{ "type": "ocd2", "file": "HKVariants.ocd2" }
]
}
}
]
}
13 changes: 8 additions & 5 deletions data/dictionary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ filegroup(
]

cc_test(
name = "dictionary_TWPhrases_reverse_mapping_test",
name = "dictionary_phrases_reverse_mapping_test",
size = "small",
srcs = ["DictionaryReverseMappingTest.cpp"],
data = [
"HKPhrases.txt",
"HKPhrasesRev.txt",
"TWPhrases.txt",
"TWPhrasesRev.txt",
],
Expand All @@ -110,10 +112,11 @@ cc_test(
)

cc_test(
name = "dictionary_TWPhrases_segmentation_test",
name = "dictionary_phrases_segmentation_test",
size = "small",
srcs = ["DictionaryTaiwanPhraseSegmentationTest.cpp"],
srcs = ["DictionaryPhraseSegmentationTest.cpp"],
data = [
"HKPhrases.txt",
"STPhrases.txt",
"TWPhrases.txt",
],
Expand Down Expand Up @@ -192,8 +195,8 @@ test_suite(
":dictionary_" + txt[:-4] + "_test"
for txt in TEXT_DICTS
] + [
":dictionary_TWPhrases_reverse_mapping_test",
":dictionary_TWPhrases_segmentation_test",
":dictionary_phrases_reverse_mapping_test",
":dictionary_phrases_segmentation_test",
":dictionary_compatibility_ideographs_test",
":dictionary_phrase_character_dependency_test",
":dictionary_variant_rev_phrases_test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,26 @@ bool FindSTPhraseValueFragment(const std::string& key,
return false;
}

TEST(DictionaryTaiwanPhraseSegmentationTest,
TWPhrasesKeysAreCoveredBySTPhraseValues) {
void ExpectProperSegmentationCoverage(const std::string& phrasesName) {
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest());
ASSERT_NE(nullptr, runfiles);

const std::string stPhrasesFile =
runfiles->Rlocation("_main/data/dictionary/STPhrases.txt");
const std::string twPhrasesFile =
runfiles->Rlocation("_main/data/dictionary/TWPhrases.txt");
const std::string phrasesFile =
runfiles->Rlocation("_main/data/dictionary/" + phrasesName + ".txt");

try {
LexiconPtr twPhrases = LoadLexicon(twPhrasesFile);
ASSERT_NE(twPhrases, nullptr);
LexiconPtr phrases = LoadLexicon(phrasesFile);
ASSERT_NE(phrases, nullptr);

std::vector<STPhraseValue> stValues = LoadSTPhraseValues(stPhrasesFile);
ASSERT_FALSE(stValues.empty());

std::ostringstream missing;
size_t missingCount = 0;
for (size_t i = 0; i < twPhrases->Length(); ++i) {
const std::string key = twPhrases->At(i)->Key();
for (size_t i = 0; i < phrases->Length(); ++i) {
const std::string key = phrases->At(i)->Key();
if (IsCoveredBySTPhraseValue(key, stValues)) {
continue;
}
Expand All @@ -174,27 +173,37 @@ TEST(DictionaryTaiwanPhraseSegmentationTest,
}

++missingCount;
missing << "TWPhrases key \"" << key
missing << phrasesName << " key \"" << key
<< "\" is not covered by any STPhrases value.\n"
<< " Conflicting STPhrases record: STPhrases.txt:"
<< risk.lineNumber << " \"" << risk.key
<< "\" -> \"" << risk.value << "\"\n"
<< " The existing value appears as a " << risk.category
<< " fragment of the Taiwan phrase key.\n";
<< " fragment of the " << phrasesName << " key.\n";
}

EXPECT_EQ(0U, missingCount)
<< "Potential missing STPhrases entries for s2twp segmentation:\n"
<< "Potential missing STPhrases entries for " << phrasesName << ":\n"
<< missing.str();
} catch (const Exception& ex) {
FAIL() << "Exception: " << ex.what();
} catch (const std::exception& ex) {
FAIL() << "std::exception: " << ex.what();
} catch (...) {
FAIL() << "Unknown exception thrown during Taiwan phrase segmentation "
FAIL() << "Unknown exception thrown during " << phrasesName << " segmentation "
"check.";
}
}

TEST(DictionaryPhraseSegmentationTest,
HKPhrasesKeysAreCoveredBySTPhraseValues) {
ExpectProperSegmentationCoverage("HKPhrases");
}

TEST(DictionaryPhraseSegmentationTest,
TWPhrasesKeysAreCoveredBySTPhraseValues) {
ExpectProperSegmentationCoverage("TWPhrases");
}

} // namespace
} // namespace opencc
38 changes: 23 additions & 15 deletions data/dictionary/DictionaryReverseMappingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ static FILE* OpenFile(const std::string& path) {
#endif
}

TEST(DictionaryReverseMappingTest, TWPhrasesReverseMapping) {
void ExpectRevComplete(const std::string& phrasesName) {
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest());
ASSERT_NE(nullptr, runfiles);

const std::string twPhrasesFile =
runfiles->Rlocation("_main/data/dictionary/TWPhrases.txt");
const std::string twPhrasesRevFile =
runfiles->Rlocation("_main/data/dictionary/TWPhrasesRev.txt");
const std::string phrasesFile =
runfiles->Rlocation("_main/data/dictionary/" + phrasesName + ".txt");
const std::string phrasesRevFile =
runfiles->Rlocation("_main/data/dictionary/" + phrasesName + "Rev" + ".txt");

auto loadLexicon = [](const std::string& path) -> LexiconPtr {
FILE* fp = OpenFile(path);
Expand Down Expand Up @@ -62,28 +62,28 @@ TEST(DictionaryReverseMappingTest, TWPhrasesReverseMapping) {
};

try {
LexiconPtr twPhrases = loadLexicon(twPhrasesFile);
LexiconPtr twPhrasesRev = loadLexicon(twPhrasesRevFile);
LexiconPtr twPhrases = loadLexicon(phrasesFile);
LexiconPtr twPhrasesRev = loadLexicon(phrasesRevFile);
ASSERT_NE(twPhrases, nullptr);
ASSERT_NE(twPhrasesRev, nullptr);

auto twMap = buildMap(twPhrases);
auto twRevMap = buildMap(twPhrasesRev);
auto phrasesMap = buildMap(twPhrases);
auto phrasesRevMap = buildMap(twPhrasesRev);

for (const auto& entry : twMap) {
for (const auto& entry : phrasesMap) {
const std::string& key = entry.first;
for (const auto& value : entry.second) {
auto it = twRevMap.find(value);
EXPECT_TRUE(it != twRevMap.end() && it->second.count(key) > 0)
auto it = phrasesRevMap.find(value);
EXPECT_TRUE(it != phrasesRevMap.end() && it->second.count(key) > 0)
<< "Missing reverse mapping: " << key << " -> " << value;
}
}

for (const auto& entry : twRevMap) {
for (const auto& entry : phrasesRevMap) {
const std::string& key = entry.first;
for (const auto& value : entry.second) {
auto it = twMap.find(value);
EXPECT_TRUE(it != twMap.end() && it->second.count(key) > 0)
auto it = phrasesMap.find(value);
EXPECT_TRUE(it != phrasesMap.end() && it->second.count(key) > 0)
<< "Missing reverse mapping: " << key << " -> " << value;
}
}
Expand All @@ -96,5 +96,13 @@ TEST(DictionaryReverseMappingTest, TWPhrasesReverseMapping) {
}
}

TEST(DictionaryReverseMappingTest, HKPhrasesReverseMapping) {
ExpectRevComplete("HKPhrases");
}

TEST(DictionaryReverseMappingTest, TWPhrasesReverseMapping) {
ExpectRevComplete("TWPhrases");
}

} // namespace
} // namespace opencc
16 changes: 16 additions & 0 deletions data/dictionary/HKPhrases.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Open Chinese Convert (OpenCC) Dictionary
# File: HKPhrases.txt
# Format: key value(s) (values separated by spaces)
# License: Apache-2.0 (see LICENSE)
# Source: https://github.com/ByVoid/OpenCC
# Used in configs: s2hkp.json (via HKPhrases.ocd2)

寬帶 寬頻
幾率 機率 概率
搜索 搜尋
操作系統 作業系統
文件夾 資料夾
服務器 伺服器
概率 概率 機會率
編程語言 程式語言
隱私權 私隱權
17 changes: 17 additions & 0 deletions data/dictionary/HKPhrasesRev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Open Chinese Convert (OpenCC) Dictionary
# File: HKPhrasesRev.txt
# Format: key value(s) (values separated by spaces)
# License: Apache-2.0 (see LICENSE)
# Source: https://github.com/ByVoid/OpenCC
# Used in configs: hk2sp.json (via HKPhrasesRev.ocd2)

伺服器 服務器
作業系統 操作系統
寬頻 寬帶
搜尋 搜索
概率 概率 幾率
機會率 概率
機率 幾率
私隱權 隱私權
程式語言 編程語言
資料夾 文件夾
2 changes: 2 additions & 0 deletions node/configs.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"destination": "<(PRODUCT_DIR)",
"files": [
"../data/config/hk2s.json",
"../data/config/hk2sp.json",
"../data/config/hk2t.json",
"../data/config/jp2t.json",
"../data/config/s2hk.json",
"../data/config/s2hkp.json",
"../data/config/s2t.json",
"../data/config/s2tw.json",
"../data/config/s2twp.json",
Expand Down
16 changes: 16 additions & 0 deletions node/dicts.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@
"inputs": ["<(input)"],
"outputs": ["<(output_prefix)HKVariantsRevPhrases.ocd2"],
"action": ["node", "<(cmd)", "<(input)", "<@(_outputs)"]
}, {
"action_name": "HKPhrases",
"variables": {
"input": "<(input_prefix)HKPhrases.txt",
},
"inputs": ["<(input)"],
"outputs": ["<(output_prefix)HKPhrases.ocd2"],
"action": ["node", "<(cmd)", "<(input)", "<@(_outputs)"]
}, {
"action_name": "HKVariantsRev.txt",
"variables": {
Expand All @@ -172,6 +180,14 @@
"inputs": ["<(input)"],
"outputs": ["<(output_prefix)HKVariantsRev.ocd2"],
"action": ["node", "<(cmd)", "<(input)", "<@(_outputs)"]
}, {
"action_name": "HKPhrasesRev",
"variables": {
"input": "<(input_prefix)HKPhrasesRev.txt",
},
"inputs": ["<(input)"],
"outputs": ["<(output_prefix)HKPhrasesRev.ocd2"],
"action": ["node", "<(cmd)", "<(input)", "<@(_outputs)"]
}, {
"action_name": "JPVariantsRev.txt",
"variables": {
Expand Down
2 changes: 2 additions & 0 deletions plugins/jieba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ if (BUILD_OPENCC_JIEBA_PLUGIN AND OPENCC_ENABLE_INSTALL)

install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/data/config/hk2sp_jieba.json
${CMAKE_CURRENT_SOURCE_DIR}/data/config/s2hk_jieba.json
${CMAKE_CURRENT_SOURCE_DIR}/data/config/s2hkp_jieba.json
${CMAKE_CURRENT_SOURCE_DIR}/data/config/s2t_jieba.json
${CMAKE_CURRENT_SOURCE_DIR}/data/config/s2tw_jieba.json
${CMAKE_CURRENT_SOURCE_DIR}/data/config/s2twp_jieba.json
Expand Down
Loading
Loading