js-opencc 1.4.0 → 1.4.2
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 +118 -120
- package/README.zh-Hant.md +222 -0
- package/data/custom/CNTWPhrases.txt +6 -0
- package/dist/bundles/cn2t.d.ts +5 -4
- package/dist/bundles/cn2t.js +70 -13
- package/dist/bundles/full.d.ts +8 -3
- package/dist/bundles/full.js +42 -19
- package/dist/bundles/t2cn.d.ts +5 -4
- package/dist/bundles/t2cn.js +58 -11
- package/dist/converter.d.ts +11 -2
- package/dist/converter.js +60 -28
- package/dist/core.d.ts +120 -16
- package/dist/core.js +403 -51
- package/dist/dict/CNTWPhrases.d.ts +2 -3
- package/dist/dict/CNTWPhrases.js +2 -2
- package/dist/dict/HKPhrases.d.ts +2 -0
- package/dist/dict/HKPhrases.js +2 -0
- package/dist/dict/HKPhrasesRev.d.ts +2 -0
- package/dist/dict/HKPhrasesRev.js +2 -0
- package/dist/dict/HKVariants.d.ts +2 -3
- package/dist/dict/HKVariants.js +2 -2
- package/dist/dict/HKVariantsPhrases.d.ts +2 -0
- package/dist/dict/HKVariantsPhrases.js +2 -0
- package/dist/dict/HKVariantsRev.d.ts +2 -3
- package/dist/dict/HKVariantsRev.js +2 -2
- package/dist/dict/HKVariantsRevPhrases.d.ts +2 -3
- package/dist/dict/HKVariantsRevPhrases.js +2 -2
- package/dist/dict/JPShinjitaiCharacters.d.ts +2 -3
- package/dist/dict/JPShinjitaiCharacters.js +2 -2
- package/dist/dict/JPShinjitaiCharactersRev.d.ts +2 -3
- package/dist/dict/JPShinjitaiCharactersRev.js +2 -2
- package/dist/dict/JPShinjitaiPhrases.d.ts +2 -3
- package/dist/dict/JPShinjitaiPhrases.js +2 -2
- package/dist/dict/STCharacters.d.ts +2 -3
- package/dist/dict/STCharacters.js +2 -2
- package/dist/dict/STPhrases.d.ts +2 -3
- package/dist/dict/STPhrases.js +2 -2
- package/dist/dict/STPhrases_GeneratedFromRegionalPhrases.d.ts +2 -0
- package/dist/dict/STPhrases_GeneratedFromRegionalPhrases.js +2 -0
- package/dist/dict/TSCharacters.d.ts +2 -3
- package/dist/dict/TSCharacters.js +2 -2
- package/dist/dict/TSPhrases.d.ts +2 -3
- package/dist/dict/TSPhrases.js +2 -2
- package/dist/dict/TWPhrases.d.ts +2 -3
- package/dist/dict/TWPhrases.js +2 -2
- package/dist/dict/TWPhrasesRev.d.ts +2 -3
- package/dist/dict/TWPhrasesRev.js +2 -2
- package/dist/dict/TWVariants.d.ts +2 -3
- package/dist/dict/TWVariants.js +2 -2
- package/dist/dict/TWVariantsPhrases.d.ts +2 -0
- package/dist/dict/TWVariantsPhrases.js +2 -0
- package/dist/dict/TWVariantsRev.d.ts +2 -3
- package/dist/dict/TWVariantsRev.js +2 -2
- package/dist/dict/TWVariantsRevPhrases.d.ts +2 -3
- package/dist/dict/TWVariantsRevPhrases.js +2 -2
- package/dist/dict/index.d.ts +0 -1
- package/dist/dict/index.js +5 -1
- package/dist/html-converter.d.ts +0 -1
- package/dist/html-converter.js +65 -26
- package/dist/index.d.ts +2 -3
- package/dist/index.js +14 -5
- package/dist/presets.d.ts +92 -4
- package/dist/presets.js +113 -7
- package/dist/umd/cn2t.js +640 -102
- 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 +657 -126
- 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 +658 -107
- 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 +2 -1
- package/dist/bundles/cn2t.d.ts.map +0 -1
- package/dist/bundles/cn2t.js.map +0 -1
- package/dist/bundles/full.d.ts.map +0 -1
- package/dist/bundles/full.js.map +0 -1
- package/dist/bundles/t2cn.d.ts.map +0 -1
- package/dist/bundles/t2cn.js.map +0 -1
- package/dist/converter.d.ts.map +0 -1
- package/dist/converter.js.map +0 -1
- package/dist/core.d.ts.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/dict/CNTWPhrases.d.ts.map +0 -1
- package/dist/dict/CNTWPhrases.js.map +0 -1
- package/dist/dict/HKVariants.d.ts.map +0 -1
- package/dist/dict/HKVariants.js.map +0 -1
- package/dist/dict/HKVariantsRev.d.ts.map +0 -1
- package/dist/dict/HKVariantsRev.js.map +0 -1
- package/dist/dict/HKVariantsRevPhrases.d.ts.map +0 -1
- package/dist/dict/HKVariantsRevPhrases.js.map +0 -1
- package/dist/dict/JPShinjitaiCharacters.d.ts.map +0 -1
- package/dist/dict/JPShinjitaiCharacters.js.map +0 -1
- package/dist/dict/JPShinjitaiCharactersRev.d.ts.map +0 -1
- package/dist/dict/JPShinjitaiCharactersRev.js.map +0 -1
- package/dist/dict/JPShinjitaiPhrases.d.ts.map +0 -1
- package/dist/dict/JPShinjitaiPhrases.js.map +0 -1
- package/dist/dict/STCharacters.d.ts.map +0 -1
- package/dist/dict/STCharacters.js.map +0 -1
- package/dist/dict/STPhrases.d.ts.map +0 -1
- package/dist/dict/STPhrases.js.map +0 -1
- package/dist/dict/TSCharacters.d.ts.map +0 -1
- package/dist/dict/TSCharacters.js.map +0 -1
- package/dist/dict/TSPhrases.d.ts.map +0 -1
- package/dist/dict/TSPhrases.js.map +0 -1
- package/dist/dict/TWPhrases.d.ts.map +0 -1
- package/dist/dict/TWPhrases.js.map +0 -1
- package/dist/dict/TWPhrasesRev.d.ts.map +0 -1
- package/dist/dict/TWPhrasesRev.js.map +0 -1
- package/dist/dict/TWVariants.d.ts.map +0 -1
- package/dist/dict/TWVariants.js.map +0 -1
- package/dist/dict/TWVariantsRev.d.ts.map +0 -1
- package/dist/dict/TWVariantsRev.js.map +0 -1
- package/dist/dict/TWVariantsRevPhrases.d.ts.map +0 -1
- package/dist/dict/TWVariantsRevPhrases.js.map +0 -1
- package/dist/dict/index.d.ts.map +0 -1
- package/dist/dict/index.js.map +0 -1
- package/dist/html-converter.d.ts.map +0 -1
- package/dist/html-converter.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/presets.d.ts.map +0 -1
- package/dist/presets.js.map +0 -1
package/dist/core.js
CHANGED
|
@@ -2,27 +2,57 @@
|
|
|
2
2
|
* OpenCC JS - Core Conversion Engine
|
|
3
3
|
* Based on Trie data structure for efficient longest-match conversion
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* `input[i]` 起是不是一个合法的代理对(高代理后面真的跟着低代理)。
|
|
7
|
+
*
|
|
8
|
+
* 存在的唯一理由是防一类静默错误:热循环从 `codePointAt` 换成 `charCodeAt` 之后,
|
|
9
|
+
* 「孤立高代理」不再天然按一个单元处理——只判高代理就跳 2 会**吞掉它后面那个
|
|
10
|
+
* 字符**,那个字符于是永远参与不了匹配,输出少转一处且不报错。真实词典里没有
|
|
11
|
+
* 孤立代理,所以 556 官方用例和整段语料对拍都发现不了,只有专门造畸形 UTF-16
|
|
12
|
+
* 才暴露。
|
|
13
|
+
*
|
|
14
|
+
* 三处不匹配步进(Trie.convert / Trie.segment / maskWithTrie)共用它。
|
|
15
|
+
*/
|
|
16
|
+
function isSurrogatePair(input, i, length) {
|
|
17
|
+
const hi = input.charCodeAt(i);
|
|
18
|
+
if (hi < 0xd800 || hi > 0xdbff || i + 1 >= length)
|
|
19
|
+
return false;
|
|
20
|
+
const lo = input.charCodeAt(i + 1);
|
|
21
|
+
return lo >= 0xdc00 && lo <= 0xdfff;
|
|
22
|
+
}
|
|
5
23
|
/**
|
|
6
24
|
* Trie tree for efficient string matching and conversion
|
|
7
25
|
*/
|
|
8
26
|
export class Trie {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.map = new Map();
|
|
11
|
-
}
|
|
12
27
|
/**
|
|
13
28
|
* Add a word to the trie
|
|
14
29
|
* @param key - The string to match
|
|
15
30
|
* @param value - The replacement string
|
|
16
31
|
*/
|
|
17
32
|
addWord(key, value) {
|
|
33
|
+
// charCodeAt + 手动代理对配对,不走 for..of 迭代器/codePointAt:构建整棵
|
|
34
|
+
// STPhrases 树实测 1.72×(10.3 → 6.0 ms)。五个走 trie 的循环(addWord /
|
|
35
|
+
// findLongestMatch / matchLongestInto / convert / segment)统一这一种写法,
|
|
36
|
+
// 改其一记得同步其余。
|
|
18
37
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
19
38
|
let node = this;
|
|
20
|
-
for (
|
|
21
|
-
|
|
22
|
-
|
|
39
|
+
for (let i = 0; i < key.length;) {
|
|
40
|
+
let codePoint = key.charCodeAt(i);
|
|
41
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdbff && i + 1 < key.length) {
|
|
42
|
+
const lo = key.charCodeAt(i + 1);
|
|
43
|
+
if (lo >= 0xdc00 && lo <= 0xdfff) {
|
|
44
|
+
codePoint = (codePoint - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000;
|
|
45
|
+
i += 2;
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
i += 1; // 孤立高代理,按单元收——与 codePointAt 行为一致
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
i += 1;
|
|
52
|
+
let nextNode = node.map?.get(codePoint);
|
|
23
53
|
if (!nextNode) {
|
|
24
54
|
nextNode = new Trie();
|
|
25
|
-
node.map.set(codePoint, nextNode);
|
|
55
|
+
(node.map ?? (node.map = new Map())).set(codePoint, nextNode);
|
|
26
56
|
}
|
|
27
57
|
node = nextNode;
|
|
28
58
|
}
|
|
@@ -75,17 +105,27 @@ export class Trie {
|
|
|
75
105
|
* not relative to `start`. Callers should check `end > start`.
|
|
76
106
|
* @param input - The string to search
|
|
77
107
|
* @param start - The index to start matching from
|
|
108
|
+
*
|
|
109
|
+
* 热路径请用 {@link matchLongestInto}(免分配变体,语义一致)——两边改其一必同步另一个。
|
|
78
110
|
*/
|
|
79
111
|
findLongestMatch(input, start) {
|
|
112
|
+
// 同 addWord:charCodeAt + 手动配对(热循环写法统一,见 addWord 注释)。
|
|
80
113
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
81
114
|
let node = this;
|
|
82
115
|
let matchEnd = 0;
|
|
83
116
|
let matchValue;
|
|
84
117
|
for (let j = start; j < input.length && node;) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
j
|
|
88
|
-
|
|
118
|
+
let codePoint = input.charCodeAt(j);
|
|
119
|
+
let step = 1;
|
|
120
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdbff && j + 1 < input.length) {
|
|
121
|
+
const lo = input.charCodeAt(j + 1);
|
|
122
|
+
if (lo >= 0xdc00 && lo <= 0xdfff) {
|
|
123
|
+
codePoint = (codePoint - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000;
|
|
124
|
+
step = 2;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
j += step;
|
|
128
|
+
const nextNode = node.map?.get(codePoint);
|
|
89
129
|
if (!nextNode)
|
|
90
130
|
break;
|
|
91
131
|
node = nextNode;
|
|
@@ -96,6 +136,39 @@ export class Trie {
|
|
|
96
136
|
}
|
|
97
137
|
return { end: matchEnd, value: matchValue };
|
|
98
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* findLongestMatch 的免分配变体:结果写进调用方复用的 `out`,不造对象。
|
|
141
|
+
* 给每个位置都要探一次的热调用方用(maskWithTrie 一个位置一次——对象版
|
|
142
|
+
* 在 4 万字语料上就是 4 万次 {end,value} 分配)。语义与 findLongestMatch
|
|
143
|
+
* 完全一致,改其一必同步另一个。
|
|
144
|
+
*/
|
|
145
|
+
matchLongestInto(input, start, out) {
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
147
|
+
let node = this;
|
|
148
|
+
out.end = 0;
|
|
149
|
+
out.value = undefined;
|
|
150
|
+
const length = input.length;
|
|
151
|
+
for (let j = start; j < length && node;) {
|
|
152
|
+
let codePoint = input.charCodeAt(j);
|
|
153
|
+
let step = 1;
|
|
154
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdbff && j + 1 < length) {
|
|
155
|
+
const lo = input.charCodeAt(j + 1);
|
|
156
|
+
if (lo >= 0xdc00 && lo <= 0xdfff) {
|
|
157
|
+
codePoint = (codePoint - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000;
|
|
158
|
+
step = 2;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
j += step;
|
|
162
|
+
const nextNode = node.map?.get(codePoint);
|
|
163
|
+
if (!nextNode)
|
|
164
|
+
break;
|
|
165
|
+
node = nextNode;
|
|
166
|
+
if (node.value !== undefined) {
|
|
167
|
+
out.end = j;
|
|
168
|
+
out.value = node.value;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
99
172
|
/**
|
|
100
173
|
* Convert a string using the trie
|
|
101
174
|
* Uses longest match algorithm for optimal conversion
|
|
@@ -112,11 +185,19 @@ export class Trie {
|
|
|
112
185
|
let matchEnd = 0;
|
|
113
186
|
let matchValue;
|
|
114
187
|
// Find the longest match starting at position i
|
|
188
|
+
// (charCodeAt + 手动配对,写法统一见 addWord 注释;实测 convert 1.30×)
|
|
115
189
|
for (let j = i; j < length && currentNode;) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
j
|
|
119
|
-
|
|
190
|
+
let codePoint = input.charCodeAt(j);
|
|
191
|
+
let step = 1;
|
|
192
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdbff && j + 1 < length) {
|
|
193
|
+
const lo = input.charCodeAt(j + 1);
|
|
194
|
+
if (lo >= 0xdc00 && lo <= 0xdfff) {
|
|
195
|
+
codePoint = (codePoint - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000;
|
|
196
|
+
step = 2;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
j += step;
|
|
200
|
+
const nextNode = currentNode.map?.get(codePoint);
|
|
120
201
|
if (!nextNode) {
|
|
121
202
|
break;
|
|
122
203
|
}
|
|
@@ -140,8 +221,7 @@ export class Trie {
|
|
|
140
221
|
if (originalStart === null) {
|
|
141
222
|
originalStart = i;
|
|
142
223
|
}
|
|
143
|
-
|
|
144
|
-
i += codePoint > 0xffff ? 2 : 1;
|
|
224
|
+
i += isSurrogatePair(input, i, length) ? 2 : 1;
|
|
145
225
|
}
|
|
146
226
|
}
|
|
147
227
|
// Flush remaining original text
|
|
@@ -150,6 +230,131 @@ export class Trie {
|
|
|
150
230
|
}
|
|
151
231
|
return result.join("");
|
|
152
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Split input into segments on this trie's entries, longest match first.
|
|
235
|
+
*
|
|
236
|
+
* Every matched entry becomes its own segment, and the runs between them are
|
|
237
|
+
* emitted as segments too, so `segments.join("")` reconstructs the input
|
|
238
|
+
* exactly. Nothing is converted here — only cut.
|
|
239
|
+
*
|
|
240
|
+
* Exists for {@link ConverterFactoryWithSegmentation}; see there for why the
|
|
241
|
+
* cut changes results.
|
|
242
|
+
*
|
|
243
|
+
* @param input - The string to split
|
|
244
|
+
* @returns Segments whose concatenation equals `input`
|
|
245
|
+
*/
|
|
246
|
+
segment(input) {
|
|
247
|
+
const segments = [];
|
|
248
|
+
const length = input.length;
|
|
249
|
+
let originalStart = null;
|
|
250
|
+
for (let i = 0; i < length;) {
|
|
251
|
+
// Inlined longest-match walk, same as `convert`. Calling
|
|
252
|
+
// `findLongestMatch` here instead would allocate a `{ end, value }`
|
|
253
|
+
// object at every position — on Chinese text that is roughly one
|
|
254
|
+
// short-lived object per character, and segmentation already runs an
|
|
255
|
+
// extra full pass. Measured worth keeping inline.
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
257
|
+
let node = this;
|
|
258
|
+
let end = 0;
|
|
259
|
+
for (let j = i; j < length && node;) {
|
|
260
|
+
let codePoint = input.charCodeAt(j);
|
|
261
|
+
let step = 1;
|
|
262
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdbff && j + 1 < length) {
|
|
263
|
+
const lo = input.charCodeAt(j + 1);
|
|
264
|
+
if (lo >= 0xdc00 && lo <= 0xdfff) {
|
|
265
|
+
codePoint = (codePoint - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000;
|
|
266
|
+
step = 2;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
j += step;
|
|
270
|
+
const nextNode = node.map?.get(codePoint);
|
|
271
|
+
if (!nextNode)
|
|
272
|
+
break;
|
|
273
|
+
node = nextNode;
|
|
274
|
+
if (node.value !== undefined)
|
|
275
|
+
end = j;
|
|
276
|
+
}
|
|
277
|
+
if (end > i) {
|
|
278
|
+
if (originalStart !== null) {
|
|
279
|
+
segments.push(input.slice(originalStart, i));
|
|
280
|
+
originalStart = null;
|
|
281
|
+
}
|
|
282
|
+
segments.push(input.slice(i, end));
|
|
283
|
+
i = end;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
if (originalStart === null) {
|
|
287
|
+
originalStart = i;
|
|
288
|
+
}
|
|
289
|
+
i += isSurrogatePair(input, i, length) ? 2 : 1;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (originalStart !== null) {
|
|
293
|
+
segments.push(input.slice(originalStart, length));
|
|
294
|
+
}
|
|
295
|
+
return segments;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* CJK Compatibility Ideographs, both blocks: U+F900..U+FAFF and
|
|
300
|
+
* U+2F800..U+2FA1F. Characters here duplicate unified ideographs and exist
|
|
301
|
+
* only to round-trip legacy encodings — 類 U+F9D0 renders the same as
|
|
302
|
+
* 類 U+985E but is a different code point, so it misses dictionary lookups,
|
|
303
|
+
* searches and string comparisons.
|
|
304
|
+
*/
|
|
305
|
+
// ⚠ 端点一律写转义,不要写字面字符。这里原来是字面的「豈」,本意 U+F900
|
|
306
|
+
// (CJK 兼容汉字),但它和 U+8C48(普通汉字)**字形完全一样**,某次被 NFC
|
|
307
|
+
// 归一化悄悄换掉了——范围于是从 [F900,FAFF] 变成 [8C48,FAFF],覆盖了大半常用
|
|
308
|
+
// 汉字和整个 PUA。输出仍然正确(normalize 对普通字是恒等),只是每段中文都要
|
|
309
|
+
// 白跑一遍 replace。肉眼、grep、测试全都看不出来,只有把端点打成码位才现形。
|
|
310
|
+
const COMPATIBILITY_IDEOGRAPHS = /[\uF900-\uFAFF\u{2F800}-\u{2FA1F}]/gu;
|
|
311
|
+
/**
|
|
312
|
+
* Fold CJK Compatibility Ideographs to their unified equivalents.
|
|
313
|
+
*
|
|
314
|
+
* OpenCC does this with a 1002-entry dictionary
|
|
315
|
+
* (`CJK_Compatibility_Ideographs`) loaded as a normalization step by every
|
|
316
|
+
* config. **We ship no such table.** Those mappings are canonical singleton
|
|
317
|
+
* decompositions in the Unicode standard, which is precisely what
|
|
318
|
+
* `String.prototype.normalize` performs — checked entry by entry against
|
|
319
|
+
* opencc-js's copy: all 1002 agree, and NFC folds nothing the table misses.
|
|
320
|
+
* So ~8.7 KB of data becomes a call into the engine's own ICU, which has the
|
|
321
|
+
* side benefit of tracking new Unicode versions without a resync.
|
|
322
|
+
*
|
|
323
|
+
* Two deliberate details:
|
|
324
|
+
*
|
|
325
|
+
* 1. **NFC, not NFKC.** NFKC would also fold full-width forms (`,`→`,`,
|
|
326
|
+
* `A`→`A`) and enclosed characters (`㈱`→`(株)`). In Chinese prose that is
|
|
327
|
+
* destructive: full-width punctuation is correct typography, not a
|
|
328
|
+
* compatibility artifact.
|
|
329
|
+
* 2. **Only the two compatibility blocks are touched**, not the whole string.
|
|
330
|
+
* Whole-string NFC would also compose combining sequences the caller never
|
|
331
|
+
* asked us to touch. The pre-test means ordinary text — which has no
|
|
332
|
+
* compatibility ideographs at all — is returned as-is with no allocation.
|
|
333
|
+
*
|
|
334
|
+
* @param input - The string to normalize
|
|
335
|
+
* @returns The string with compatibility ideographs folded
|
|
336
|
+
*/
|
|
337
|
+
export function normalizeCompatibilityIdeographs(input) {
|
|
338
|
+
// 手写 charCodeAt 预扫描,正则 .test 的 5×(0.68 → 0.14 ms / 4 万字):
|
|
339
|
+
// 兼容区只有两段——BMP 的 U+F900–FAFF,和增补区 U+2F800–2FA1F(整段的高代理
|
|
340
|
+
// 恰好都是 U+D87E)。汉字主体 U+4E00–9FFF 一次比较出局。扫描判据是正则的
|
|
341
|
+
// 超集(D87E 也覆盖 U+2FA20–2FBFF),命中了才交给正则精确判——所以只会多走
|
|
342
|
+
// 慢路径,不会漏。
|
|
343
|
+
let hit = false;
|
|
344
|
+
for (let i = 0; i < input.length; i++) {
|
|
345
|
+
const c = input.charCodeAt(i);
|
|
346
|
+
if ((c >= 0xf900 && c <= 0xfaff) || c === 0xd87e) {
|
|
347
|
+
hit = true;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (!hit)
|
|
352
|
+
return input;
|
|
353
|
+
COMPATIBILITY_IDEOGRAPHS.lastIndex = 0;
|
|
354
|
+
if (!COMPATIBILITY_IDEOGRAPHS.test(input))
|
|
355
|
+
return input;
|
|
356
|
+
COMPATIBILITY_IDEOGRAPHS.lastIndex = 0;
|
|
357
|
+
return input.replace(COMPATIBILITY_IDEOGRAPHS, (char) => char.normalize("NFC"));
|
|
153
358
|
}
|
|
154
359
|
/**
|
|
155
360
|
* Create a converter from multiple dictionary groups
|
|
@@ -164,7 +369,65 @@ export function ConverterFactory(...dictGroups) {
|
|
|
164
369
|
return trie;
|
|
165
370
|
});
|
|
166
371
|
return function convert(input) {
|
|
167
|
-
return tries.reduce((text, trie) => trie.convert(text), input);
|
|
372
|
+
return tries.reduce((text, trie) => trie.convert(text), normalizeCompatibilityIdeographs(input));
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Like {@link ConverterFactory}, but cuts the input into segments first and
|
|
377
|
+
* runs every conversion step **inside each segment** instead of across the
|
|
378
|
+
* whole string.
|
|
379
|
+
*
|
|
380
|
+
* ## What this is for
|
|
381
|
+
*
|
|
382
|
+
* With a two-step chain (`cn → t`, then `t → tw`), the second step sees text
|
|
383
|
+
* the first step produced. Without segmentation it can match across a word
|
|
384
|
+
* boundary the first step established, and the regional vocabulary tables
|
|
385
|
+
* (`TWPhrases`, `HKPhrases`) then fire in places OpenCC does not fire them.
|
|
386
|
+
* Measured against OpenCC's own output on 1707 phrases in context, dropping
|
|
387
|
+
* segmentation changes 21 of them — always by over-applying:
|
|
388
|
+
*
|
|
389
|
+
* ```text
|
|
390
|
+
* 他优化了 OpenCC 他優化了 no segmentation 他最佳化了
|
|
391
|
+
* 他函数了 OpenCC 他函數了 no segmentation 他函式了
|
|
392
|
+
* 他宽带了 OpenCC 他寬帶了 no segmentation 他寬頻了
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
* Note the bare phrase still converts (`优化` → `最佳化`) either way. It is
|
|
396
|
+
* only *in context* that the boundary matters, which is what makes the bug
|
|
397
|
+
* easy to miss with word-list tests.
|
|
398
|
+
*
|
|
399
|
+
* ## Which dictionary to cut on
|
|
400
|
+
*
|
|
401
|
+
* The segmentation dictionary must be keyed in the **input's** script, since
|
|
402
|
+
* it is the raw input being cut: OpenCC uses `STPhrases` for `s2*` and
|
|
403
|
+
* `TSPhrases` for `*2s`. {@link segmentationDictsFor} encodes that choice.
|
|
404
|
+
*
|
|
405
|
+
* ## Cost
|
|
406
|
+
*
|
|
407
|
+
* One extra trie walk plus per-segment string handling — roughly 2× the
|
|
408
|
+
* conversion time (0.73 ms → 1.45 ms on a 15 000-character chapter, which cut
|
|
409
|
+
* into ~5200 segments). Only chains with two or more steps need it, and
|
|
410
|
+
* {@link segmentationDictsFor} returns nothing for the rest, so single-step
|
|
411
|
+
* conversions keep the cheap path.
|
|
412
|
+
*
|
|
413
|
+
* @param segmentation - Dictionary group to cut on, or `null` for no cutting
|
|
414
|
+
* @param dictGroups - Conversion steps, applied in order within each segment
|
|
415
|
+
* @returns Converter function
|
|
416
|
+
*/
|
|
417
|
+
export function ConverterFactoryWithSegmentation(segmentation, ...dictGroups) {
|
|
418
|
+
if (!segmentation || segmentation.length === 0) {
|
|
419
|
+
return ConverterFactory(...dictGroups);
|
|
420
|
+
}
|
|
421
|
+
const segmenter = new Trie();
|
|
422
|
+
segmenter.loadDictGroup(segmentation);
|
|
423
|
+
const tries = dictGroups.map((group) => {
|
|
424
|
+
const trie = new Trie();
|
|
425
|
+
trie.loadDictGroup(group);
|
|
426
|
+
return trie;
|
|
427
|
+
});
|
|
428
|
+
return function convert(input) {
|
|
429
|
+
const segments = segmenter.segment(normalizeCompatibilityIdeographs(input));
|
|
430
|
+
return tries.reduce((current, trie) => current.map((segment) => trie.convert(segment)), segments).join("");
|
|
168
431
|
};
|
|
169
432
|
}
|
|
170
433
|
/**
|
|
@@ -195,10 +458,51 @@ const PROTECT_PLACEHOLDER_END = 0xf8ff;
|
|
|
195
458
|
* Safe to nest: each layer scans its input for existing PUA codepoints (from
|
|
196
459
|
* outer layers) and allocates around them. PUA chars from outer layers pass
|
|
197
460
|
* through unchanged.
|
|
461
|
+
*
|
|
462
|
+
* Rules must not contain PUA characters (U+E000..U+F8FF) — throws TypeError at
|
|
463
|
+
* build time. This was documented-but-unenforced for a while: a PUA char inside
|
|
464
|
+
* a rule VALUE can collide with an allocated placeholder and get swapped for a
|
|
465
|
+
* different rule's value at restore time. That failure needs two rules plus a
|
|
466
|
+
* specific allocation order, so it would surface as rare, unreproducible
|
|
467
|
+
* corruption — exactly the kind of bug a constructor throw is cheapest against.
|
|
468
|
+
* (PUA in user INPUT text is fine — the input scan routes around it.)
|
|
469
|
+
*/
|
|
470
|
+
/**
|
|
471
|
+
* PUA 字符(U+E000..U+F8FF)是 ProtectedConverter 的内部占位符段,规则里不能有它。
|
|
472
|
+
*
|
|
473
|
+
* 危害不是假设的:规则**值**里的 PUA 可能撞上分配出去的占位符,还原时被换成另一条
|
|
474
|
+
* 规则的值——要两条规则加特定分配顺序才触发,表现为罕见且无法复现的串词。
|
|
475
|
+
*
|
|
476
|
+
* 处理方式是**静默剥掉**,不是抛错。理由:这些字符肉眼不可见,用户看到的规则本来就是
|
|
477
|
+
* 剥掉之后那个样子;而规则常常来自最终用户(粘贴 / 导入 / localStorage 里的历史数据),
|
|
478
|
+
* 抛错等于把库的内部不变式变成每个调用方都要先洗一遍的负担。剥完为空的键值对整条跳过,
|
|
479
|
+
* 与 `Trie.loadDict` 对畸形条目的一贯宽容度一致。
|
|
480
|
+
*
|
|
481
|
+
* 用户**输入文本**里的 PUA 不受影响——那是数据,掩码分配器会绕开它们走。
|
|
198
482
|
*/
|
|
483
|
+
function stripPUA(text) {
|
|
484
|
+
// 转义写法,不写裸字符——裸 PUA 在多数编辑器里完全不可见。
|
|
485
|
+
return text.replace(/[\uE000-\uF8FF]/g, "");
|
|
486
|
+
}
|
|
487
|
+
function sanitizeRules(protectedDict) {
|
|
488
|
+
const entries = typeof protectedDict === "string"
|
|
489
|
+
? protectedDict.split("|").map((e) => {
|
|
490
|
+
const i = e.indexOf(" ");
|
|
491
|
+
return i < 0 ? [e] : [e.slice(0, i), e.slice(i + 1)];
|
|
492
|
+
})
|
|
493
|
+
: protectedDict;
|
|
494
|
+
const out = [];
|
|
495
|
+
for (const entry of entries) {
|
|
496
|
+
const key = stripPUA(entry[0] ?? "");
|
|
497
|
+
const value = stripPUA(entry[1] ?? "");
|
|
498
|
+
if (key && value)
|
|
499
|
+
out.push([key, value]);
|
|
500
|
+
}
|
|
501
|
+
return out;
|
|
502
|
+
}
|
|
199
503
|
export function ProtectedConverter(protectedDict, innerConvert) {
|
|
200
504
|
const trie = new Trie();
|
|
201
|
-
trie.loadDict(protectedDict);
|
|
505
|
+
trie.loadDict(sanitizeRules(protectedDict));
|
|
202
506
|
return function convert(input) {
|
|
203
507
|
const slotsByCode = new Map();
|
|
204
508
|
const valueToPlaceholder = new Map();
|
|
@@ -207,6 +511,32 @@ export function ProtectedConverter(protectedDict, innerConvert) {
|
|
|
207
511
|
return restorePlaceholders(converted, slotsByCode);
|
|
208
512
|
};
|
|
209
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Reverse a packed dict string ("k1 v1|k2 v2") into `[value, key][]` entries.
|
|
516
|
+
* The value is everything after the FIRST space (values may contain spaces,
|
|
517
|
+
* e.g. 二维码 → "QR Code") — same rule as `Trie.loadDict`'s string form.
|
|
518
|
+
*
|
|
519
|
+
* Collision policy, identical to `reverseEntries` in scripts/sync-opencc.ts:
|
|
520
|
+
* when several keys share one value (U盘/优盘 → 隨身碟) the FIRST key wins,
|
|
521
|
+
* because dicts list the preferred term first and the trie is last-wins — so
|
|
522
|
+
* without this the trailing synonym takes over (隨身碟 → 优盘). An identity pair
|
|
523
|
+
* outranks that, leaving the term untouched rather than guessing a synonym.
|
|
524
|
+
*
|
|
525
|
+
* Entries with no separator are skipped, as `Trie.loadDict` does.
|
|
526
|
+
*/
|
|
527
|
+
export function reverseDictString(data) {
|
|
528
|
+
const reversed = new Map();
|
|
529
|
+
for (const entry of data.split("|")) {
|
|
530
|
+
const sep = entry.indexOf(" ");
|
|
531
|
+
if (sep < 0)
|
|
532
|
+
continue;
|
|
533
|
+
const key = entry.slice(0, sep);
|
|
534
|
+
const value = entry.slice(sep + 1);
|
|
535
|
+
if (!reversed.has(value) || key === value)
|
|
536
|
+
reversed.set(value, key);
|
|
537
|
+
}
|
|
538
|
+
return [...reversed];
|
|
539
|
+
}
|
|
210
540
|
/**
|
|
211
541
|
* Parse OpenCC-format dictionary text into `[key, value][]` — the shape
|
|
212
542
|
* accepted by `protectedDict`, `CustomConverter`, and `ConverterFactory`.
|
|
@@ -272,11 +602,14 @@ export function parseOpenCCDict(text) {
|
|
|
272
602
|
*/
|
|
273
603
|
function maskWithTrie(input, trie, slotsByCode, valueToPlaceholder) {
|
|
274
604
|
// Scan input for any existing PUA codepoints (from outer ProtectedConverter
|
|
275
|
-
// layers
|
|
276
|
-
//
|
|
605
|
+
// layers, or plain user data). Their ONLY consumer is allocateCode below —
|
|
606
|
+
// matching needs no per-char passthrough branch: the constructor guarantees
|
|
607
|
+
// rules contain no PUA, so no trie match can ever cover a PUA char and it
|
|
608
|
+
// falls into the unmatched run untouched. (PUA is Plane 0 → plain charCodeAt
|
|
609
|
+
// scan, no surrogate pairing needed; measured ~5× over the for..of version.)
|
|
277
610
|
const existingPUA = new Set();
|
|
278
|
-
for (
|
|
279
|
-
const cp =
|
|
611
|
+
for (let k = 0; k < input.length; k++) {
|
|
612
|
+
const cp = input.charCodeAt(k);
|
|
280
613
|
if (cp >= PROTECT_PLACEHOLDER_BASE && cp <= PROTECT_PLACEHOLDER_END) {
|
|
281
614
|
existingPUA.add(cp);
|
|
282
615
|
}
|
|
@@ -290,36 +623,43 @@ function maskWithTrie(input, trie, slotsByCode, valueToPlaceholder) {
|
|
|
290
623
|
}
|
|
291
624
|
return nextCode++;
|
|
292
625
|
};
|
|
626
|
+
// Inlined longest-match walk + run slicing, same shape as Trie.convert:
|
|
627
|
+
// the previous version called findLongestMatch per position (one {end,value}
|
|
628
|
+
// allocation per character) and pushed per-char substrings (one string per
|
|
629
|
+
// character even with zero matches). One PC layer cost +2.7 ms on a 40k-char
|
|
630
|
+
// corpus — nearly doubling the whole pipeline; this rewrite makes the
|
|
631
|
+
// no-match path allocation-free.
|
|
293
632
|
const result = [];
|
|
294
633
|
const length = input.length;
|
|
295
|
-
let
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
let placeholder = valueToPlaceholder.get(value);
|
|
634
|
+
let originalStart = null;
|
|
635
|
+
const hit = { end: 0, value: undefined };
|
|
636
|
+
for (let i = 0; i < length;) {
|
|
637
|
+
trie.matchLongestInto(input, i, hit);
|
|
638
|
+
const matchEnd = hit.end;
|
|
639
|
+
const matchValue = hit.value;
|
|
640
|
+
if (matchEnd > 0 && matchValue !== undefined) {
|
|
641
|
+
if (originalStart !== null) {
|
|
642
|
+
result.push(input.slice(originalStart, i));
|
|
643
|
+
originalStart = null;
|
|
644
|
+
}
|
|
645
|
+
let placeholder = valueToPlaceholder.get(matchValue);
|
|
308
646
|
if (placeholder === undefined) {
|
|
309
647
|
const code = allocateCode();
|
|
310
648
|
placeholder = String.fromCodePoint(code);
|
|
311
|
-
valueToPlaceholder.set(
|
|
312
|
-
slotsByCode.set(code,
|
|
649
|
+
valueToPlaceholder.set(matchValue, placeholder);
|
|
650
|
+
slotsByCode.set(code, matchValue);
|
|
313
651
|
}
|
|
314
652
|
result.push(placeholder);
|
|
315
|
-
i =
|
|
653
|
+
i = matchEnd;
|
|
316
654
|
}
|
|
317
655
|
else {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
i +=
|
|
656
|
+
if (originalStart === null)
|
|
657
|
+
originalStart = i;
|
|
658
|
+
i += isSurrogatePair(input, i, length) ? 2 : 1;
|
|
321
659
|
}
|
|
322
660
|
}
|
|
661
|
+
if (originalStart !== null)
|
|
662
|
+
result.push(input.slice(originalStart, length));
|
|
323
663
|
return result.join("");
|
|
324
664
|
}
|
|
325
665
|
/**
|
|
@@ -331,17 +671,29 @@ function maskWithTrie(input, trie, slotsByCode, valueToPlaceholder) {
|
|
|
331
671
|
function restorePlaceholders(text, slotsByCode) {
|
|
332
672
|
if (slotsByCode.size === 0)
|
|
333
673
|
return text;
|
|
674
|
+
// Run slicing instead of one push per character: placeholders are Plane-0
|
|
675
|
+
// PUA, so a plain charCodeAt compare finds them and everything between two
|
|
676
|
+
// placeholders is emitted as a single slice. The per-char version allocated
|
|
677
|
+
// 40k single-char strings to restore 3 placeholders.
|
|
334
678
|
const result = [];
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
679
|
+
const length = text.length;
|
|
680
|
+
let runStart = 0;
|
|
681
|
+
for (let i = 0; i < length; i++) {
|
|
682
|
+
const cp = text.charCodeAt(i);
|
|
683
|
+
if (cp >= PROTECT_PLACEHOLDER_BASE && cp <= PROTECT_PLACEHOLDER_END) {
|
|
684
|
+
const restored = slotsByCode.get(cp);
|
|
685
|
+
if (restored !== undefined) {
|
|
686
|
+
if (runStart < i)
|
|
687
|
+
result.push(text.slice(runStart, i));
|
|
688
|
+
result.push(restored);
|
|
689
|
+
runStart = i + 1;
|
|
690
|
+
}
|
|
691
|
+
// 不在本层 map 里的 PUA(外层的占位符/用户数据)留在 run 里原样通过
|
|
343
692
|
}
|
|
344
693
|
}
|
|
694
|
+
if (runStart === 0)
|
|
695
|
+
return text;
|
|
696
|
+
if (runStart < length)
|
|
697
|
+
result.push(text.slice(runStart, length));
|
|
345
698
|
return result.join("");
|
|
346
699
|
}
|
|
347
|
-
//# sourceMappingURL=core.js.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
3
|
-
//# sourceMappingURL=CNTWPhrases.d.ts.map
|
|
1
|
+
declare const dict: string;
|
|
2
|
+
export default dict;
|
package/dist/dict/CNTWPhrases.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const dict = "视频 影片|内存 記憶體|鼠标 滑鼠|U盘 隨身碟|优盘 隨身碟|打印机 印表機|杀毒软件 防毒軟體|默认 預設|调制解调器 數據機|出租车 計程車|地铁 捷運|公交车 公車|摩托车 機車|航站楼 航廈|立交桥 交流道|盒饭 便當|酸奶 優格|芝士 起司|土豆 馬鈴薯|卷心菜 高麗菜|包菜 高麗菜|方便面 泡麵|薯片 洋芋片|雪糕 冰淇淋|幼儿园 幼稚園|小学 國小|初中 國中|高考 大學入學考試|简历 履歷|项目 專案|营销 行銷|合同 合約|空调 冷氣|物业 物業|二手房 中古屋|煤气 瓦斯|二维码 QR Code|人脸识别 人臉辨識|云计算 雲端運算|虚拟现实 虛擬實境|增强现实 擴增實境";
|
|
2
|
+
export default dict;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const dict = "丹尼·博伊爾 丹尼·波爾|亞歷杭德羅·岡薩雷斯·伊納裏圖 艾力謝路·高沙里斯·依拿力圖|伊利亞·卡贊 伊力·卡山|伊利諾伊 伊利諾|伊利諾伊州 伊利諾州|伍迪·艾倫 活地·亞倫|俄克拉何馬 奧克拉荷馬|俄克拉何馬州 奧克拉荷馬州|俄克拉荷馬 奧克拉荷馬|俄克拉荷馬州 奧克拉荷馬州|保羅·哈吉斯 保羅·夏傑斯|保羅·托馬斯·安德森 保羅·湯馬士·安德遜|光標 游標|克林特·伊斯特伍德 奇連·伊士活|克里斯托弗·諾蘭 基斯杜化·路蘭|內存條 記憶體模組|凱文·科斯特納 奇雲·高士拿|凱瑟琳·畢格羅 嘉芙蓮·碧格露|北卡羅來納 北卡羅萊納|北卡羅來納州 北卡羅萊納州|南卡羅來納 南卡羅萊納|南卡羅來納州 南卡羅萊納州|史蒂夫·麥奎因 史提夫·麥昆|吉列爾莫·德爾托羅 古利姆·迪托路|喬治·克魯尼 佐治·古尼|大衛·利恩 大衛·連|奧利弗·斯通 奧利華·史東|威廉·弗萊德金 威廉·佛烈金|密歇根 密芝根|密歇根州 密芝根州|寬帶 寬頻|山姆·曼德斯 森·曼特斯|布拉德·皮特 畢·彼特|幾率 機率|弗吉尼亞 維珍尼亞|弗吉尼亞州 維珍尼亞州|弗朗西絲·麥克多曼德 法蘭絲·麥杜雯|彼得·傑克遜 彼德·積遜|得克薩斯 德薩斯|得克薩斯州 德薩斯州|德克薩斯 德薩斯|德克薩斯州 德薩斯州|搜索 搜尋|操作系統 作業系統|文件夾 資料夾|斯蒂芬·斯皮爾伯格 史提芬·史匹堡|服務器 伺服器|朗·霍華德 朗·侯活|本·阿弗萊克 賓·艾佛力|查爾斯·羅文 查理士·路雲|梅爾·吉布森 米路·吉遜|概率 概率|沃倫·比蒂 華倫·比提|湯姆·霍伯 湯賀柏|硬盤 硬碟|科恩兄弟 高安兄弟|簡·坎皮恩 珍·甘比茵|米歇爾·阿扎納維西於斯 米高·哈薩拿維斯|約瑟夫·曼凱維奇 約瑟·曼基威士|編程語言 程式語言|羅伯特·懷斯 羅拔·淮斯|羅伯特·澤米吉斯 羅拔·湛米基斯|羅伯特·雷德福 羅拔·烈福|羅得島 羅德島|羅得島州 羅德島州|肖恩·貝克 辛·貝克|舒芙蕾 梳芙厘|艾瑪·托馬斯 愛瑪·湯馬士|西弗吉尼亞 西維珍尼亞|西弗吉尼亞州 西維珍尼亞州|詹姆斯·卡梅隆 占士·金馬倫|諾蘭 路蘭|賓夕法尼亞 賓夕凡尼亞|賓夕法尼亞州 賓夕凡尼亞州|邁克·尼科爾斯 米克·尼高斯|邁克爾·道格拉斯 米高·德格拉斯|阿黛爾·羅曼斯基 愛黛兒·羅曼斯基|隱私權 私隱權|馬丁·斯科塞斯 馬田·史高西斯|馬里蘭 馬利蘭|馬里蘭州 馬利蘭州|鼠標 滑鼠";
|
|
2
|
+
export default dict;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const dict = "丹尼·波爾 丹尼·博伊爾|伊利諾 伊利諾伊|伊利諾州 伊利諾伊州|伊力·卡山 伊利亞·卡贊|伺服器 服務器|佐治·古尼 喬治·克魯尼|作業系統 操作系統|保羅·夏傑斯 保羅·哈吉斯|保羅·湯馬士·安德遜 保羅·托馬斯·安德森|北卡羅萊納 北卡羅來納|北卡羅萊納州 北卡羅來納州|南卡羅萊納 南卡羅來納|南卡羅萊納州 南卡羅來納州|占士·金馬倫 詹姆斯·卡梅隆|古利姆·迪托路 吉列爾莫·德爾托羅|史提夫·麥昆 史蒂夫·麥奎因|史提芬·史匹堡 斯蒂芬·斯皮爾伯格|嘉芙蓮·碧格露 凱瑟琳·畢格羅|基斯杜化·路蘭 克里斯托弗·諾蘭|大衛·連 大衛·利恩|奇連·伊士活 克林特·伊斯特伍德|奇雲·高士拿 凱文·科斯特納|奧克拉荷馬 俄克拉何馬|奧克拉荷馬州 俄克拉何馬州|奧利華·史東 奧利弗·斯通|威廉·佛烈金 威廉·弗萊德金|密芝根 密歇根|密芝根州 密歇根州|寬頻 寬帶|彼德·積遜 彼得·傑克遜|德薩斯 得克薩斯|德薩斯州 得克薩斯州|愛瑪·湯馬士 艾瑪·托馬斯|愛黛兒·羅曼斯基 阿黛爾·羅曼斯基|搜尋 搜索|朗·侯活 朗·霍華德|查理士·路雲 查爾斯·羅文|梳芙厘 舒芙蕾|森·曼特斯 山姆·曼德斯|概率 概率|機會率 概率|機率 幾率|法蘭絲·麥杜雯 弗朗西絲·麥克多曼德|活地·亞倫 伍迪·艾倫|游標 光標|湯賀柏 湯姆·霍伯|滑鼠 鼠標|珍·甘比茵 簡·坎皮恩|畢·彼特 布拉德·皮特|硬碟 硬盤|私隱權 隱私權|程式語言 編程語言|米克·尼高斯 邁克·尼科爾斯|米路·吉遜 梅爾·吉布森|米高·哈薩拿維斯 米歇爾·阿扎納維西於斯|米高·德格拉斯 邁克爾·道格拉斯|約瑟·曼基威士 約瑟夫·曼凱維奇|維珍尼亞 弗吉尼亞|維珍尼亞州 弗吉尼亞州|羅德島 羅得島|羅德島州 羅得島州|羅拔·淮斯 羅伯特·懷斯|羅拔·湛米基斯 羅伯特·澤米吉斯|羅拔·烈福 羅伯特·雷德福|艾力謝路·高沙里斯·依拿力圖 亞歷杭德羅·岡薩雷斯·伊納裏圖|華倫·比提 沃倫·比蒂|西維珍尼亞 西弗吉尼亞|西維珍尼亞州 西弗吉尼亞州|記憶體模組 內存條|資料夾 文件夾|賓·艾佛力 本·阿弗萊克|賓夕凡尼亞 賓夕法尼亞|賓夕凡尼亞州 賓夕法尼亞州|路蘭 諾蘭|辛·貝克 肖恩·貝克|馬利蘭 馬里蘭|馬利蘭州 馬里蘭州|馬田·史高西斯 馬丁·斯科塞斯|高安兄弟 科恩兄弟";
|
|
2
|
+
export default dict;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
3
|
-
//# sourceMappingURL=HKVariants.d.ts.map
|
|
1
|
+
declare const dict: string;
|
|
2
|
+
export default dict;
|
package/dist/dict/HKVariants.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const dict = "僞 偽|兌 兑|叄 叁|喫 吃|囪 囱|媼 媪|嬀 媯|悅 悦|慍 愠|戶 户|挩 捝|搵 揾|敓 敚|敘 敍|柺 枴|梲 棁|棱 稜|榲 榅|檯 枱|氳 氲|涗 涚|溫 温|溼 濕|潙 溈|潨 潀|熅 煴|爲 為|癡 痴|皁 皂|祕 秘|稅 税|竈 灶|糉 粽|縕 緼|纔 才|脣 唇|脫 脱|膃 腽|臥 卧|臺 台|菸 煙|蒕 蒀|蔥 葱|蔿 蒍|蘊 藴|蛻 蜕|衆 眾|衛 衞|覈 核|說 説|踊 踴|轀 輼|醞 醖|鉢 缽|鉤 鈎|銳 鋭|鍼 針|閱 閲|鰮 鰛";
|
|
2
|
+
export default dict;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const dict = "一幻拉麪 一幻拉麵|一粥麪 一粥麵|三田製麪所 三田製麵所|仙姑峯 仙姑峰|何芷姍 何芷姗|佛教茂峯法師紀念中學 佛教茂峰法師紀念中學|儒林台 儒林臺|儒林臺 儒林臺|光明台 光明臺|光明臺 光明臺|光景台 光景臺|光景臺 光景臺|光漢台 光漢臺|光漢臺 光漢臺|冠冕台 冠冕臺|冠冕臺 冠冕臺|冠峯街 冠峰街|冼靖峯 冼靖峰|列拿士地台 列拿士地臺|列拿士地臺 列拿士地臺|利羣道 利群道|利舞台廣場 利舞臺廣場|利舞臺廣場 利舞臺廣場|劉利羣 劉利群|加倫台 加倫臺|加倫臺 加倫臺|加冕台 加冕臺|加冕臺 加冕臺|北港島線 北港島綫|北環線 北環綫|北角台 北角臺|北角臺 北角臺|匯基書院 滙基書院|匯豐 滙豐|匯豐銀行 滙豐銀行|南港島線 南港島綫|南記粉麪 南記粉麵|吃茶舍 喫茶舍|合羣街 合群街|吳子沖 吳子冲|味千拉麪 味千拉麵|啟思中學 啓思中學|喫茶小舖 喫茶小舖|喫茶舍 喫茶舍|大埔循道衛理小學 大埔循道衛理小學|大埔循道衞理小學 大埔循道衛理小學|大學教育資助委員會祕書處 大學教育資助委員會秘書處|大安台 大安臺|大安臺 大安臺|大班麪包西餅 大班麵包西餅|天文台圍 天文臺圍|天文台道 天文臺道|天文臺圍 天文臺圍|天文臺道 天文臺道|姜詠鑫 姜咏鑫|孖峯嶺路 孖峰嶺路|安慶台 安慶臺|安慶臺 安慶臺|安羣街 安群街|宋皇台 宋皇臺|宋皇台道 宋皇臺道|宋皇臺 宋皇臺|宋皇臺道 宋皇臺道|宏豐台 宏豐臺|宏豐臺 宏豐臺|寧漢豪 甯漢豪|寶峯徑 寶峰徑|將軍澳循道衛理小學 將軍澳循道衛理小學|將軍澳循道衞理小學 將軍澳循道衛理小學|將軍澳線 將軍澳綫|尖尾峯 尖尾峰|尖峯山 尖峰山|尚麪 尚麵|屯馬線 屯馬綫|山坡台 山坡臺|山坡臺 山坡臺|山城小麪 山城小麵|山崎麪飽 山崎麵飽|山村台 山村臺|山村臺 山村臺|山邊台 山邊臺|山邊臺 山邊臺|峯華邨 峰華邨|峯霞道 峰霞道|巷仔見麪館 巷仔見麵館|幺鳳士多 么鳳士多|康福台 康福臺|康福臺 康福臺|建羣街 建群街|張柏芝 張柏芝|張栢芝 張栢芝|張穎康 張頴康|張華峯 張華峰|張衛健 張衛健|張衞健 張衛健|循道衛理 循道衛理|循道衞理 循道衛理|恆大 恒大|恆指 恒指|恆生 恒生|恆生大學 恒生大學|恆生指數 恒生指數|愉峯道 愉峰道|愛羣道 愛群道|截取通訊及監察事務專員祕書處 截取通訊及監察事務專員秘書處|摩頓台 摩頓臺|摩頓臺 摩頓臺|春暉台 春暉臺|春暉臺 春暉臺|景峯 景峰|景峯徑 景峰徑|朱匯林 朱滙林|朱柏康 朱栢康|朱柏謙 朱栢謙|李啟傑 李啓傑|李鉅峯 李鉅峰|杜琪峯 杜琪峰|東九龍線 東九龍綫|東山台 東山臺|東山臺 東山臺|東涌線 東涌綫|東鐵線 東鐵綫|林一峯 林一峰|林曉峯 林曉峰|林正峯 林正峰|林海峯 林海峰|林逸峯 林逸峰|桃李台 桃李臺|桃李臺 桃李臺|梁季彝中學 梁季彜中學|梁證嘉 梁証嘉|梁輝台 梁輝臺|梁輝臺 梁輝臺|梁釗峯 梁釗峰|梅豔芳 梅艷芳|榮華台 榮華臺|榮華臺 榮華臺|樂景台 樂景臺|樂景臺 樂景臺|樂羣街 樂群街|樓梯台 樓梯臺|樓梯臺 樓梯臺|機場快線 機場快綫|正斗粥麪專家 正斗粥麵專家|沙中線 沙中綫|沙田循道衛理小學 沙田循道衛理小學|沙田循道衞理小學 沙田循道衛理小學|河上鄉排峯路 河上鄉排峰路|活倫台 活倫臺|活倫臺 活倫臺|温兆倫 溫兆倫|温碧霞 溫碧霞|港島線 港島綫|溫兆倫 溫兆倫|溫碧霞 溫碧霞|潘雲峯 潘雲峰|澳美斯牀褥 澳美斯床褥|炮台山循道衛理中學 炮台山循道衛理中學|炮台山循道衞理中學 炮台山循道衛理中學|無線新聞 無綫新聞|無線新聞台 無綫新聞台|爐峯峽 爐峰峽|牛驥同一皁 牛驥同一皁|牛驥同皁 牛驥同皁|王家衛 王家衛|王家衞 王家衛|璧峯路 璧峰路|白石台 白石臺|白石台路 白石臺路|白石臺 白石臺|白石臺路 白石臺路|白臘 白腊|白臘仔 白腊仔|白臘灣 白腊灣|百老匯 百老滙|益羣道 益群道|福羣道 福群道|純喫茶 純喫茶|純陽峯 純陽峰|緬甸台 緬甸臺|緬甸臺 緬甸臺|繼園台 繼園臺|繼園臺 繼園臺|翠羣徑 翠群徑|翡翠拉麪小籠包 翡翠拉麵小籠包|老媽拌麪 老媽拌麵|聯合祕書處 聯合秘書處|肇輝台 肇輝臺|肇輝臺 肇輝臺|育羣街 育群街|脣茶 唇茶|芝古台 芝古臺|芝古臺 芝古臺|英王麪包 英王麵包|英華台 英華臺|英華臺 英華臺|茂峯 茂峰|荃灣線 荃灣綫|荔峯街 荔峰街|萬茂台 萬茂臺|萬茂臺 萬茂臺|葉藴儀 葉蘊儀|葉蘊儀 葉蘊儀|蔡曉峯 蔡曉峰|薪諮會聯合祕書處 薪諮會聯合秘書處|衛志豪 衛志豪|衛蘭 衛蘭|衛訊 衛訊|衛詩 衛詩|衛詩雅 衛詩雅|衞志豪 衛志豪|衞蘭 衛蘭|衞訊 衛訊|衞詩 衛詩|衞詩雅 衛詩雅|西摩台 西摩臺|西摩臺 西摩臺|西灣台 西灣臺|西灣臺 西灣臺|西鐵線 西鐵綫|觀塘線 觀塘綫|諾士佛台 諾士佛臺|諾士佛臺 諾士佛臺|謝詠欣 謝咏欣|豔馬道 艷馬道|迪士尼線 迪士尼綫|郭偉強 郭偉强|郭柏妍 郭柏姸|鄧梓峯 鄧梓峰|鄭恕峯 鄭恕峰|鄭衍峯 鄭衍峰|金龍台 金龍臺|金龍臺 金龍臺|鉛礦坳 鉛鑛坳|銀台路 銀臺路|銀礦灣 銀鑛灣|銀礦灣路 銀鑛灣路|銀線灣道 銀綫灣道|銀臺路 銀臺路|鋼線灣道 鋼綫灣道|錦繡大道 錦綉大道|錦繡花園 錦綉花園|阮政峯 阮政峰|陳柏緯 陳栢緯|雅芳婷牀褥 雅芳婷床褥|雅蘭牀褥 雅蘭床褥|青蓮台 青蓮臺|青蓮臺 青蓮臺|馬鞍山循道衛理小學 馬鞍山循道衛理小學|馬鞍山循道衞理小學 馬鞍山循道衛理小學|馬頭峯 馬頭峰|駿羣路 駿群路|騰龍台 騰龍臺|騰龍臺 騰龍臺|高盛台 高盛臺|高盛臺 高盛臺|魏韻芝 魏韵芝|鳳凰台 鳳凰臺|鳳凰臺 鳳凰臺|鳳羣徑 鳳群徑|鳳羣街 鳳群街|鳳輝台 鳳輝臺|鳳輝臺 鳳輝臺|麪房街 麵房街|麪房里 麵房里|黃成 黃成|黃柏文 黃栢文|黃柏鳴 黃栢鳴|鼇磡 鰲磡|鼇磡沙 鰲磡沙|鼇磡石 鰲磡石|鼇魚頭 鰲魚頭";
|
|
2
|
+
export default dict;
|