js-opencc 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -10
- package/README.zh-Hant.md +26 -10
- package/dist/bundles/cn2t.js +30 -13
- package/dist/bundles/full.d.ts +2 -2
- package/dist/bundles/full.js +20 -7
- package/dist/bundles/t2cn.js +25 -13
- package/dist/converter.d.ts +13 -6
- package/dist/converter.js +28 -18
- package/dist/core.d.ts +5 -1
- package/dist/core.js +5 -1
- package/dist/dict/HKVariantsPhrases.js +1 -1
- package/dist/dict/JPShinjitaiCharactersRev.js +1 -1
- package/dist/dict/STPhrases.js +1 -1
- package/dist/dict/STPhrases_GeneratedFromRegionalPhrases.js +1 -1
- package/dist/dict/SealCharacters.d.ts +2 -0
- package/dist/dict/SealCharacters.js +2 -0
- package/dist/dict/SealCharactersRev.d.ts +2 -0
- package/dist/dict/SealCharactersRev.js +2 -0
- package/dist/dict/SealVariants.d.ts +2 -0
- package/dist/dict/SealVariants.js +2 -0
- package/dist/dict/SealVariantsRev.d.ts +2 -0
- package/dist/dict/SealVariantsRev.js +2 -0
- package/dist/dict/TSCharacters.js +1 -1
- package/dist/dict/TSPhrases.js +1 -1
- package/dist/dict/TWPhrases.js +1 -1
- package/dist/dict/TWPhrasesRev.js +1 -1
- package/dist/dict/TWVariants.js +1 -1
- package/dist/dict/TWVariantsRev.js +1 -1
- package/dist/dict/index.js +4 -0
- package/dist/presets.d.ts +26 -11
- package/dist/presets.js +39 -21
- package/dist/umd/cn2t.js +75 -40
- package/dist/umd/cn2t.js.map +1 -1
- package/dist/umd/cn2t.min.js +1 -1
- package/dist/umd/cn2t.min.js.map +1 -1
- package/dist/umd/full.js +108 -69
- package/dist/umd/full.js.map +1 -1
- package/dist/umd/full.min.js +1 -1
- package/dist/umd/full.min.js.map +1 -1
- package/dist/umd/t2cn.js +73 -39
- package/dist/umd/t2cn.js.map +1 -1
- package/dist/umd/t2cn.min.js +1 -1
- package/dist/umd/t2cn.min.js.map +1 -1
- package/package.json +1 -1
package/dist/presets.js
CHANGED
|
@@ -3,13 +3,20 @@
|
|
|
3
3
|
* Defines dictionary mappings for different Chinese variants
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Conversion steps from a variant to OpenCC standard.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* 值 = **步骤列表**,按 OpenCC `conversion_chain` 的顺序依次执行;每一步是一个字典名单,
|
|
9
|
+
* 整个名单合进一个 trie。名单**内部**的顺序是 OpenCC 顺序的反面:上游首匹配即停,我们的
|
|
10
|
+
* trie 后写覆盖,所以优先级最高的(词组字典)要排在**最后**。步骤之间不反转——步骤就是
|
|
11
|
+
* 上游那一串 `dict`,一步对应一个 `conversion_chain` 元素。
|
|
12
|
+
*
|
|
13
|
+
* 步内可以合并、跨步不许合并:`group / union` 就是一个 trie,而先后两个步骤是两次 passes。
|
|
14
|
+
* 小篆两侧各两步(`年 →(SealVariants) 秊 →(SealCharactersRev) 小篆`),并进一个 trie 只走
|
|
15
|
+
* 一遍,第二次的输入根本不是 `秊`。链对账在 `scripts/sync-opencc.ts` 里按步比 upstream
|
|
16
|
+
* 的 `conversion_chain`,拍平它会当场红。
|
|
17
|
+
*
|
|
18
|
+
* Each array is ONE conversion step, merged into a single trie. Chains mirror
|
|
19
|
+
* `tw2t` / `hk2t` / `tw2sp` / `hk2sp` in OpenCC's data/config.
|
|
13
20
|
*/
|
|
14
21
|
export const variants2standard = {
|
|
15
22
|
// The generated dict sits between: upstream's group is
|
|
@@ -17,33 +24,38 @@ export const variants2standard = {
|
|
|
17
24
|
// order STPhrases stays highest. Its value is the point — 出租车 must become
|
|
18
25
|
// 出租車 as a pinned unit (char-wise conversion could pick wrong variants for
|
|
19
26
|
// ambiguous characters), and segmentation needs it as a boundary entry.
|
|
20
|
-
cn: ["STCharacters", "STPhrases_GeneratedFromRegionalPhrases", "STPhrases"],
|
|
21
|
-
hk: ["HKVariantsRev", "HKVariantsRevPhrases"],
|
|
22
|
-
hkp: ["HKVariantsRev", "HKVariantsRevPhrases", "HKPhrasesRev"],
|
|
23
|
-
tw: ["TWVariantsRev", "TWVariantsRevPhrases"],
|
|
24
|
-
twp: ["TWVariantsRev", "TWVariantsRevPhrases", "TWPhrasesRev"],
|
|
25
|
-
jp: ["JPShinjitaiCharacters", "JPShinjitaiPhrases"],
|
|
27
|
+
cn: [["STCharacters", "STPhrases_GeneratedFromRegionalPhrases", "STPhrases"]],
|
|
28
|
+
hk: [["HKVariantsRev", "HKVariantsRevPhrases"]],
|
|
29
|
+
hkp: [["HKVariantsRev", "HKVariantsRevPhrases", "HKPhrasesRev"]],
|
|
30
|
+
tw: [["TWVariantsRev", "TWVariantsRevPhrases"]],
|
|
31
|
+
twp: [["TWVariantsRev", "TWVariantsRevPhrases", "TWPhrasesRev"]],
|
|
32
|
+
jp: [["JPShinjitaiCharacters", "JPShinjitaiPhrases"]],
|
|
33
|
+
// seal2t.json 的两步,顺序照上游:先 小篆 → 现代汉字,再还原《說文》隶定字形。
|
|
34
|
+
seal: [["SealCharacters"], ["SealVariantsRev"]],
|
|
26
35
|
};
|
|
27
36
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
37
|
+
* Conversion steps from OpenCC standard to a variant. Same ordering rules as
|
|
38
|
+
* {@link variants2standard}; chains mirror `t2tw` / `t2hk` / `s2twp` / `s2hkp`.
|
|
30
39
|
*
|
|
31
40
|
* The `*VariantsPhrases` dicts are what keep proper nouns from being
|
|
32
41
|
* over-converted (張棟樑 must not become 張棟梁, 純喫茶 not 純吃茶) — dropping
|
|
33
42
|
* them silently diverges from OpenCC on hundreds of entries.
|
|
34
43
|
*/
|
|
35
44
|
export const standard2variants = {
|
|
36
|
-
cn: ["TSCharacters", "TSPhrases"],
|
|
37
|
-
hk: ["HKVariants", "HKVariantsPhrases"],
|
|
38
|
-
hkp: ["HKVariants", "HKVariantsPhrases", "HKPhrases"],
|
|
39
|
-
tw: ["TWVariants", "TWVariantsPhrases"],
|
|
40
|
-
twp: ["TWVariants", "TWVariantsPhrases", "TWPhrases"],
|
|
41
|
-
jp: ["JPShinjitaiCharactersRev"],
|
|
45
|
+
cn: [["TSCharacters", "TSPhrases"]],
|
|
46
|
+
hk: [["HKVariants", "HKVariantsPhrases"]],
|
|
47
|
+
hkp: [["HKVariants", "HKVariantsPhrases", "HKPhrases"]],
|
|
48
|
+
tw: [["TWVariants", "TWVariantsPhrases"]],
|
|
49
|
+
twp: [["TWVariants", "TWVariantsPhrases", "TWPhrases"]],
|
|
50
|
+
jp: [["JPShinjitaiCharactersRev"]],
|
|
51
|
+
// t2seal.json 的两步:现代标准字 →《說文》隸定字,然后 汉字 → 小篆。
|
|
52
|
+
// 顺序不能并,理由见 {@link variants2standard} 的「跨步不许合并」。
|
|
53
|
+
seal: [["SealVariants"], ["SealCharactersRev"]],
|
|
42
54
|
};
|
|
43
55
|
/**
|
|
44
56
|
* All dictionary file names
|
|
45
57
|
*/
|
|
46
|
-
export const allDictFiles = [...new Set([...Object.values(variants2standard).flat(), ...Object.values(standard2variants).flat()])];
|
|
58
|
+
export const allDictFiles = [...new Set([...Object.values(variants2standard).flat(2), ...Object.values(standard2variants).flat(2)])];
|
|
47
59
|
/** Traditional variants that carry their own regional vocabulary tables. */
|
|
48
60
|
const REGIONAL_VARIANTS = new Set(["tw", "twp", "hk", "hkp"]);
|
|
49
61
|
/**
|
|
@@ -72,6 +84,12 @@ const REGIONAL_VARIANTS = new Set(["tw", "twp", "hk", "hkp"]);
|
|
|
72
84
|
* `jp` is excluded deliberately: Shinjitai conversion has no phrase table
|
|
73
85
|
* keyed in the source script, and OpenCC declares no segmentation for it.
|
|
74
86
|
*
|
|
87
|
+
* `seal` likewise gets no cut, and for a reason worth keeping straight: its
|
|
88
|
+
* extra steps map single characters only, so no phrase dictionary is around to
|
|
89
|
+
* bite across a boundary — a multi-step chain is not by itself a reason to
|
|
90
|
+
* segment. `scripts/sync-opencc.ts` re-checks that no config we skip here ever
|
|
91
|
+
* grows a `segmentation` upstream.
|
|
92
|
+
*
|
|
75
93
|
* ## The second segmentation dict: `STPhrases_GeneratedFromRegionalPhrases`
|
|
76
94
|
*
|
|
77
95
|
* OpenCC's `s2*` configs segment on **two** dictionaries — `STPhrases` plus a
|