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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document compiles the Open Chinese Convert (OpenCC) project information to
## Data and Configuration
- Dictionaries are maintained in `data/dictionary/*.txt`, covering phrases, characters, regional differences, Japanese new characters, and other topic files; converted to `.ocd2` during build for acceleration.
- Default configurations are located in `data/config/`, such as `s2t.json`, `t2s.json`, `s2tw.json`, etc., defining segmenter types, dictionaries used, and combination methods.
- `SealCharacters.txt` (Unicode 18.0 Seal block → modern CJK equivalent) is derived from the UCD `SealSources.txt` `kSEAL_MCJK` property (the generator is not checked in); keep it in line with the UCD data and list any deviation in the file header. `kSEAL_MCJK` values are strict 說文 transcriptions (隸定字, e.g. `秊`, `歬`, `𡭔`), so `SealVariants.txt` maps modern standard characters (and their regional variants) to those forms (`年 -> 秊`); only same-character variant forms belong there, not 本字/假借 substitutions. Both reverses (`SealCharactersRev`, `SealVariantsRev`) are produced at build time like `TWVariantsRev`. Chains: `t2seal` = `SealVariants -> SealCharactersRev`, `seal2t` = `SealCharacters -> SealVariantsRev`; a self-mapping plus `@reverse-prefer` in `SealVariants.txt` keeps a 隸定字 that is itself standard (e.g. `裏`, `爲`) unchanged in `seal2t`.
- Jieba-backed plugin configurations live under `plugins/jieba/data/config/`, such as `s2twp_jieba.json`; they are packaged only when the optional `opencc-jieba` plugin is built or distributed.
- `data/scheme` and `data/scripts` provide dictionary compilation scripts and specification validation tools.

Expand Down
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ OpenCC 以 [Apache License 2.0](LICENSE) 釋出。提交 Pull Request、issue/co
- `JPShinjitaiCharacters.txt` - 日文新舊字體對照(單字)
- `JPShinjitaiPhrases.txt` - 日文新字體到舊字體(詞組,亦包含少量和製漢語詞匯轉換)

- **小篆對照**(僅供探索性研究,不建議用於生產環境)
- `SealCharacters.txt` - Unicode 18.0 篆書區塊(U+3D000..U+3FC3F)小篆到現代漢字對照(單字)。內容取自 Unicode `SealSources.txt` 的 `kSEAL_MCJK` 屬性,應與之保持一致,修正請附 UCD 依據,例外須列於檔頭;反向的 `SealCharactersRev.txt` 於建置時生成,供 `t2seal` 使用
- `SealVariants.txt` - 現代標準字(含臺、港異體)到《說文》隸定字對照(單字),如 `年 → 秊`、`前 → 歬`,用來銜接 `kSEAL_MCJK` 的隸定字形。只收同字異形,不收本字、假借(如 `他 → 佗`);反向的 `SealVariantsRev.txt` 於建置時生成,供 `seal2t` 使用

### 2. 詞典格式規範

詞典檔案使用 **Tab 字元**(`\t`)分隔來源詞與目標詞,**請勿使用空格**。
Expand Down Expand Up @@ -300,7 +304,7 @@ python3 scripts/add_testcase.py \

此腳本目前生成以下配置的結果:`s2t`、`s2tw`、`s2twp`、`s2hk`、`t2s`、
`t2tw`、`t2hk`、`tw2s`、`tw2sp`、`tw2t`、`hk2s`、`hk2t`。若需要測試
`jp2t`、`t2jp`,請手動在 `expected` 中加入對應結果。
`jp2t`、`t2jp`、`t2seal`、`seal2t`、`s2seal`,請手動在 `expected` 中加入對應結果。

### 可用的轉換配置

Expand All @@ -324,6 +328,9 @@ python3 scripts/add_testcase.py \
下列模式僅供探索性研究,不建議用於生產環境:
- `jp2t` - 日文新字體到舊字體
- `t2jp` - 日文舊字體到新字體
- `t2seal` - 繁體漢字到小篆(Unicode 18.0 篆書區塊)
- `s2seal` - 簡體到小篆(`s2t` 後接 `t2seal`)
- `seal2t` - 小篆(Unicode 18.0 篆書區塊)到繁體漢字

### Golden 測試

Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* **公開 API**:
* `ConversionCandidates.hpp`(`GetAllConversions`)與 `ConversionAmbiguities.hpp`(`ConvertWithAmbiguities`、`AmbiguityStream`)移入已安裝標頭集並納入相容性契約,文件中「內部、不穩定、不隨標頭安裝」的但書一併移除;Bazel 目標的 visibility 亦由 `//src:__pkg__` 放寬為公開。這兩個 API 的目標使用者本來就是輸入法引擎——librime 的 `Simplifier` 以 `GetAllConversions` 取代自行走訪 `Dict`/`DictEntry` 的實作,以 `ConvertWithAmbiguities` 實作隨機取字模式——而私有標頭不會被安裝,下游在對接系統安裝的 OpenCC 時根本引用不到。
* `StreamWindow.hpp` 隨之安裝,因為 `ConversionAmbiguities.hpp` 需要其中的 `kDefaultStreamKeepChars` 作為 `AmbiguityStream` 的預設引數。該標頭內容位於 `opencc::internal` 命名空間,仍屬實作細節,不提供相容性保證。
* **小篆對照(實驗性)**:
* 新增 Unicode 18.0 篆書區塊(Seal,U+3D000..U+3FC3F,共 11,328 字)與現代漢字的雙向對照。`SealCharacters.txt`(小篆 → 漢字)取自 UCD `SealSources.txt` 的 `kSEAL_MCJK` 屬性,反向詞典 `SealCharactersRev`(漢字 → 小篆)與 `TWVariantsRev` 等一樣於建置時生成。一個漢字對應多個小篆時(共 94 字),反向預設取碼位最小者(通常為《說文解字》正篆,重文在後),另有 4 字以 `@reverse-prefer` 改取版本來源(藤花榭本、陳昌治本、汲古閣本、段注本)更完整者。
* 新增 `SealVariants.txt`(現代標準字 → 《說文》隸定字,約 1,000 字,如 `年 → 秊`、`前 → 歬`、`小 → 𡭔`),銜接 `kSEAL_MCJK` 的隸定字形;`t2seal` 先經此表再查 `SealCharactersRev`,`seal2t` 則先查 `SealCharacters` 再以建置時生成的 `SealVariantsRev` 還原為標準字。此表由 shuowen.org 開放數據(Apache-2.0)的字頭序列與 `kSEAL_MCJK` 對齊,並輔以人工審閱的 Unihan 異體資料整理而成。另,《說文》「玉」(U+3D06D)的 `kSEAL_MCJK` 為「王」,與「王」(U+3D068)衝突,詞典中改對應「玉」。
* 新增配置 `t2seal.json`(繁體漢字 → 小篆)、`seal2t.json`(小篆 → 繁體漢字)與 `s2seal.json`(簡體 → 小篆,即 `s2t` 後接 `t2seal`),已加入 CLI 說明、npm CLI 內建配置表與測試案例;僅供探索性研究,顯示需搭配支援 Unicode 18.0 篆書區塊的字型。

## Version 1.4.2

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ These ports are community-maintained and may not always track upstream updates.

* `t2jp.json` **Old Japanese Kanji (Kyūjitai)** to **New Japanese Kanji (Shinjitai)** / **日文舊字體** 到 **日文新字體**
* `jp2t.json` **New Japanese Kanji (Shinjitai)** to **Old Japanese Kanji (Kyūjitai)** / **日文新字體** 到 **日文舊字體**,並將少量日文詞組轉換爲對應中文
* `t2seal.json` **Traditional Chinese Characters** to **Small Seal Script (Unicode 18.0 Seal block)** / **繁體漢字** 到 **小篆(Unicode 18.0 篆書區塊 U+3D000..U+3FC3F)**,需搭配支援該區塊的字型顯示
* `s2seal.json` **Simplified Chinese** to **Small Seal Script (Unicode 18.0 Seal block)** / **簡體** 到 **小篆**,相當於 `s2t` 後接 `t2seal`。反方向(小篆到簡體)請依序執行 `seal2t` 與 `t2s`:分詞只在輸入端進行一次,小篆輸入無法為 `t2s` 的詞組轉換分詞
* `seal2t.json` **Small Seal Script (Unicode 18.0 Seal block)** to **Traditional Chinese Characters** / **小篆(Unicode 18.0 篆書區塊)** 到 **繁體漢字**,依 Unicode `SealSources.txt` 的 `kSEAL_MCJK` 屬性對應,並以 `SealVariants.txt` 銜接現代標準字與《說文》隸定字(如 `年`/`秊`);《說文》未收之字(如 `你`、`們`)保持不變

#### 指定配置文件

Expand Down
25 changes: 25 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set(
HKPhrasesRev
JPShinjitaiCharacters
JPShinjitaiPhrases
SealCharacters
SealVariants
)

set(
Expand All @@ -41,6 +43,8 @@ set(
TWVariantsRev
HKVariantsRev
JPShinjitaiCharactersRev
SealCharactersRev
SealVariantsRev
)

set(DICTS ${DICTS_RAW} ${DICTS_GENERATED})
Expand Down Expand Up @@ -134,6 +138,24 @@ set(
${DICT_REVERSE_BIN} ${DICT_JPShinjitaiCharactersRev_GENERATING_INPUT} JPShinjitaiCharactersRev.txt
)

set(
DICT_SealCharactersRev_GENERATING_INPUT
${DICT_DIR}/SealCharacters.txt
)
set(
DICT_SealCharactersRev_GENERATING_COMMAND
${DICT_REVERSE_BIN} ${DICT_SealCharactersRev_GENERATING_INPUT} SealCharactersRev.txt
)

set(
DICT_SealVariantsRev_GENERATING_INPUT
${DICT_DIR}/SealVariants.txt
)
set(
DICT_SealVariantsRev_GENERATING_COMMAND
${DICT_REVERSE_BIN} ${DICT_SealVariantsRev_GENERATING_INPUT} SealVariantsRev.txt
)

add_custom_target(
copy_libopencc_to_dir_of_opencc_dict
COMMENT
Expand Down Expand Up @@ -273,12 +295,15 @@ set(CONFIG_FILES
config/jp2t.json
config/s2hk.json
config/s2hkp.json
config/s2seal.json
config/s2t.json
config/s2tw.json
config/s2twp.json
config/seal2t.json
config/t2hk.json
config/t2jp.json
config/t2s.json
config/t2seal.json
config/t2tw.json
config/tw2s.json
config/tw2sp.json
Expand Down
27 changes: 27 additions & 0 deletions data/config/s2seal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Simplified Chinese to Small Seal Script",
"normalization": [
{ "dict": { "type": "ocd2", "file": "CJK_Compatibility_Ideographs.ocd2" } }
],
"conversion_chain": [
{
"dict": {
"type": "group",
"match_policy": "short_circuit",
"dicts": [
{
"type": "group",
"match_policy": "union",
"dicts": [
{ "type": "ocd2", "file": "STPhrases.ocd2" },
{ "type": "ocd2", "file": "STPhrases_GeneratedFromRegionalPhrases.ocd2" }
]
},
{ "type": "ocd2", "file": "STCharacters.ocd2" }
]
}
},
{ "dict": { "type": "ocd2", "file": "SealVariants.ocd2" } },
{ "dict": { "type": "ocd2", "file": "SealCharactersRev.ocd2" } }
]
}
10 changes: 10 additions & 0 deletions data/config/seal2t.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Small Seal Script to Traditional Chinese Characters",
"normalization": [
{ "dict": { "type": "ocd2", "file": "CJK_Compatibility_Ideographs.ocd2" } }
],
"conversion_chain": [
{ "dict": { "type": "ocd2", "file": "SealCharacters.ocd2" } },
{ "dict": { "type": "ocd2", "file": "SealVariantsRev.ocd2" } }
]
}
10 changes: 10 additions & 0 deletions data/config/t2seal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Traditional Chinese Characters to Small Seal Script",
"normalization": [
{ "dict": { "type": "ocd2", "file": "CJK_Compatibility_Ideographs.ocd2" } }
],
"conversion_chain": [
{ "dict": { "type": "ocd2", "file": "SealVariants.ocd2" } },
{ "dict": { "type": "ocd2", "file": "SealCharactersRev.ocd2" } }
]
}
10 changes: 10 additions & 0 deletions data/dictionary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ exports_files(
"TWVariants",
"HKVariants",
"JPShinjitaiCharacters",
"SealCharacters",
"SealVariants",
]
]

Expand All @@ -45,15 +47,23 @@ TEXT_DICTS = glob(
"TWVariantsRev.txt",
"HKVariantsRev.txt",
"JPShinjitaiCharactersRev.txt",
"SealCharactersRev.txt",
"SealVariantsRev.txt",
]

# Character dictionaries are expected to contain non-BMP characters: the
# Small Seal dictionaries live entirely in the Seal block (U+3D000..U+3FC3F).
NON_BMP_TEXT_DICTS = [
txt
for txt in TEXT_DICTS
if txt not in [
"STCharacters.txt",
"TSCharacters.txt",
"TSCharactersExt.txt",
"SealCharacters.txt",
"SealCharactersRev.txt",
"SealVariants.txt",
"SealVariantsRev.txt",
]
]

Expand Down
3 changes: 2 additions & 1 deletion data/dictionary/CJK_Compatibility_Ideographs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# License: Apache-2.0 (see LICENSE)
# Source: https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt (accessed 2026-06-07)
# Used in configs: all built-in configs (hk2s, hk2sp, hk2t, jp2t, s2hk, s2hkp,
# s2t, s2tw, s2twp, t2hk, t2jp, t2s, t2tw, tw2s, tw2sp, tw2t) via the
# s2seal, s2t, s2tw, s2twp, seal2t, t2hk, t2jp, t2s, t2seal, t2tw, tw2s, tw2sp, tw2t)
# via the
# normalization field, which runs this dictionary as a pre-pass before
# segmentation and conversion.
# Compatible OpenCC implementations are encouraged to apply the same
Expand Down
Loading
Loading