indickit 0.6.0 → 0.9.0
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 +245 -29
- package/dist/deromanize.js +1 -0
- package/dist/normalize.js +1 -204
- package/dist/phonetic-search.js +1 -0
- package/dist/phonetic.js +1 -836
- package/dist/romanize.js +1 -743
- package/dist/segment.js +1 -175
- package/dist/stem.js +1 -48
- package/dist/types/js/deromanize.d.ts +57 -0
- package/dist/types/js/phonetic-search.d.ts +104 -0
- package/dist/types/js/phonetic.d.ts +14 -0
- package/dist/types/js/stem.d.ts +1 -0
- package/dist/types/js/unidata.d.ts +36 -0
- package/dist/types/js/wellformed.d.ts +31 -0
- package/dist/wellformed.js +1 -0
- package/package.json +14 -2
package/dist/romanize.js
CHANGED
|
@@ -1,743 +1 @@
|
|
|
1
|
-
// romanize/rules.json
|
|
2
|
-
var rules_default = {
|
|
3
|
-
beam: {
|
|
4
|
-
names: 12,
|
|
5
|
-
words: 8
|
|
6
|
-
},
|
|
7
|
-
bos: "<s>",
|
|
8
|
-
eos: "</s>",
|
|
9
|
-
families: {
|
|
10
|
-
names: {
|
|
11
|
-
as: {
|
|
12
|
-
file: "as.names.bin",
|
|
13
|
-
group: "brahmic",
|
|
14
|
-
lookup: 669,
|
|
15
|
-
pooled: "names-brahmic.bin",
|
|
16
|
-
tag: "as"
|
|
17
|
-
},
|
|
18
|
-
bn: {
|
|
19
|
-
file: "bn.names.bin",
|
|
20
|
-
group: "brahmic",
|
|
21
|
-
lookup: 1785,
|
|
22
|
-
pooled: "names-brahmic.bin",
|
|
23
|
-
tag: "bn"
|
|
24
|
-
},
|
|
25
|
-
gom: {
|
|
26
|
-
file: "gom.names.bin",
|
|
27
|
-
group: "brahmic",
|
|
28
|
-
lookup: 17,
|
|
29
|
-
pooled: "names-brahmic.bin",
|
|
30
|
-
tag: "gom"
|
|
31
|
-
},
|
|
32
|
-
gu: {
|
|
33
|
-
file: "gu.names.bin",
|
|
34
|
-
group: "brahmic",
|
|
35
|
-
lookup: 131,
|
|
36
|
-
pooled: "names-brahmic.bin",
|
|
37
|
-
tag: "gu"
|
|
38
|
-
},
|
|
39
|
-
hi: {
|
|
40
|
-
file: "hi.names.bin",
|
|
41
|
-
group: "brahmic",
|
|
42
|
-
lookup: 1152,
|
|
43
|
-
pooled: "names-brahmic.bin",
|
|
44
|
-
tag: "hi"
|
|
45
|
-
},
|
|
46
|
-
kn: {
|
|
47
|
-
file: "kn.names.bin",
|
|
48
|
-
group: "brahmic",
|
|
49
|
-
lookup: 448,
|
|
50
|
-
pooled: "names-brahmic.bin",
|
|
51
|
-
tag: "kn"
|
|
52
|
-
},
|
|
53
|
-
ks: {
|
|
54
|
-
file: "ks.names.bin",
|
|
55
|
-
group: "arabic",
|
|
56
|
-
lookup: 130,
|
|
57
|
-
pooled: "names-arabic.bin",
|
|
58
|
-
tag: "ks"
|
|
59
|
-
},
|
|
60
|
-
mai: {
|
|
61
|
-
file: "mai.names.bin",
|
|
62
|
-
group: "brahmic",
|
|
63
|
-
lookup: 150,
|
|
64
|
-
pooled: "names-brahmic.bin",
|
|
65
|
-
tag: "mai"
|
|
66
|
-
},
|
|
67
|
-
ml: {
|
|
68
|
-
file: "ml.names.bin",
|
|
69
|
-
group: "brahmic",
|
|
70
|
-
lookup: 908,
|
|
71
|
-
pooled: "names-brahmic.bin",
|
|
72
|
-
tag: "ml"
|
|
73
|
-
},
|
|
74
|
-
mni: {
|
|
75
|
-
file: "mni.names.bin",
|
|
76
|
-
group: "meetei",
|
|
77
|
-
lookup: 253,
|
|
78
|
-
pooled: "names-meetei.bin",
|
|
79
|
-
tag: "mni"
|
|
80
|
-
},
|
|
81
|
-
mr: {
|
|
82
|
-
file: "mr.names.bin",
|
|
83
|
-
group: "brahmic",
|
|
84
|
-
lookup: 716,
|
|
85
|
-
pooled: "names-brahmic.bin",
|
|
86
|
-
tag: "mr"
|
|
87
|
-
},
|
|
88
|
-
ne: {
|
|
89
|
-
file: "ne.names.bin",
|
|
90
|
-
group: "brahmic",
|
|
91
|
-
lookup: 146,
|
|
92
|
-
pooled: "names-brahmic.bin",
|
|
93
|
-
tag: "ne"
|
|
94
|
-
},
|
|
95
|
-
or: {
|
|
96
|
-
file: "or.names.bin",
|
|
97
|
-
group: "brahmic",
|
|
98
|
-
lookup: 610,
|
|
99
|
-
pooled: "names-brahmic.bin",
|
|
100
|
-
tag: "or"
|
|
101
|
-
},
|
|
102
|
-
pa: {
|
|
103
|
-
file: "pa.names.bin",
|
|
104
|
-
group: "brahmic",
|
|
105
|
-
lookup: 996,
|
|
106
|
-
pooled: "names-brahmic.bin",
|
|
107
|
-
tag: "pa"
|
|
108
|
-
},
|
|
109
|
-
sa: {
|
|
110
|
-
file: "sa.names.bin",
|
|
111
|
-
group: "brahmic",
|
|
112
|
-
lookup: 66,
|
|
113
|
-
pooled: "names-brahmic.bin",
|
|
114
|
-
tag: "sa"
|
|
115
|
-
},
|
|
116
|
-
sat: {
|
|
117
|
-
file: "sat.names.bin",
|
|
118
|
-
group: "olchiki",
|
|
119
|
-
lookup: 407,
|
|
120
|
-
pooled: "names-olchiki.bin",
|
|
121
|
-
tag: "sat"
|
|
122
|
-
},
|
|
123
|
-
sd: {
|
|
124
|
-
file: "sd.names.bin",
|
|
125
|
-
group: "arabic",
|
|
126
|
-
lookup: 72,
|
|
127
|
-
pooled: "names-arabic.bin",
|
|
128
|
-
tag: "sd"
|
|
129
|
-
},
|
|
130
|
-
ta: {
|
|
131
|
-
file: "ta.names.bin",
|
|
132
|
-
group: "brahmic",
|
|
133
|
-
lookup: 3961,
|
|
134
|
-
pooled: "names-brahmic.bin",
|
|
135
|
-
tag: "ta"
|
|
136
|
-
},
|
|
137
|
-
te: {
|
|
138
|
-
file: "te.names.bin",
|
|
139
|
-
group: "brahmic",
|
|
140
|
-
lookup: 2126,
|
|
141
|
-
pooled: "names-brahmic.bin",
|
|
142
|
-
tag: "te"
|
|
143
|
-
},
|
|
144
|
-
ur: {
|
|
145
|
-
file: "ur.names.bin",
|
|
146
|
-
group: "arabic",
|
|
147
|
-
lookup: 1961,
|
|
148
|
-
pooled: "names-arabic.bin",
|
|
149
|
-
tag: "ur"
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
words: {
|
|
153
|
-
as: {
|
|
154
|
-
file: "as.words.bin",
|
|
155
|
-
group: "brahmic",
|
|
156
|
-
lookup: 0,
|
|
157
|
-
pooled: "words-brahmic.bin",
|
|
158
|
-
tag: "as:w"
|
|
159
|
-
},
|
|
160
|
-
bn: {
|
|
161
|
-
file: "bn.words.bin",
|
|
162
|
-
group: "brahmic",
|
|
163
|
-
lookup: 0,
|
|
164
|
-
pooled: "words-brahmic.bin",
|
|
165
|
-
tag: "bn:w"
|
|
166
|
-
},
|
|
167
|
-
brx: {
|
|
168
|
-
file: "brx.words.bin",
|
|
169
|
-
group: "brahmic",
|
|
170
|
-
lookup: 0,
|
|
171
|
-
pooled: "words-brahmic.bin",
|
|
172
|
-
tag: "brx:w"
|
|
173
|
-
},
|
|
174
|
-
doi: {
|
|
175
|
-
file: "doi.words.bin",
|
|
176
|
-
group: "brahmic",
|
|
177
|
-
lookup: 0,
|
|
178
|
-
pooled: "words-brahmic.bin",
|
|
179
|
-
tag: "doi:w"
|
|
180
|
-
},
|
|
181
|
-
gom: {
|
|
182
|
-
file: "gom.words.bin",
|
|
183
|
-
group: "brahmic",
|
|
184
|
-
lookup: 0,
|
|
185
|
-
pooled: "words-brahmic.bin",
|
|
186
|
-
tag: "gom:w"
|
|
187
|
-
},
|
|
188
|
-
gu: {
|
|
189
|
-
file: "gu.words.bin",
|
|
190
|
-
group: "brahmic",
|
|
191
|
-
lookup: 0,
|
|
192
|
-
pooled: "words-brahmic.bin",
|
|
193
|
-
tag: "gu:w"
|
|
194
|
-
},
|
|
195
|
-
hi: {
|
|
196
|
-
file: "hi.words.bin",
|
|
197
|
-
group: "brahmic",
|
|
198
|
-
lookup: 0,
|
|
199
|
-
pooled: "words-brahmic.bin",
|
|
200
|
-
tag: "hi:w"
|
|
201
|
-
},
|
|
202
|
-
kn: {
|
|
203
|
-
file: "kn.words.bin",
|
|
204
|
-
group: "brahmic",
|
|
205
|
-
lookup: 0,
|
|
206
|
-
pooled: "words-brahmic.bin",
|
|
207
|
-
tag: "kn:w"
|
|
208
|
-
},
|
|
209
|
-
ks: {
|
|
210
|
-
file: "ks.words.bin",
|
|
211
|
-
group: "arabic",
|
|
212
|
-
lookup: 0,
|
|
213
|
-
pooled: "words-arabic.bin",
|
|
214
|
-
tag: "ks:w"
|
|
215
|
-
},
|
|
216
|
-
mai: {
|
|
217
|
-
file: "mai.words.bin",
|
|
218
|
-
group: "brahmic",
|
|
219
|
-
lookup: 0,
|
|
220
|
-
pooled: "words-brahmic.bin",
|
|
221
|
-
tag: "mai:w"
|
|
222
|
-
},
|
|
223
|
-
ml: {
|
|
224
|
-
file: "ml.words.bin",
|
|
225
|
-
group: "brahmic",
|
|
226
|
-
lookup: 0,
|
|
227
|
-
pooled: "words-brahmic.bin",
|
|
228
|
-
tag: "ml:w"
|
|
229
|
-
},
|
|
230
|
-
mni: {
|
|
231
|
-
file: "mni.words.bin",
|
|
232
|
-
group: "meetei",
|
|
233
|
-
lookup: 0,
|
|
234
|
-
pooled: "words-meetei.bin",
|
|
235
|
-
tag: "mni:w"
|
|
236
|
-
},
|
|
237
|
-
mr: {
|
|
238
|
-
file: "mr.words.bin",
|
|
239
|
-
group: "brahmic",
|
|
240
|
-
lookup: 0,
|
|
241
|
-
pooled: "words-brahmic.bin",
|
|
242
|
-
tag: "mr:w"
|
|
243
|
-
},
|
|
244
|
-
ne: {
|
|
245
|
-
file: "ne.words.bin",
|
|
246
|
-
group: "brahmic",
|
|
247
|
-
lookup: 0,
|
|
248
|
-
pooled: "words-brahmic.bin",
|
|
249
|
-
tag: "ne:w"
|
|
250
|
-
},
|
|
251
|
-
or: {
|
|
252
|
-
file: "or.words.bin",
|
|
253
|
-
group: "brahmic",
|
|
254
|
-
lookup: 0,
|
|
255
|
-
pooled: "words-brahmic.bin",
|
|
256
|
-
tag: "or:w"
|
|
257
|
-
},
|
|
258
|
-
pa: {
|
|
259
|
-
file: "pa.words.bin",
|
|
260
|
-
group: "brahmic",
|
|
261
|
-
lookup: 0,
|
|
262
|
-
pooled: "words-brahmic.bin",
|
|
263
|
-
tag: "pa:w"
|
|
264
|
-
},
|
|
265
|
-
sa: {
|
|
266
|
-
file: "sa.words.bin",
|
|
267
|
-
group: "brahmic",
|
|
268
|
-
lookup: 0,
|
|
269
|
-
pooled: "words-brahmic.bin",
|
|
270
|
-
tag: "sa:w"
|
|
271
|
-
},
|
|
272
|
-
sd: {
|
|
273
|
-
file: "sd.words.bin",
|
|
274
|
-
group: "arabic",
|
|
275
|
-
lookup: 0,
|
|
276
|
-
pooled: "words-arabic.bin",
|
|
277
|
-
tag: "sd:w"
|
|
278
|
-
},
|
|
279
|
-
ta: {
|
|
280
|
-
file: "ta.words.bin",
|
|
281
|
-
group: "brahmic",
|
|
282
|
-
lookup: 0,
|
|
283
|
-
pooled: "words-brahmic.bin",
|
|
284
|
-
tag: "ta:w"
|
|
285
|
-
},
|
|
286
|
-
te: {
|
|
287
|
-
file: "te.words.bin",
|
|
288
|
-
group: "brahmic",
|
|
289
|
-
lookup: 0,
|
|
290
|
-
pooled: "words-brahmic.bin",
|
|
291
|
-
tag: "te:w"
|
|
292
|
-
},
|
|
293
|
-
ur: {
|
|
294
|
-
file: "ur.words.bin",
|
|
295
|
-
group: "arabic",
|
|
296
|
-
lookup: 0,
|
|
297
|
-
pooled: "words-arabic.bin",
|
|
298
|
-
tag: "ur:w"
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
files: {
|
|
303
|
-
"as.names.bin": 89974,
|
|
304
|
-
"as.words.bin": 235757,
|
|
305
|
-
"bn.names.bin": 182011,
|
|
306
|
-
"bn.words.bin": 377491,
|
|
307
|
-
"brx.words.bin": 208654,
|
|
308
|
-
"doi.words.bin": 48681,
|
|
309
|
-
"gom.names.bin": 9361,
|
|
310
|
-
"gom.words.bin": 324293,
|
|
311
|
-
"gu.names.bin": 38634,
|
|
312
|
-
"gu.words.bin": 370117,
|
|
313
|
-
"hi.names.bin": 162471,
|
|
314
|
-
"hi.words.bin": 468425,
|
|
315
|
-
"kn.names.bin": 73095,
|
|
316
|
-
"kn.words.bin": 273776,
|
|
317
|
-
"ks.names.bin": 36223,
|
|
318
|
-
"ks.words.bin": 445883,
|
|
319
|
-
"mai.names.bin": 40421,
|
|
320
|
-
"mai.words.bin": 381362,
|
|
321
|
-
"ml.names.bin": 133130,
|
|
322
|
-
"ml.words.bin": 342656,
|
|
323
|
-
"mni.names.bin": 12382,
|
|
324
|
-
"mni.words.bin": 133350,
|
|
325
|
-
"mr.names.bin": 119082,
|
|
326
|
-
"mr.words.bin": 327753,
|
|
327
|
-
"names-arabic.bin": 188775,
|
|
328
|
-
"names-brahmic.bin": 594055,
|
|
329
|
-
"names-meetei.bin": 43805,
|
|
330
|
-
"names-olchiki.bin": 97591,
|
|
331
|
-
"ne.names.bin": 37468,
|
|
332
|
-
"ne.words.bin": 297072,
|
|
333
|
-
"or.names.bin": 83867,
|
|
334
|
-
"or.words.bin": 285972,
|
|
335
|
-
"pa.names.bin": 140045,
|
|
336
|
-
"pa.words.bin": 419426,
|
|
337
|
-
"sa.names.bin": 24600,
|
|
338
|
-
"sa.words.bin": 243993,
|
|
339
|
-
"sat.names.bin": 73397,
|
|
340
|
-
"sd.names.bin": 11896,
|
|
341
|
-
"sd.words.bin": 463475,
|
|
342
|
-
"ta.names.bin": 295030,
|
|
343
|
-
"ta.words.bin": 244532,
|
|
344
|
-
"te.names.bin": 229077,
|
|
345
|
-
"te.words.bin": 295013,
|
|
346
|
-
"ur.names.bin": 192400,
|
|
347
|
-
"ur.words.bin": 540255,
|
|
348
|
-
"words-arabic.bin": 1182486,
|
|
349
|
-
"words-brahmic.bin": 2542643,
|
|
350
|
-
"words-meetei.bin": 198229,
|
|
351
|
-
"words-olchiki.bin": 61705
|
|
352
|
-
},
|
|
353
|
-
groups: {
|
|
354
|
-
arabic: [
|
|
355
|
-
1536,
|
|
356
|
-
1791
|
|
357
|
-
],
|
|
358
|
-
brahmic: [
|
|
359
|
-
2304,
|
|
360
|
-
3455
|
|
361
|
-
],
|
|
362
|
-
meetei: [
|
|
363
|
-
43744,
|
|
364
|
-
44031
|
|
365
|
-
],
|
|
366
|
-
olchiki: [
|
|
367
|
-
7248,
|
|
368
|
-
7295
|
|
369
|
-
]
|
|
370
|
-
},
|
|
371
|
-
max_n: 3,
|
|
372
|
-
order: 3,
|
|
373
|
-
rules_version: "2026-10-07",
|
|
374
|
-
unify: {
|
|
375
|
-
from: [
|
|
376
|
-
2432,
|
|
377
|
-
3455
|
|
378
|
-
],
|
|
379
|
-
mask: 127,
|
|
380
|
-
to_block: 2304
|
|
381
|
-
},
|
|
382
|
-
unknown_penalty: 20,
|
|
383
|
-
version: 1
|
|
384
|
-
};
|
|
385
|
-
// package.json
|
|
386
|
-
var version = "0.6.0";
|
|
387
|
-
|
|
388
|
-
// js/lang.ts
|
|
389
|
-
var ISO_639_2 = "asm as ben bn guj gu hin hi kan kn kas ks mal ml mar mr nep ne ori or pan pa san sa snd sd tam ta tel te urd ur ";
|
|
390
|
-
function langCode(tag) {
|
|
391
|
-
const t = (tag ?? "").toLowerCase().split(/[-_]/)[0];
|
|
392
|
-
const i = t.length === 3 ? ISO_639_2.indexOf(t + " ") : -1;
|
|
393
|
-
return i >= 0 && i % 7 === 0 ? ISO_639_2.slice(i + 4, i + 6) : t;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// js/romanize.ts
|
|
397
|
-
var RULES = rules_default;
|
|
398
|
-
var RULES_VERSION = RULES.rules_version;
|
|
399
|
-
function languages(mode = "words") {
|
|
400
|
-
return Object.keys(RULES.families[mode]).sort();
|
|
401
|
-
}
|
|
402
|
-
var CDN = `https://cdn.jsdelivr.net/gh/micahchoo/indickit@v${version}/romanize/lang/`;
|
|
403
|
-
async function fetchBytes(url) {
|
|
404
|
-
const res = await fetch(url);
|
|
405
|
-
if (!res.ok)
|
|
406
|
-
throw new Error(`romanize: ${url}: ${res.status}`);
|
|
407
|
-
return res.arrayBuffer();
|
|
408
|
-
}
|
|
409
|
-
function defaultFetcher(local) {
|
|
410
|
-
return async (url) => {
|
|
411
|
-
try {
|
|
412
|
-
return await fetchBytes(url);
|
|
413
|
-
} catch {
|
|
414
|
-
return fetchBytes(new URL(url.href.slice(local.href.length), CDN));
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
function code(lang) {
|
|
419
|
-
const c = langCode(lang);
|
|
420
|
-
return c === "kok" ? "gom" : c;
|
|
421
|
-
}
|
|
422
|
-
var pooledCache = new Map;
|
|
423
|
-
async function load(lang, mode = "words", opts = {}) {
|
|
424
|
-
const c = code(lang);
|
|
425
|
-
const l = RULES.families[mode][c];
|
|
426
|
-
if (!l)
|
|
427
|
-
throw new Error(`romanize: no ${mode} tables for "${lang}"`);
|
|
428
|
-
const base = new URL(opts.base ?? "../romanize/lang/", import.meta.url);
|
|
429
|
-
const get = opts.fetch ?? (opts.base ? fetchBytes : defaultFetcher(base));
|
|
430
|
-
const poolKey = `${base}${l.group}/${l.pooled}`;
|
|
431
|
-
if (!pooledCache.has(poolKey))
|
|
432
|
-
pooledCache.set(poolKey, get(new URL(`${l.group}/${l.pooled}`, base)));
|
|
433
|
-
const [own, pool] = await Promise.all([get(new URL(`${c}/${l.file}`, base)), pooledCache.get(poolKey)]);
|
|
434
|
-
return fromBytes(c, mode, new Uint8Array(own), new Uint8Array(pool));
|
|
435
|
-
}
|
|
436
|
-
function fromBytes(lang, mode, own, pool) {
|
|
437
|
-
const l = RULES.families[mode][lang];
|
|
438
|
-
if (!l)
|
|
439
|
-
throw new Error(`romanize: no ${mode} tables for "${lang}"`);
|
|
440
|
-
const x = new Mix(own, pool, l.tag, RULES.beam[mode]);
|
|
441
|
-
const [lo, hi] = RULES.groups[l.group];
|
|
442
|
-
const inScript = (ch) => {
|
|
443
|
-
const cp = ch.codePointAt(0);
|
|
444
|
-
return cp >= lo && cp <= hi || cp === 8204 || cp === 8205;
|
|
445
|
-
};
|
|
446
|
-
const letter = /[\p{L}\p{M}]/u;
|
|
447
|
-
const word = (w, n = 4) => {
|
|
448
|
-
const s = w.normalize("NFC");
|
|
449
|
-
const known = x.lookup.get(s);
|
|
450
|
-
if (known)
|
|
451
|
-
return known.slice(0, n);
|
|
452
|
-
return x.decode(unify(s), n).filter((o) => o !== "");
|
|
453
|
-
};
|
|
454
|
-
const r = {
|
|
455
|
-
lang,
|
|
456
|
-
mode,
|
|
457
|
-
word,
|
|
458
|
-
text(t) {
|
|
459
|
-
const cs = [...t.normalize("NFC")];
|
|
460
|
-
let out = "";
|
|
461
|
-
for (let i = 0;i < cs.length; ) {
|
|
462
|
-
if (!(inScript(cs[i]) && letter.test(cs[i]))) {
|
|
463
|
-
out += cs[i++];
|
|
464
|
-
continue;
|
|
465
|
-
}
|
|
466
|
-
let j = i;
|
|
467
|
-
while (j < cs.length && inScript(cs[j]) && letter.test(cs[j]))
|
|
468
|
-
j++;
|
|
469
|
-
const run = cs.slice(i, j).join("");
|
|
470
|
-
out += word(run, 1)[0] ?? run;
|
|
471
|
-
i = j;
|
|
472
|
-
}
|
|
473
|
-
return out;
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
Object.defineProperty(r, "_mix", { value: x });
|
|
477
|
-
return r;
|
|
478
|
-
}
|
|
479
|
-
function unify(w) {
|
|
480
|
-
const u = RULES.unify;
|
|
481
|
-
let out = "";
|
|
482
|
-
for (const ch of w) {
|
|
483
|
-
const cp = ch.codePointAt(0);
|
|
484
|
-
out += cp >= u.from[0] && cp <= u.from[1] ? String.fromCodePoint(u.to_block + (cp & u.mask)) : ch;
|
|
485
|
-
}
|
|
486
|
-
return out;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
class Reader {
|
|
490
|
-
b;
|
|
491
|
-
pos = 4;
|
|
492
|
-
constructor(b) {
|
|
493
|
-
this.b = b;
|
|
494
|
-
if (b[0] !== 73 || b[1] !== 75 || b[2] !== 82 || b[3] !== 49)
|
|
495
|
-
throw new Error("romanize: not an IKR1 file");
|
|
496
|
-
}
|
|
497
|
-
varint() {
|
|
498
|
-
let v = 0;
|
|
499
|
-
let shift = 1;
|
|
500
|
-
for (;; ) {
|
|
501
|
-
const byte = this.b[this.pos++];
|
|
502
|
-
v += (byte & 127) * shift;
|
|
503
|
-
if (byte < 128)
|
|
504
|
-
return v;
|
|
505
|
-
shift *= 128;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
str() {
|
|
509
|
-
const n = this.varint();
|
|
510
|
-
const s = DECODER.decode(this.b.subarray(this.pos, this.pos + n));
|
|
511
|
-
this.pos += n;
|
|
512
|
-
return s;
|
|
513
|
-
}
|
|
514
|
-
float64() {
|
|
515
|
-
const v = new DataView(this.b.buffer, this.b.byteOffset + this.pos, 8).getFloat64(0, true);
|
|
516
|
-
this.pos += 8;
|
|
517
|
-
return v;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
var DECODER = new TextDecoder;
|
|
521
|
-
var ID = 2 ** 21;
|
|
522
|
-
function ctxKey(ctx, from) {
|
|
523
|
-
let k = 0;
|
|
524
|
-
for (let i = from;i < ctx.length; i++)
|
|
525
|
-
k = k * ID + (ctx[i] + 1);
|
|
526
|
-
return k;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
class Model {
|
|
530
|
-
vocab;
|
|
531
|
-
levels = [];
|
|
532
|
-
constructor(r, strs, ids) {
|
|
533
|
-
this.vocab = r.varint();
|
|
534
|
-
for (let l = r.varint();l > 0; l--) {
|
|
535
|
-
const lv = { stats: new Map, counts: new Map };
|
|
536
|
-
for (let c = r.varint();c > 0; c--) {
|
|
537
|
-
const ctx = [];
|
|
538
|
-
for (let i = r.varint();i > 0; i--)
|
|
539
|
-
ctx.push(ids.id(strs[r.varint()]));
|
|
540
|
-
const key = ctxKey(ctx, 0);
|
|
541
|
-
const counts = new Map;
|
|
542
|
-
let total = 0;
|
|
543
|
-
let prev = 0;
|
|
544
|
-
for (let t = r.varint();t > 0; t--) {
|
|
545
|
-
prev += r.varint();
|
|
546
|
-
const k = r.varint();
|
|
547
|
-
counts.set(ids.id(strs[prev]), k);
|
|
548
|
-
total += k;
|
|
549
|
-
}
|
|
550
|
-
lv.stats.set(key, [total, counts.size]);
|
|
551
|
-
lv.counts.set(key, counts);
|
|
552
|
-
}
|
|
553
|
-
this.levels.push(lv);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
stats(ctx) {
|
|
557
|
-
const s = { counts: [], total: [], wb: [] };
|
|
558
|
-
for (let n = 0;n < this.levels.length; n++) {
|
|
559
|
-
const key = ctxKey(ctx, ctx.length - n);
|
|
560
|
-
const st = this.levels[n].stats.get(key);
|
|
561
|
-
if (st && st[1] !== 0) {
|
|
562
|
-
s.counts[n] = this.levels[n].counts.get(key);
|
|
563
|
-
s.total[n] = st[0];
|
|
564
|
-
s.wb[n] = st[0] / (st[0] + st[1]);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return s;
|
|
568
|
-
}
|
|
569
|
-
prob(s, tok) {
|
|
570
|
-
let p = 1 / (this.vocab + 1);
|
|
571
|
-
for (let n = 0;n < this.levels.length; n++) {
|
|
572
|
-
const c = s.counts[n];
|
|
573
|
-
if (!c)
|
|
574
|
-
continue;
|
|
575
|
-
const lam = s.wb[n];
|
|
576
|
-
p = lam * (c.get(tok) ?? 0) / s.total[n] + (1 - lam) * p;
|
|
577
|
-
}
|
|
578
|
-
return p;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
class Interner {
|
|
583
|
-
ids = new Map;
|
|
584
|
-
strs = [];
|
|
585
|
-
id(s) {
|
|
586
|
-
let v = this.ids.get(s);
|
|
587
|
-
if (v === undefined) {
|
|
588
|
-
v = this.strs.length;
|
|
589
|
-
this.ids.set(s, v);
|
|
590
|
-
this.strs.push(s);
|
|
591
|
-
}
|
|
592
|
-
return v;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
function before(a, b) {
|
|
596
|
-
if (a.score !== b.score)
|
|
597
|
-
return a.score > b.score;
|
|
598
|
-
if (a.out !== b.out)
|
|
599
|
-
return a.out < b.out;
|
|
600
|
-
return a.idx < b.idx;
|
|
601
|
-
}
|
|
602
|
-
function top(cs, k) {
|
|
603
|
-
const best = [];
|
|
604
|
-
for (const c of cs) {
|
|
605
|
-
if (best.length === k && !before(c, best[k - 1]))
|
|
606
|
-
continue;
|
|
607
|
-
let lo = 0;
|
|
608
|
-
let hi = best.length;
|
|
609
|
-
while (lo < hi) {
|
|
610
|
-
const mid = lo + hi >> 1;
|
|
611
|
-
if (before(c, best[mid]))
|
|
612
|
-
hi = mid;
|
|
613
|
-
else
|
|
614
|
-
lo = mid + 1;
|
|
615
|
-
}
|
|
616
|
-
best.splice(lo, 0, c);
|
|
617
|
-
if (best.length > k)
|
|
618
|
-
best.pop();
|
|
619
|
-
}
|
|
620
|
-
return best;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
class Mix {
|
|
624
|
-
beam;
|
|
625
|
-
a;
|
|
626
|
-
b;
|
|
627
|
-
lam;
|
|
628
|
-
start = [];
|
|
629
|
-
eos;
|
|
630
|
-
options = new Map;
|
|
631
|
-
lookup = new Map;
|
|
632
|
-
constructor(own, pool, tag, beam) {
|
|
633
|
-
this.beam = beam;
|
|
634
|
-
const ids = new Interner;
|
|
635
|
-
let r = new Reader(pool);
|
|
636
|
-
let strs = readStrings(r);
|
|
637
|
-
this.b = new Model(r, strs, ids);
|
|
638
|
-
r = new Reader(own);
|
|
639
|
-
strs = readStrings(r);
|
|
640
|
-
this.lam = r.float64();
|
|
641
|
-
this.a = new Model(r, strs, ids);
|
|
642
|
-
for (let k = r.varint();k > 0; k--) {
|
|
643
|
-
const native = r.str();
|
|
644
|
-
const sp = [];
|
|
645
|
-
for (let i = r.varint();i > 0; i--)
|
|
646
|
-
sp.push(strs[r.varint()]);
|
|
647
|
-
this.lookup.set(native, sp);
|
|
648
|
-
}
|
|
649
|
-
for (let i = 0;i < RULES.order - 2; i++)
|
|
650
|
-
this.start.push(ids.id(RULES.bos));
|
|
651
|
-
this.start.push(ids.id(`<s:${tag}>`));
|
|
652
|
-
this.eos = ids.id(RULES.eos);
|
|
653
|
-
const seen = new Set;
|
|
654
|
-
for (const m of [this.a, this.b]) {
|
|
655
|
-
for (const counts of m.levels[0].counts.values()) {
|
|
656
|
-
for (const t of counts.keys()) {
|
|
657
|
-
if (t === this.eos || seen.has(t))
|
|
658
|
-
continue;
|
|
659
|
-
seen.add(t);
|
|
660
|
-
const s = ids.strs[t];
|
|
661
|
-
const i = s.indexOf("|");
|
|
662
|
-
const chunk = s.slice(0, i);
|
|
663
|
-
const list = this.options.get(chunk) ?? [];
|
|
664
|
-
list.push({ tok: t, en: s.slice(i + 1) });
|
|
665
|
-
this.options.set(chunk, list);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
for (const list of this.options.values())
|
|
670
|
-
list.sort((p, q) => p.en < q.en ? -1 : p.en > q.en ? 1 : 0);
|
|
671
|
-
if (this.start.length > 2 || ids.strs.length >= ID)
|
|
672
|
-
throw new Error("romanize: beyond the engine's limits");
|
|
673
|
-
}
|
|
674
|
-
logp(sa, sb, tok) {
|
|
675
|
-
const pa = Math.exp(Math.log(this.a.prob(sa, tok)));
|
|
676
|
-
const pb = Math.exp(Math.log(this.b.prob(sb, tok)));
|
|
677
|
-
return Math.log(this.lam * pa + (1 - this.lam) * pb);
|
|
678
|
-
}
|
|
679
|
-
decode(word, n) {
|
|
680
|
-
const w = [...word];
|
|
681
|
-
const h = RULES.order - 1;
|
|
682
|
-
const root = { score: 0, out: "", ctx: this.start };
|
|
683
|
-
const beams = Array.from({ length: w.length + 1 }, () => []);
|
|
684
|
-
beams[0].push({ score: 0, out: "", parent: null, tok: -1, idx: 0 });
|
|
685
|
-
const context = (c) => {
|
|
686
|
-
if (c.tok < 0)
|
|
687
|
-
return c.parent.ctx;
|
|
688
|
-
const ctx = [...c.parent.ctx, c.tok];
|
|
689
|
-
return ctx.slice(ctx.length - h);
|
|
690
|
-
};
|
|
691
|
-
for (let i = 0;i < w.length; i++) {
|
|
692
|
-
if (beams[i].length === 0)
|
|
693
|
-
continue;
|
|
694
|
-
for (const c of top(beams[i], this.beam)) {
|
|
695
|
-
const hy = i === 0 ? root : { score: c.score, out: c.out, ctx: context(c) };
|
|
696
|
-
let moved = false;
|
|
697
|
-
const sa = this.a.stats(hy.ctx);
|
|
698
|
-
const sb = this.b.stats(hy.ctx);
|
|
699
|
-
for (let k = 1;k <= RULES.max_n && i + k <= w.length; k++) {
|
|
700
|
-
const opts = this.options.get(w.slice(i, i + k).join(""));
|
|
701
|
-
if (!opts)
|
|
702
|
-
continue;
|
|
703
|
-
for (const o of opts) {
|
|
704
|
-
const next = beams[i + k];
|
|
705
|
-
next.push({ score: hy.score + this.logp(sa, sb, o.tok), out: hy.out + o.en, parent: hy, tok: o.tok, idx: next.length });
|
|
706
|
-
moved = true;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
if (!moved) {
|
|
710
|
-
const next = beams[i + 1];
|
|
711
|
-
next.push({ score: hy.score - RULES.unknown_penalty, out: hy.out, parent: hy, tok: -1, idx: next.length });
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
const final = new Map;
|
|
716
|
-
for (const c of beams[w.length]) {
|
|
717
|
-
const ctx = c.parent === null ? this.start : context(c);
|
|
718
|
-
const s = c.score + this.logp(this.a.stats(ctx), this.b.stats(ctx), this.eos);
|
|
719
|
-
const v = final.get(c.out);
|
|
720
|
-
if (v === undefined || s > v)
|
|
721
|
-
final.set(c.out, s);
|
|
722
|
-
}
|
|
723
|
-
return [...final].sort((p, q) => p[1] !== q[1] ? q[1] - p[1] : p[0] < q[0] ? -1 : p[0] > q[0] ? 1 : 0).slice(0, n).map((e) => e[0]);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
function readStrings(r) {
|
|
727
|
-
const strs = [];
|
|
728
|
-
for (let i = r.varint();i > 0; i--)
|
|
729
|
-
strs.push(r.str());
|
|
730
|
-
return strs;
|
|
731
|
-
}
|
|
732
|
-
function _decode(r, word, n) {
|
|
733
|
-
return r._mix.decode(word, n);
|
|
734
|
-
}
|
|
735
|
-
export {
|
|
736
|
-
unify,
|
|
737
|
-
load,
|
|
738
|
-
languages,
|
|
739
|
-
fromBytes,
|
|
740
|
-
_decode,
|
|
741
|
-
RULES_VERSION,
|
|
742
|
-
CDN
|
|
743
|
-
};
|
|
1
|
+
var N={beam:{names:12,words:8},bos:"<s>",eos:"</s>",families:{names:{as:{file:"as.names.bin",group:"brahmic",lookup:669,pooled:"names-brahmic.bin",tag:"as"},bn:{file:"bn.names.bin",group:"brahmic",lookup:1785,pooled:"names-brahmic.bin",tag:"bn"},gom:{file:"gom.names.bin",group:"brahmic",lookup:17,pooled:"names-brahmic.bin",tag:"gom"},gu:{file:"gu.names.bin",group:"brahmic",lookup:131,pooled:"names-brahmic.bin",tag:"gu"},hi:{file:"hi.names.bin",group:"brahmic",lookup:1152,pooled:"names-brahmic.bin",tag:"hi"},kn:{file:"kn.names.bin",group:"brahmic",lookup:448,pooled:"names-brahmic.bin",tag:"kn"},ks:{file:"ks.names.bin",group:"arabic",lookup:130,pooled:"names-arabic.bin",tag:"ks"},mai:{file:"mai.names.bin",group:"brahmic",lookup:150,pooled:"names-brahmic.bin",tag:"mai"},ml:{file:"ml.names.bin",group:"brahmic",lookup:908,pooled:"names-brahmic.bin",tag:"ml"},mni:{file:"mni.names.bin",group:"brahmic",lookup:253,pooled:"names-brahmic.bin",tag:"mni"},mr:{file:"mr.names.bin",group:"brahmic",lookup:716,pooled:"names-brahmic.bin",tag:"mr"},ne:{file:"ne.names.bin",group:"brahmic",lookup:146,pooled:"names-brahmic.bin",tag:"ne"},or:{file:"or.names.bin",group:"brahmic",lookup:610,pooled:"names-brahmic.bin",tag:"or"},pa:{file:"pa.names.bin",group:"brahmic",lookup:996,pooled:"names-brahmic.bin",tag:"pa"},sa:{file:"sa.names.bin",group:"brahmic",lookup:66,pooled:"names-brahmic.bin",tag:"sa"},sat:{file:"sat.names.bin",group:"olchiki",lookup:407,pooled:"names-olchiki.bin",tag:"sat"},sd:{file:"sd.names.bin",group:"arabic",lookup:72,pooled:"names-arabic.bin",tag:"sd"},ta:{file:"ta.names.bin",group:"brahmic",lookup:3961,pooled:"names-brahmic.bin",tag:"ta"},te:{file:"te.names.bin",group:"brahmic",lookup:2126,pooled:"names-brahmic.bin",tag:"te"},ur:{file:"ur.names.bin",group:"arabic",lookup:1961,pooled:"names-arabic.bin",tag:"ur"}},words:{as:{file:"as.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"as:w"},bn:{file:"bn.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"bn:w"},brx:{file:"brx.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"brx:w"},doi:{file:"doi.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"doi:w"},gom:{file:"gom.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"gom:w"},gu:{file:"gu.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"gu:w"},hi:{file:"hi.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"hi:w"},kn:{file:"kn.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"kn:w"},ks:{file:"ks.words.bin",group:"arabic",lookup:0,pooled:"words-arabic.bin",tag:"ks:w"},mai:{file:"mai.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"mai:w"},ml:{file:"ml.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"ml:w"},mni:{file:"mni.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"mni:w"},mr:{file:"mr.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"mr:w"},ne:{file:"ne.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"ne:w"},or:{file:"or.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"or:w"},pa:{file:"pa.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"pa:w"},sa:{file:"sa.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"sa:w"},sd:{file:"sd.words.bin",group:"arabic",lookup:0,pooled:"words-arabic.bin",tag:"sd:w"},ta:{file:"ta.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"ta:w"},te:{file:"te.words.bin",group:"brahmic",lookup:0,pooled:"words-brahmic.bin",tag:"te:w"},ur:{file:"ur.words.bin",group:"arabic",lookup:0,pooled:"words-arabic.bin",tag:"ur:w"}}},files:{"as.names.bin":89974,"as.words.bin":235757,"bn.names.bin":182011,"bn.words.bin":377491,"brx.words.bin":208654,"doi.words.bin":48681,"gom.names.bin":9361,"gom.words.bin":324293,"gu.names.bin":38634,"gu.words.bin":370117,"hi.names.bin":162471,"hi.words.bin":468425,"kn.names.bin":73095,"kn.words.bin":273776,"ks.names.bin":36223,"ks.words.bin":445883,"mai.names.bin":40421,"mai.words.bin":381362,"ml.names.bin":133130,"ml.words.bin":342656,"mni.names.bin":12382,"mni.words.bin":133350,"mr.names.bin":119082,"mr.words.bin":327753,"names-arabic.bin":188775,"names-brahmic.bin":600155,"names-olchiki.bin":97591,"ne.names.bin":37468,"ne.words.bin":297072,"or.names.bin":83867,"or.words.bin":285972,"pa.names.bin":140045,"pa.words.bin":419426,"sa.names.bin":24600,"sa.words.bin":243993,"sat.names.bin":73397,"sd.names.bin":11896,"sd.words.bin":463475,"ta.names.bin":295030,"ta.words.bin":244532,"te.names.bin":229077,"te.words.bin":295013,"ur.names.bin":192400,"ur.words.bin":540255,"words-arabic.bin":1182486,"words-brahmic.bin":2679161,"words-olchiki.bin":61705},groups:{arabic:[[1536,1791]],brahmic:[[2304,3455],[43744,44031]],olchiki:[[7248,7295]]},max_letters:256,max_n:3,order:3,rules_version:"2026-10-09",unify:{from:[2432,3455],mask:127,to_block:2304},unknown_penalty:20,version:1};var C="0.9.0";function D(i){let n=(i??"").toLowerCase().split(/[-_]/)[0],a=n.length===3?"asm as ben bn guj gu hin hi kan kn kas ks mal ml mar mr nep ne ori or pan pa san sa snd sd tam ta tel te urd ur ".indexOf(n+" "):-1;return a>=0&&a%7===0?"asm as ben bn guj gu hin hi kan kn kas ks mal ml mar mr nep ne ori or pan pa san sa snd sd tam ta tel te urd ur ".slice(a+4,a+6):n}var z={unicode:"15.0.0",python:"3.12.13",ranges:[1536,1791,1872,1919,2304,3455,7248,7295,7376,7423,43232,43263,43744,44031,64336,65023,65136,65279,72448,72543],mn:[1552,1562,1611,1631,1648,1648,1750,1756,1759,1764,1767,1768,1770,1773,2304,2306,2362,2362,2364,2364,2369,2376,2381,2381,2385,2391,2402,2403,2433,2433,2492,2492,2497,2500,2509,2509,2530,2531,2558,2558,2561,2562,2620,2620,2625,2626,2631,2632,2635,2637,2641,2641,2672,2673,2677,2677,2689,2690,2748,2748,2753,2757,2759,2760,2765,2765,2786,2787,2810,2815,2817,2817,2876,2876,2879,2879,2881,2884,2893,2893,2901,2902,2914,2915,2946,2946,3008,3008,3021,3021,3072,3072,3076,3076,3132,3132,3134,3136,3142,3144,3146,3149,3157,3158,3170,3171,3201,3201,3260,3260,3263,3263,3270,3270,3276,3277,3298,3299,3328,3329,3387,3388,3393,3396,3405,3405,3426,3427,7376,7378,7380,7392,7394,7400,7405,7405,7412,7412,7416,7417,43232,43249,43263,43263,43756,43757,43766,43766,44005,44005,44008,44008,44013,44013],m:[1552,1562,1611,1631,1648,1648,1750,1756,1759,1764,1767,1768,1770,1773,2304,2307,2362,2364,2366,2383,2385,2391,2402,2403,2433,2435,2492,2492,2494,2500,2503,2504,2507,2509,2519,2519,2530,2531,2558,2558,2561,2563,2620,2620,2622,2626,2631,2632,2635,2637,2641,2641,2672,2673,2677,2677,2689,2691,2748,2748,2750,2757,2759,2761,2763,2765,2786,2787,2810,2815,2817,2819,2876,2876,2878,2884,2887,2888,2891,2893,2901,2903,2914,2915,2946,2946,3006,3010,3014,3016,3018,3021,3031,3031,3072,3076,3132,3132,3134,3140,3142,3144,3146,3149,3157,3158,3170,3171,3201,3203,3260,3260,3262,3268,3270,3272,3274,3277,3285,3286,3298,3299,3315,3315,3328,3331,3387,3388,3390,3396,3398,3400,3402,3405,3415,3415,3426,3427,7376,7378,7380,7400,7405,7405,7412,7412,7415,7417,43232,43249,43263,43263,43755,43759,43765,43766,44003,44010,44012,44013],l:[1568,1610,1646,1647,1649,1747,1749,1749,1765,1766,1774,1775,1786,1788,1791,1791,1872,1919,2308,2361,2365,2365,2384,2384,2392,2401,2417,2432,2437,2444,2447,2448,2451,2472,2474,2480,2482,2482,2486,2489,2493,2493,2510,2510,2524,2525,2527,2529,2544,2545,2556,2556,2565,2570,2575,2576,2579,2600,2602,2608,2610,2611,2613,2614,2616,2617,2649,2652,2654,2654,2674,2676,2693,2701,2703,2705,2707,2728,2730,2736,2738,2739,2741,2745,2749,2749,2768,2768,2784,2785,2809,2809,2821,2828,2831,2832,2835,2856,2858,2864,2866,2867,2869,2873,2877,2877,2908,2909,2911,2913,2929,2929,2947,2947,2949,2954,2958,2960,2962,2965,2969,2970,2972,2972,2974,2975,2979,2980,2984,2986,2990,3001,3024,3024,3077,3084,3086,3088,3090,3112,3114,3129,3133,3133,3160,3162,3165,3165,3168,3169,3200,3200,3205,3212,3214,3216,3218,3240,3242,3251,3253,3257,3261,3261,3293,3294,3296,3297,3313,3314,3332,3340,3342,3344,3346,3386,3389,3389,3406,3406,3412,3414,3423,3425,3450,3455,7258,7293,7401,7404,7406,7411,7413,7414,7418,7418,43250,43255,43259,43259,43261,43262,43744,43754,43762,43764,43777,43782,43785,43790,43793,43798,43808,43814,43816,43822,43824,43866,43868,43881,43888,44002,64336,64433,64467,64829,64848,64911,64914,64967,65008,65019,65136,65140,65142,65276],ccc:[1552,1559,230,1560,1560,30,1561,1561,31,1562,1562,32,1611,1611,27,1612,1612,28,1613,1613,29,1614,1614,30,1615,1615,31,1616,1616,32,1617,1617,33,1618,1618,34,1619,1620,230,1621,1622,220,1623,1627,230,1628,1628,220,1629,1630,230,1631,1631,220,1648,1648,35,1750,1756,230,1759,1762,230,1763,1763,220,1764,1764,230,1767,1768,230,1770,1770,220,1771,1772,230,1773,1773,220,2364,2364,7,2381,2381,9,2385,2385,230,2386,2386,220,2387,2388,230,2492,2492,7,2509,2509,9,2558,2558,230,2620,2620,7,2637,2637,9,2748,2748,7,2765,2765,9,2876,2876,7,2893,2893,9,3021,3021,9,3132,3132,7,3149,3149,9,3157,3157,84,3158,3158,91,3260,3260,7,3277,3277,9,3387,3388,9,3405,3405,9,7376,7378,230,7380,7380,1,7381,7385,220,7386,7387,230,7388,7391,220,7392,7392,230,7394,7400,1,7405,7405,220,7412,7412,230,7416,7417,230,43232,43249,230,43766,43766,9,44013,44013,9],decomp:{"1570":[1575,1619],"1571":[1575,1620],"1572":[1608,1620],"1573":[1575,1621],"1574":[1610,1620],"1728":[1749,1620],"1730":[1729,1620],"1747":[1746,1620],"2345":[2344,2364],"2353":[2352,2364],"2356":[2355,2364],"2392":[2325,2364],"2393":[2326,2364],"2394":[2327,2364],"2395":[2332,2364],"2396":[2337,2364],"2397":[2338,2364],"2398":[2347,2364],"2399":[2351,2364],"2507":[2503,2494],"2508":[2503,2519],"2524":[2465,2492],"2525":[2466,2492],"2527":[2479,2492],"2611":[2610,2620],"2614":[2616,2620],"2649":[2582,2620],"2650":[2583,2620],"2651":[2588,2620],"2654":[2603,2620],"2888":[2887,2902],"2891":[2887,2878],"2892":[2887,2903],"2908":[2849,2876],"2909":[2850,2876],"2964":[2962,3031],"3018":[3014,3006],"3019":[3015,3006],"3020":[3014,3031],"3144":[3142,3158],"3264":[3263,3285],"3271":[3270,3285],"3272":[3270,3286],"3274":[3270,3266],"3275":[3274,3285],"3402":[3398,3390],"3403":[3399,3390],"3404":[3398,3415]},excl:[2392,2393,2394,2395,2396,2397,2398,2399,2524,2525,2527,2611,2614,2649,2650,2651,2654,2908,2909]};var y2=z.unicode,a2=1,K=2,v=4,W=8,_=new Map,G=new Map,M=new Map;for(let i=0;i<z.ranges.length;i+=2)for(let n=z.ranges[i];n<=z.ranges[i+1];n++)_.set(n,0);var X=(i,n)=>{for(let a=0;a<i.length;a+=2)for(let b=i[a];b<=i[a+1];b++)_.set(b,_.get(b)|n)};X(z.mn,a2);X(z.m,K);X(z.l,v);for(let i=0;i<z.ccc.length;i+=3)for(let n=z.ccc[i];n<=z.ccc[i+1];n++)_.set(n,_.get(n)|z.ccc[i+2]<<4);var o2=new Set(z.excl);for(let[i,n]of Object.entries(z.decomp)){let a=Number(i);if(G.set(a,n),n.length===2&&!o2.has(a))M.set(n[0]*1114112+n[1],a),_.set(n[1],_.get(n[1])|W)}var Y=(i)=>String.fromCodePoint(i);function Q(i,n,a){let b="";for(let o=n;o<a;o+=8192)b+=String.fromCodePoint(...i.slice(o,Math.min(a,o+8192)));return b}function Z(i){let n=_.get(i);return n===void 0?/\p{M}/u.test(Y(i)):(n&K)!==0}function $(i){let n=_.get(i);return n===void 0?/\p{L}/u.test(Y(i)):(n&v)!==0}function q(i){if(!_.has(i))return Array.from(Y(i).normalize("NFD"),(a)=>a.codePointAt(0));let n=G.get(i);return n?n.flatMap(q):[i]}var e2=(i,n)=>i>>4===0&&(i&W)===0&&!G.has(n);function A(i){let n=Array.from(i,(b)=>b.codePointAt(0)),a="";for(let b=0;b<n.length;){let o=b+1,m=_.has(n[b]);for(;o<n.length;o++){let g=_.get(n[o]);if(g===void 0)m=!1;else if(e2(g,n[o]))break}a+=m?m2(n,b,o):Q(n,b,o).normalize("NFC"),b=o}return a}function m2(i,n,a){let b=0,o=!0;for(let s=n;s<a&&o;s++){let h=_.get(i[s]),e=h>>4;if(G.has(i[s])||(h&W)!==0||e!==0&&e<b)o=!1;b=e}if(o)return Q(i,n,a);let m=[];for(let s=n;s<a;s++)m.push(...q(i[s]));let g=(s)=>_.get(s)>>4;for(let s=0;s<m.length;){if(g(m[s])===0){s++;continue}let h=s;while(h<m.length&&g(m[h])!==0)h++;let e=m.slice(s,h).sort((r,w)=>g(r)-g(w));for(let r=0;r<e.length;r++)m[s+r]=e[r];s=h}let d=[],u=-1;for(let s of m){let h=g(s);if(u>=0&&(d.length-1===u||g(d[d.length-1])<h)){let e=M.get(d[u]*1114112+s);if(e!==void 0){d[u]=e;continue}}if(h===0)u=d.length;d.push(s)}return Q(d,0,d.length)}var k=N,G2=k.rules_version;function H2(i="words"){return Object.keys(k.families[i]).sort()}var b2=`https://cdn.jsdelivr.net/gh/micahchoo/indickit@v${C}/romanize/lang/`;async function V(i){let n=await fetch(i);if(!n.ok)throw Error(`romanize: ${i}: ${n.status}`);return n.arrayBuffer()}function r2(i){return async(n)=>{try{return await V(n)}catch{return V(new URL(n.href.slice(i.href.length),b2))}}}function s2(i){let n=D(i);return n==="kok"?"gom":n}var F=new Map;async function Q2(i,n="words",a={}){let b=s2(i),o=k.families[n][b];if(!o)throw Error(`romanize: no ${n} tables for "${i}"`);let m=new URL(a.base??"../romanize/lang/",import.meta.url),g=a.fetch??(a.base?V:r2(m)),d=`${m}${o.group}/${o.pooled}`;if(!F.has(d))F.set(d,g(new URL(`${o.group}/${o.pooled}`,m)));let[u,s]=await Promise.all([g(new URL(`${b}/${o.file}`,m)),F.get(d)]);return d2(b,n,new Uint8Array(u),new Uint8Array(s))}function d2(i,n,a,b){let o=k.families[n][i];if(!o)throw Error(`romanize: no ${n} tables for "${i}"`);let m=new p(a,b,o.tag,k.beam[n]),g=k.groups[o.group],d=(e)=>{let r=e.codePointAt(0);return r===8204||r===8205||g.some(([w,t])=>r>=w&&r<=t)},u=(e)=>{let r=e.codePointAt(0);return r===8204||r===8205||$(r)||Z(r)},s=(e,r=4)=>{let w=x(A(e)),t=[...w];if(t.length>k.max_letters){let l="";for(let y=0;y<t.length;y+=k.max_letters)l+=s(t.slice(y,y+k.max_letters).join(""),1)[0]??"";return l===""?[]:[l]}let I=m.lookup.get(w);if(I)return I.slice(0,r);return m.decode(h2(w),r).filter((l)=>l!=="")},h={lang:i,mode:n,word:s,text(e){let r=[...A(e)],w="";for(let t=0;t<r.length;){let I=r[t].codePointAt(0);if(!(d(r[t])&&($(I)||Z(I)))){w+=r[t++];continue}let l=t;while(l<r.length&&d(r[l])&&u(r[l]))l++;let y=r.slice(t,l).join("");w+=s(y,1)[0]??y,t=l}return w}};return Object.defineProperty(h,"_mix",{value:m}),h}var g2=/[\u200c\u200d]/gu;function x(i){return i.replace(g2,"")}function h2(i){let n=k.unify,a="";for(let b of i){let o=b.codePointAt(0);a+=o>=n.from[0]&&o<=n.from[1]?String.fromCodePoint(n.to_block+(o&n.mask)):b}return a}class J{b;pos=4;constructor(i){this.b=i;if(i[0]!==73||i[1]!==75||i[2]!==82||i[3]!==49)throw Error("romanize: not an IKR1 file")}varint(){let i=0,n=1;for(;;){let a=this.b[this.pos++];if(i+=(a&127)*n,a<128)return i;n*=128}}str(){let i=this.varint(),n=u2.decode(this.b.subarray(this.pos,this.pos+i));return this.pos+=i,n}float64(){let i=new DataView(this.b.buffer,this.b.byteOffset+this.pos,8).getFloat64(0,!0);return this.pos+=8,i}}var u2=new TextDecoder,L=2097152;function H(i,n){let a=0;for(let b=n;b<i.length;b++)a=a*L+(i[b]+1);return a}class B{vocab;levels=[];constructor(i,n,a){this.vocab=i.varint();for(let b=i.varint();b>0;b--){let o={stats:new Map,counts:new Map};for(let m=i.varint();m>0;m--){let g=[];for(let e=i.varint();e>0;e--)g.push(a.id(n[i.varint()]));let d=H(g,0),u=new Map,s=0,h=0;for(let e=i.varint();e>0;e--){h+=i.varint();let r=i.varint();u.set(a.id(n[h]),r),s+=r}o.stats.set(d,[s,u.size]),o.counts.set(d,u)}this.levels.push(o)}}stats(i){let n={counts:[],total:[],wb:[]};for(let a=0;a<this.levels.length;a++){let b=H(i,i.length-a),o=this.levels[a].stats.get(b);if(o&&o[1]!==0)n.counts[a]=this.levels[a].counts.get(b),n.total[a]=o[0],n.wb[a]=o[0]/(o[0]+o[1])}return n}prob(i,n){let a=1/(this.vocab+1);for(let b=0;b<this.levels.length;b++){let o=i.counts[b];if(!o)continue;let m=i.wb[b];a=m*(o.get(n)??0)/i.total[b]+(1-m)*a}return a}}class E{ids=new Map;strs=[];id(i){let n=this.ids.get(i);if(n===void 0)n=this.strs.length,this.ids.set(i,n),this.strs.push(i);return n}}function t2(i){let n=[];for(let a=i;a;a=a.parent)n.push(a.piece);return n.reverse().join("")}function l2(i,n){let a=[i.piece],b=[n.piece],o=i.parent,m=n.parent;while(o!==m)if(m===null||o!==null&&o.at>m.at)a.push(o.piece),o=o.parent;else if(o===null||m.at>o.at)b.push(m.piece),m=m.parent;else a.push(o.piece),o=o.parent,b.push(m.piece),m=m.parent;let g=a.reverse().join(""),d=b.reverse().join("");return g<d?-1:g>d?1:0}function U(i,n){if(i.score!==n.score)return i.score>n.score;let a=l2(i,n);if(a!==0)return a<0;return i.idx<n.idx}class R{k;all;n=0;best=[];constructor(i,n){this.k=i;this.all=n}closed(i){return!this.all&&this.best.length===this.k&&i+0.000000001<this.best[this.k-1].score}add(i,n,a,b){let o=this.n++,m=!this.all&&this.best.length===this.k;if(m&&i<this.best[this.k-1].score)return;let g={score:i,parent:n,piece:a,tok:b,idx:o};if(this.all){this.best.push(g);return}if(m&&!U(g,this.best[this.k-1]))return;let d=0,u=this.best.length;while(d<u){let s=d+u>>1;if(U(g,this.best[s]))u=s;else d=s+1}if(this.best.splice(d,0,g),this.best.length>this.k)this.best.pop()}}class p{beam;a;b;lam;start=[];eos;options=new Map;lookup=new Map;constructor(i,n,a,b){this.beam=b;let o=new E,m=new J(n),g=S(m);this.b=new B(m,g,o),m=new J(i),g=S(m),this.lam=m.float64(),this.a=new B(m,g,o);for(let u=m.varint();u>0;u--){let s=m.str(),h=[];for(let e=m.varint();e>0;e--)h.push(g[m.varint()]);this.lookup.set(s,h)}for(let u=0;u<k.order-2;u++)this.start.push(o.id(k.bos));this.start.push(o.id(`<s:${a}>`)),this.eos=o.id(k.eos);let d=new Set;for(let u of[this.a,this.b])for(let s of u.levels[0].counts.values())for(let h of s.keys()){if(h===this.eos||d.has(h))continue;d.add(h);let e=o.strs[h],r=e.indexOf("|"),w=e.slice(0,r),t=this.options.get(w)??[];t.push({tok:h,en:e.slice(r+1)}),this.options.set(w,t)}for(let u of this.options.values())u.sort((s,h)=>s.en<h.en?-1:s.en>h.en?1:0);if(this.start.length>2||o.strs.length>=L)throw Error("romanize: beyond the engine's limits")}logp(i,n,a){let b=Math.exp(Math.log(this.a.prob(i,a))),o=Math.exp(Math.log(this.b.prob(n,a)));return Math.log(this.lam*b+(1-this.lam)*o)}decode(i,n){let a=[...x(i)],b=k.order-1,o={score:0,parent:null,piece:"",at:0,ctx:this.start},m=Array.from({length:a.length+1},(e,r)=>new R(this.beam,r===a.length));m[0].add(0,null,"",-1);let g=(e)=>{if(e.tok<0)return e.parent.ctx;let r=[...e.parent.ctx,e.tok];return r.slice(r.length-b)},d=Array(k.max_n+1);for(let e=0;e<a.length;e++){let r=new Map;for(let w of m[e].best){let t=!1,I=!1;for(let f=1;f<=k.max_n&&e+f<=a.length;f++)if(d[f]=this.options.get(a.slice(e,e+f).join("")),d[f]?.length)t=!0,I||=!m[e+f].closed(w.score);if(t&&!I){for(let f=1;f<=k.max_n&&e+f<=a.length;f++)m[e+f].n+=d[f]?.length??0;continue}let l=e===0?o:{score:w.score,parent:w.parent,piece:w.piece,at:e,ctx:g(w)};if(!t){m[e+1].add(l.score-k.unknown_penalty,l,"",-1);continue}let y=H(l.ctx,0),j=r.get(y);if(!j)j={sa:this.a.stats(l.ctx),sb:this.b.stats(l.ctx),lp:[]},r.set(y,j);for(let f=1;f<=k.max_n&&e+f<=a.length;f++){let O=d[f];if(!O)continue;if(m[e+f].closed(l.score)){m[e+f].n+=O.length;continue}let P=j.lp[f];if(!P)P=O.map((T)=>this.logp(j.sa,j.sb,T.tok)),j.lp[f]=P;for(let T=0;T<O.length;T++)m[e+f].add(l.score+P[T],l,O[T].en,O[T].tok)}}}let u=new Map,s=new Map,h=new Map;for(let e of m[a.length].best){let r=e.parent===null?this.start:g(e),w=H(r,0),t=s.get(w);if(t===void 0)t=this.logp(this.a.stats(r),this.b.stats(r),this.eos),s.set(w,t);let I=e.score+t,l=e.piece;if(e.parent!==null){let j=h.get(e.parent);if(j===void 0)j=t2(e.parent),h.set(e.parent,j);l=j+e.piece}let y=u.get(l);if(y===void 0||I>y)u.set(l,I)}return[...u].sort((e,r)=>e[1]!==r[1]?r[1]-e[1]:e[0]<r[0]?-1:e[0]>r[0]?1:0).slice(0,n).map((e)=>e[0])}}function S(i){let n=[];for(let a=i.varint();a>0;a--)n.push(i.str());return n}function W2(i,n,a){return i._mix.decode(n,a)}export{h2 as unify,Q2 as load,H2 as languages,d2 as fromBytes,W2 as _decode,G2 as RULES_VERSION,b2 as CDN};
|