jsmigemo 0.4.3 → 0.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 +13 -0
- package/bin/jsmigemo-cli.mjs +13 -13
- package/dist/jsmigemo.cjs +142 -126
- package/dist/jsmigemo.d.ts +25 -18
- package/dist/jsmigemo.js +142 -126
- package/dist/jsmigemo.min.cjs +1 -1
- package/dist/jsmigemo.min.js +1 -1
- package/dist/jsmigemo.min.mjs +1 -1
- package/dist/jsmigemo.mjs +140 -123
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -56,6 +56,19 @@ console.log(m.query('kensaku'));
|
|
|
56
56
|
//=> (kensaku|けんさく|ケンサク|建策|憲[作冊]|検索|献策|研削|羂索|kensaku|ケンサク)
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
### Deno
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import * as migemo from "https://cdn.jsdelivr.net/npm/jsmigemo/dist/jsmigemo.min.mjs";
|
|
63
|
+
|
|
64
|
+
const data = await Deno.readFile("./migemo-compact-dict");
|
|
65
|
+
const dict = new migemo.CompactDictionary(data.buffer);
|
|
66
|
+
const m = new migemo.Migemo();
|
|
67
|
+
m.setDict(dict);
|
|
68
|
+
console.log(m.query("kensaku"));
|
|
69
|
+
//=> (kensaku|けんさく|ケンサク|建策|憲[作冊]|検索|献策|研削|羂索|kensaku|ケンサク)
|
|
70
|
+
```
|
|
71
|
+
|
|
59
72
|
### Browser
|
|
60
73
|
|
|
61
74
|
`jsmigemo.js` と `migemo-compact-dict` を本リポジトリから用意します。
|
package/bin/jsmigemo-cli.mjs
CHANGED
|
@@ -9,18 +9,18 @@ import readline from 'readline';
|
|
|
9
9
|
|
|
10
10
|
function help(prgname) {
|
|
11
11
|
const MIGEMO_ABOUT = "jsmigemo - Js/Migemo Library";
|
|
12
|
-
console.log(
|
|
13
|
-
\n
|
|
14
|
-
USAGE:
|
|
15
|
-
\n
|
|
16
|
-
OPTIONS:\n
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
console.log(MIGEMO_ABOUT + "\n" +
|
|
13
|
+
"\n" +
|
|
14
|
+
"USAGE: " + prgname + " [OPTIONS]\n" +
|
|
15
|
+
"\n" +
|
|
16
|
+
"OPTIONS:\n" +
|
|
17
|
+
" -d --dict <dict> Use a file <dict> for dictionary.\n" +
|
|
18
|
+
" -q --quiet Show no message except results.\n" +
|
|
19
|
+
" -v --vim Use vim style regexp.\n" +
|
|
20
|
+
" -e --emacs Use emacs style regexp.\n" +
|
|
21
|
+
" -n --nonewline Don't use newline match.\n" +
|
|
22
|
+
" -w --word <word> Expand a <word> and soon exit.\n" +
|
|
23
|
+
" -h --help Show this message.")
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
let mode_vim = false;
|
|
@@ -72,7 +72,7 @@ for (let i = 2; i < process.argv.length; i++) {
|
|
|
72
72
|
}
|
|
73
73
|
if (mode_help) {
|
|
74
74
|
help(prgname);
|
|
75
|
-
exit(0);
|
|
75
|
+
process.exit(0);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
const buffer = fs.readFileSync(file);
|
package/dist/jsmigemo.cjs
CHANGED
|
@@ -1339,19 +1339,20 @@ class TernaryRegexGenerator {
|
|
|
1339
1339
|
}
|
|
1340
1340
|
}
|
|
1341
1341
|
|
|
1342
|
-
|
|
1342
|
+
class RomajiPredictiveResult {
|
|
1343
1343
|
constructor(prefix, suffixes) {
|
|
1344
1344
|
this.prefix = prefix;
|
|
1345
1345
|
this.suffixes = suffixes;
|
|
1346
1346
|
}
|
|
1347
|
-
}
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1348
1349
|
class RomajiProcessor2 {
|
|
1349
1350
|
constructor(trie, hiraganaList, remainList) {
|
|
1350
1351
|
this.trie = trie;
|
|
1351
1352
|
this.hiraganaList = hiraganaList;
|
|
1352
1353
|
this.remainList = remainList;
|
|
1353
1354
|
}
|
|
1354
|
-
static
|
|
1355
|
+
static build() {
|
|
1355
1356
|
const base = new Int16Array([0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 31, 95, -1, 100, 121, 147, -1, 175, 182, 203, 229, 251, -1, 266, 284, 291, 302, 334, -1, 379, 401, 420, 432, 464, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 50, 49, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 28, -1, -1, -1, -1, 52, -1, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 67, -1, -1, -1, -1, -1, -1, -1, 34, -1, -1, -1, -1, -1, -1, 76, -1, 93, -1, -1, -1, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 118, -1, 136, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 149, -1, 158, -1, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 160, -1, -1, -1, -1, 177, -1, 201, -1, -1, -1, -1, -1, -1, 61, -1, -1, -1, -1, -1, -1, -1, -1, 44, -1, -1, 47, -1, 212, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 230, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 248, 86, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 269, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 317, -1, -1, -1, -1, -1, 293, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 319, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 343, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 360, -1, -1, -1, 361, -1, 362, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 384, -1, -1, -1, -1, 402, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, -1, 74, -1, -1, -1, -1, 85, -1, -1, -1, -1, -1, -1, -1, -1, 68, -1, -1, 83, -1, 427, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 445, -1]);
|
|
1356
1357
|
const check = new Int16Array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 98, 147, 0, 98, 99, 147, 99, 98, 99, 147, 100, 99, 99, 98, 171, 147, 270, 159, 99, 98, 322, 147, 135, 98, 99, 152, 135, 207, 99, 152, 135, 134, 221, 152, 310, 319, 135, 319, 310, 152, 199, 520, 135, 134, 199, 152, 221, 134, 199, 214, 183, 522, 221, 214, 199, 522, 539, 214, 527, 536, 199, 536, 527, 214, -1, -1, 216, 373, 100, 214, 216, 100, 100, 102, 216, 100, 100, 102, 102, 373, 216, 102, 100, 373, -1, -1, 216, 102, 100, -1, 100, 240, 100, 102, 103, 240, -1, 102, 103, 240, 103, -1, 103, -1, -1, 240, -1, -1, 103, 242, -1, 240, -1, 242, 103, -1, 103, 242, 103, -1, 104, -1, 266, 242, 104, -1, 266, 104, 104, 242, 266, 268, -1, 296, 104, 268, 266, 296, -1, 268, 104, 296, 104, -1, 104, 268, 266, 296, 106, -1, 301, 268, 106, 296, 301, 107, 106, 106, 301, 107, -1, -1, 106, 107, 301, 107, 110, -1, 106, 107, 301, -1, 106, -1, 303, 107, 108, 107, 303, 107, 108, -1, 303, -1, 108, 324, 108, 108, 303, 324, 108, -1, -1, 324, 303, 108, 108, -1, 108, 324, 108, -1, 109, 350, -1, 324, 109, 350, -1, -1, 109, 350, -1, -1, 109, -1, 109, 350, -1, -1, -1, 372, 109, 350, 110, 372, 109, -1, 110, 372, -1, -1, 110, -1, -1, 372, -1, 110, 110, 112, -1, 372, 387, 112, 110, -1, 387, 112, 110, 116, 387, -1, -1, 112, 112, -1, 387, 113, -1, 112, -1, 113, 387, 112, 114, 113, 412, -1, 114, -1, 412, 113, 114, 113, 412, 115, -1, 113, 114, 115, 412, 114, 115, 115, 114, -1, 412, -1, 114, 115, 406, -1, 423, 115, 406, 115, 423, -1, 406, 115, 423, -1, -1, -1, 406, -1, 423, 116, -1, -1, 406, 116, 423, -1, 116, 116, 438, -1, -1, -1, 438, 116, -1, -1, 438, 116, 116, 116, -1, 116, 438, 116, -1, 449, 453, 455, 438, 449, 453, 455, -1, 449, 453, 455, -1, -1, -1, 449, 453, 455, -1, -1, 118, 449, 453, 455, 118, 500, -1, -1, 118, 500, -1, -1, -1, 500, 118, -1, -1, -1, -1, 500, 118, 118, 119, 505, 118, 500, 119, 505, -1, 119, 119, 505, 122, 122, 122, 122, 119, 505, -1, -1, -1, 120, 119, 505, 119, 120, 119, -1, 541, 120, -1, 120, 541, 121, 120, 120, 541, 121, -1, -1, 120, 120, 541, 120, 120, 120, 585, 121, 541, -1, 585, -1, -1, 121, 585, -1, -1, 121, -1, 122, 585, 122, -1, -1, -1, 122, 585, -1, -1, 122, -1, -1, 122, 122, 122, 122, 122, -1, -1, 122, -1, -1, -1, -1, -1, 122, -1, -1, -1, 122, 122]);
|
|
1357
1358
|
const remainList = new Int8Array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, -1, -1, 0, -1, -1, -1, 0, -1, -1, -1, 0, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, -1, -1, 0, -1, 0, 0, 0, -1, -1, 0, 0, 1, -1, 0, -1, -1, 0, -1, -1, 0, 0, -1, 0, -1, 0, 0, -1, -1, 0, -1, -1, 0, -1, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, -1, -1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, -1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 1, 0, 0, 0, -1, -1, 0, 0, -1, 0, -1, -1, 0, -1, -1, 0, 0, -1, 0, 0, 0, -1, -1, 0, 0, -1, -1, 1, -1, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, -1, 0, -1, -1, 0, -1, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, -1, -1, 0, -1, -1, 0, 1, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 1, -1, 0, 0, -1, 0, -1, -1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, -1, 0, -1, -1, -1, 0, -1, 0, 0, -1, -1, 0, 0, 0, -1, -1, 0, 0, -1, -1, -1, 0, 0, -1, -1, 0, -1, 1, 0, -1, -1, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, -1, -1, 0, 0, -1, -1, -1, -1, 0, 0, 1, 0, 0, -1, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 1, 0, -1, -1, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, -1, 1, -1, 0, 0, 0, -1, 0, -1, -1, 0, 0, -1, -1, 1, -1, 0, 0, 0, -1, -1, -1, 0, 0, -1, -1, 0, -1, -1, 0, 0, 0, 0, 0, -1, -1, 0, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, 1]);
|
|
@@ -1410,10 +1411,10 @@ class RomajiProcessor2 {
|
|
|
1410
1411
|
}
|
|
1411
1412
|
if (list.length == 1) {
|
|
1412
1413
|
builder = builder + list[0];
|
|
1413
|
-
return new RomajiPredictiveResult
|
|
1414
|
+
return new RomajiPredictiveResult(builder, [""]);
|
|
1414
1415
|
}
|
|
1415
1416
|
else {
|
|
1416
|
-
return new RomajiPredictiveResult
|
|
1417
|
+
return new RomajiPredictiveResult(builder, list);
|
|
1417
1418
|
}
|
|
1418
1419
|
}
|
|
1419
1420
|
else if (longestNode >= 0) {
|
|
@@ -1425,7 +1426,7 @@ class RomajiProcessor2 {
|
|
|
1425
1426
|
cursor++;
|
|
1426
1427
|
}
|
|
1427
1428
|
}
|
|
1428
|
-
return new RomajiPredictiveResult
|
|
1429
|
+
return new RomajiPredictiveResult(builder, [""]);
|
|
1429
1430
|
}
|
|
1430
1431
|
}
|
|
1431
1432
|
|
|
@@ -1433,7 +1434,7 @@ class Migemo {
|
|
|
1433
1434
|
constructor() {
|
|
1434
1435
|
this.dict = null;
|
|
1435
1436
|
this.rxop = null;
|
|
1436
|
-
this.processor = RomajiProcessor2.
|
|
1437
|
+
this.processor = RomajiProcessor2.build();
|
|
1437
1438
|
}
|
|
1438
1439
|
queryAWord(word) {
|
|
1439
1440
|
const generator = this.rxop == null ? TernaryRegexGenerator.getDEFAULT() : new TernaryRegexGenerator(this.rxop[0], this.rxop[1], this.rxop[2], this.rxop[3], this.rxop[4], this.rxop[5]);
|
|
@@ -1488,6 +1489,9 @@ class Migemo {
|
|
|
1488
1489
|
setRxop(rxop) {
|
|
1489
1490
|
this.rxop = rxop;
|
|
1490
1491
|
}
|
|
1492
|
+
setRomajiProcessor(processor) {
|
|
1493
|
+
this.processor = processor;
|
|
1494
|
+
}
|
|
1491
1495
|
*parseQuery(query) {
|
|
1492
1496
|
const re = /[^A-Z\s]+|[A-Z]{2,}|([A-Z][^A-Z\s]+)|([A-Z]\s*$)/g;
|
|
1493
1497
|
let myArray;
|
|
@@ -1835,140 +1839,153 @@ const ROMAN_ENTRIES = [
|
|
|
1835
1839
|
new RomanEntry("who", "うぉ", 0)
|
|
1836
1840
|
]
|
|
1837
1841
|
.sort((a, b) => a.index - b.index);
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
this.
|
|
1842
|
-
this.
|
|
1842
|
+
class RomajiProcessor1 {
|
|
1843
|
+
constructor(entries) {
|
|
1844
|
+
this.roman_indexes = [];
|
|
1845
|
+
this.roman_entries = [];
|
|
1846
|
+
this.roman_entries = entries.sort((a, b) => a.index - b.index);
|
|
1847
|
+
this.roman_indexes = this.roman_entries.map(e => e.index);
|
|
1843
1848
|
}
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
let
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1849
|
+
static build() {
|
|
1850
|
+
return new RomajiProcessor1(ROMAN_ENTRIES);
|
|
1851
|
+
}
|
|
1852
|
+
romajiToHiragana(romaji) {
|
|
1853
|
+
if (romaji.length == 0) {
|
|
1854
|
+
return "";
|
|
1855
|
+
}
|
|
1856
|
+
let hiragana = "";
|
|
1857
|
+
let start = 0;
|
|
1858
|
+
let end = 1;
|
|
1859
|
+
while (start < romaji.length) {
|
|
1860
|
+
let lastFound = -1;
|
|
1861
|
+
let lower = 0;
|
|
1862
|
+
let upper = this.roman_indexes.length;
|
|
1863
|
+
while (upper - lower > 1 && end <= romaji.length) {
|
|
1864
|
+
const lowerKey = RomanEntry._calculateIndex(romaji, start, end);
|
|
1865
|
+
lower = binarySearch(this.roman_indexes, lower, upper, lowerKey);
|
|
1866
|
+
if (lower >= 0) {
|
|
1867
|
+
lastFound = lower;
|
|
1868
|
+
}
|
|
1869
|
+
else {
|
|
1870
|
+
lower = -lower - 1;
|
|
1871
|
+
}
|
|
1872
|
+
const upperKey = lowerKey + (1 << (32 - 8 * (end - start)));
|
|
1873
|
+
upper = binarySearch(this.roman_indexes, lower, upper, upperKey);
|
|
1874
|
+
if (upper < 0) {
|
|
1875
|
+
upper = -upper - 1;
|
|
1876
|
+
}
|
|
1877
|
+
end++;
|
|
1861
1878
|
}
|
|
1862
|
-
|
|
1863
|
-
|
|
1879
|
+
if (lastFound >= 0) {
|
|
1880
|
+
const entry = this.roman_entries[lastFound];
|
|
1881
|
+
hiragana = hiragana + entry.hiragana;
|
|
1882
|
+
start = start + entry.roman.length - entry.remain;
|
|
1883
|
+
end = start + 1;
|
|
1864
1884
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1885
|
+
else {
|
|
1886
|
+
hiragana = hiragana + romaji.charAt(start);
|
|
1887
|
+
start++;
|
|
1888
|
+
end = start + 1;
|
|
1869
1889
|
}
|
|
1870
|
-
end++;
|
|
1871
|
-
}
|
|
1872
|
-
if (lastFound >= 0) {
|
|
1873
|
-
const entry = ROMAN_ENTRIES[lastFound];
|
|
1874
|
-
hiragana = hiragana + entry.hiragana;
|
|
1875
|
-
start = start + entry.roman.length - entry.remain;
|
|
1876
|
-
end = start + 1;
|
|
1877
|
-
}
|
|
1878
|
-
else {
|
|
1879
|
-
hiragana = hiragana + romaji.charAt(start);
|
|
1880
|
-
start++;
|
|
1881
|
-
end = start + 1;
|
|
1882
1890
|
}
|
|
1891
|
+
return hiragana;
|
|
1883
1892
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
if (roman.length <= offset + i) {
|
|
1891
|
-
break;
|
|
1892
|
-
}
|
|
1893
|
-
const startKey = RomanEntry._calculateIndex(roman, offset, offset + i + 1);
|
|
1894
|
-
startIndex = binarySearch(ROMAN_INDEXES, startIndex, endIndex, startKey);
|
|
1895
|
-
if (startIndex >= 0) ;
|
|
1896
|
-
else {
|
|
1897
|
-
startIndex = -startIndex - 1;
|
|
1898
|
-
}
|
|
1899
|
-
const endKey = startKey + (1 << (24 - 8 * i));
|
|
1900
|
-
endIndex = binarySearch(ROMAN_INDEXES, startIndex, endIndex, endKey);
|
|
1901
|
-
if (endIndex < 0) {
|
|
1902
|
-
endIndex = -endIndex - 1;
|
|
1903
|
-
}
|
|
1904
|
-
if (endIndex - startIndex == 1) {
|
|
1905
|
-
return new Set([ROMAN_ENTRIES[startIndex]]);
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
const result = new Set();
|
|
1909
|
-
for (let i = startIndex; i < endIndex; i++) {
|
|
1910
|
-
result.add(ROMAN_ENTRIES[i]);
|
|
1911
|
-
}
|
|
1912
|
-
return result;
|
|
1913
|
-
}
|
|
1914
|
-
function romajiToHiraganaPredictively(romaji) {
|
|
1915
|
-
if (romaji.length == 0) {
|
|
1916
|
-
return new RomajiPredictiveResult("", new Set([""]));
|
|
1917
|
-
}
|
|
1918
|
-
let hiragana = "";
|
|
1919
|
-
let start = 0;
|
|
1920
|
-
let end = 1;
|
|
1921
|
-
while (start < romaji.length) {
|
|
1922
|
-
let lastFound = -1;
|
|
1923
|
-
let lower = 0;
|
|
1924
|
-
let upper = ROMAN_INDEXES.length;
|
|
1925
|
-
while (upper - lower > 1 && end <= romaji.length) {
|
|
1926
|
-
const lowerKey = RomanEntry._calculateIndex(romaji, start, end);
|
|
1927
|
-
lower = binarySearch(ROMAN_INDEXES, lower, upper, lowerKey);
|
|
1928
|
-
if (lower >= 0) {
|
|
1929
|
-
lastFound = lower;
|
|
1893
|
+
findRomanEntryPredicatively(roman, offset) {
|
|
1894
|
+
let startIndex = 0;
|
|
1895
|
+
let endIndex = this.roman_indexes.length;
|
|
1896
|
+
for (let i = 0; i < 4; i++) {
|
|
1897
|
+
if (roman.length <= offset + i) {
|
|
1898
|
+
break;
|
|
1930
1899
|
}
|
|
1900
|
+
const startKey = RomanEntry._calculateIndex(roman, offset, offset + i + 1);
|
|
1901
|
+
startIndex = binarySearch(this.roman_indexes, startIndex, endIndex, startKey);
|
|
1902
|
+
if (startIndex >= 0) ;
|
|
1931
1903
|
else {
|
|
1932
|
-
|
|
1904
|
+
startIndex = -startIndex - 1;
|
|
1933
1905
|
}
|
|
1934
|
-
const
|
|
1935
|
-
|
|
1936
|
-
if (
|
|
1937
|
-
|
|
1906
|
+
const endKey = startKey + (1 << (24 - 8 * i));
|
|
1907
|
+
endIndex = binarySearch(this.roman_indexes, startIndex, endIndex, endKey);
|
|
1908
|
+
if (endIndex < 0) {
|
|
1909
|
+
endIndex = -endIndex - 1;
|
|
1910
|
+
}
|
|
1911
|
+
if (endIndex - startIndex == 1) {
|
|
1912
|
+
return new Set([this.roman_entries[startIndex]]);
|
|
1938
1913
|
}
|
|
1939
|
-
end++;
|
|
1940
1914
|
}
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1915
|
+
const result = new Set();
|
|
1916
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
1917
|
+
result.add(this.roman_entries[i]);
|
|
1918
|
+
}
|
|
1919
|
+
return result;
|
|
1920
|
+
}
|
|
1921
|
+
romajiToHiraganaPredictively(romaji) {
|
|
1922
|
+
if (romaji.length == 0) {
|
|
1923
|
+
return new RomajiPredictiveResult("", [""]);
|
|
1924
|
+
}
|
|
1925
|
+
let hiragana = "";
|
|
1926
|
+
let start = 0;
|
|
1927
|
+
let end = 1;
|
|
1928
|
+
while (start < romaji.length) {
|
|
1929
|
+
let lastFound = -1;
|
|
1930
|
+
let lower = 0;
|
|
1931
|
+
let upper = this.roman_indexes.length;
|
|
1932
|
+
while (upper - lower > 1 && end <= romaji.length) {
|
|
1933
|
+
const lowerKey = RomanEntry._calculateIndex(romaji, start, end);
|
|
1934
|
+
lower = binarySearch(this.roman_indexes, lower, upper, lowerKey);
|
|
1935
|
+
if (lower >= 0) {
|
|
1936
|
+
lastFound = lower;
|
|
1937
|
+
}
|
|
1938
|
+
else {
|
|
1939
|
+
lower = -lower - 1;
|
|
1940
|
+
}
|
|
1941
|
+
const upperKey = lowerKey + (1 << (32 - 8 * (end - start)));
|
|
1942
|
+
upper = binarySearch(this.roman_indexes, lower, upper, upperKey);
|
|
1943
|
+
if (upper < 0) {
|
|
1944
|
+
upper = -upper - 1;
|
|
1945
|
+
}
|
|
1946
|
+
end++;
|
|
1947
|
+
}
|
|
1948
|
+
if (end > romaji.length && upper - lower > 1) {
|
|
1949
|
+
const set = new Set();
|
|
1950
|
+
for (let i = lower; i < upper; i++) {
|
|
1951
|
+
const re = this.roman_entries[i];
|
|
1952
|
+
if (re.remain > 0) {
|
|
1953
|
+
let set2 = this.findRomanEntryPredicatively(romaji, end - 1 - re.remain);
|
|
1954
|
+
for (let re2 of set2) {
|
|
1955
|
+
if (re2.remain == 0) {
|
|
1956
|
+
set.add(re.hiragana + re2.hiragana);
|
|
1957
|
+
}
|
|
1950
1958
|
}
|
|
1951
1959
|
}
|
|
1960
|
+
else {
|
|
1961
|
+
set.add(re.hiragana);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
let list = new Array();
|
|
1965
|
+
for (let e of set) {
|
|
1966
|
+
list.push(e);
|
|
1967
|
+
}
|
|
1968
|
+
if (list.length == 1) {
|
|
1969
|
+
return new RomajiPredictiveResult(hiragana + list[0], [""]);
|
|
1952
1970
|
}
|
|
1953
1971
|
else {
|
|
1954
|
-
|
|
1972
|
+
return new RomajiPredictiveResult(hiragana, list);
|
|
1955
1973
|
}
|
|
1956
1974
|
}
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
end = start + 1;
|
|
1975
|
+
if (lastFound >= 0) {
|
|
1976
|
+
const entry = this.roman_entries[lastFound];
|
|
1977
|
+
hiragana = hiragana + entry.hiragana;
|
|
1978
|
+
start = start + entry.roman.length - entry.remain;
|
|
1979
|
+
end = start + 1;
|
|
1980
|
+
}
|
|
1981
|
+
else {
|
|
1982
|
+
hiragana = hiragana + romaji.charAt(start);
|
|
1983
|
+
start++;
|
|
1984
|
+
end = start + 1;
|
|
1985
|
+
}
|
|
1969
1986
|
}
|
|
1987
|
+
return new RomajiPredictiveResult(hiragana, [""]);
|
|
1970
1988
|
}
|
|
1971
|
-
return new RomajiPredictiveResult(hiragana.toString(), new Set([""]));
|
|
1972
1989
|
}
|
|
1973
1990
|
|
|
1974
1991
|
exports.BitList = BitList;
|
|
@@ -1980,17 +1997,16 @@ exports.DoubleArray = DoubleArray;
|
|
|
1980
1997
|
exports.LOUDSTrie = LOUDSTrie;
|
|
1981
1998
|
exports.LOUDSTrieBuilder = LOUDSTrieBuilder;
|
|
1982
1999
|
exports.Migemo = Migemo;
|
|
1983
|
-
exports.RomajiPredictiveResult = RomajiPredictiveResult
|
|
2000
|
+
exports.RomajiPredictiveResult = RomajiPredictiveResult;
|
|
2001
|
+
exports.RomajiProcessor1 = RomajiProcessor1;
|
|
1984
2002
|
exports.RomajiProcessor2 = RomajiProcessor2;
|
|
2003
|
+
exports.RomanEntry = RomanEntry;
|
|
1985
2004
|
exports.TernaryRegexGenerator = TernaryRegexGenerator;
|
|
1986
2005
|
exports.binarySearch = binarySearch;
|
|
1987
2006
|
exports.binarySearchString = binarySearchString;
|
|
1988
2007
|
exports.binarySearchUint16 = binarySearchUint16;
|
|
1989
2008
|
exports.bitCount = bitCount;
|
|
1990
|
-
exports.findRomanEntryPredicatively = findRomanEntryPredicatively;
|
|
1991
2009
|
exports.han2zen_conv = han2zen_conv;
|
|
1992
2010
|
exports.hira2kata_conv = hira2kata_conv;
|
|
1993
2011
|
exports.numberOfTrailingZeros = numberOfTrailingZeros;
|
|
1994
|
-
exports.romajiToHiragana = romajiToHiragana;
|
|
1995
|
-
exports.romajiToHiraganaPredictively = romajiToHiraganaPredictively;
|
|
1996
2012
|
exports.zen2han_conv = zen2han_conv;
|
package/dist/jsmigemo.d.ts
CHANGED
|
@@ -83,30 +83,26 @@ declare class LOUDSTrieBuilder {
|
|
|
83
83
|
static build(keys: string[]): [LOUDSTrie, Uint32Array];
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
declare class RomajiPredictiveResult
|
|
86
|
+
declare class RomajiPredictiveResult {
|
|
87
87
|
prefix: string;
|
|
88
88
|
suffixes: string[];
|
|
89
89
|
constructor(prefix: string, suffixes: string[]);
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
trie: DoubleArray;
|
|
93
|
-
hiraganaList: Array<string>;
|
|
94
|
-
remainList: Int8Array;
|
|
95
|
-
constructor(trie: DoubleArray, hiraganaList: string[], remainList: Int8Array);
|
|
96
|
-
static buildProcessor(): RomajiProcessor2;
|
|
91
|
+
interface RomajiProcessor {
|
|
97
92
|
romajiToHiragana(romaji: string): string;
|
|
98
|
-
romajiToHiraganaPredictively(romaji: string): RomajiPredictiveResult
|
|
93
|
+
romajiToHiraganaPredictively(romaji: string): RomajiPredictiveResult;
|
|
99
94
|
}
|
|
100
95
|
|
|
101
96
|
declare class Migemo {
|
|
102
97
|
dict: CompactDictionary | null;
|
|
103
98
|
rxop: Array<string> | null;
|
|
104
|
-
processor:
|
|
99
|
+
processor: RomajiProcessor;
|
|
105
100
|
constructor();
|
|
106
101
|
queryAWord(word: string): string;
|
|
107
102
|
query(word: string): string;
|
|
108
103
|
setDict(dict: CompactDictionary | null): void;
|
|
109
104
|
setRxop(rxop: [string] | null): void;
|
|
105
|
+
setRomajiProcessor(processor: RomajiProcessor): void;
|
|
110
106
|
parseQuery(query: string): IterableIterator<string>;
|
|
111
107
|
}
|
|
112
108
|
|
|
@@ -119,14 +115,25 @@ declare class RomanEntry {
|
|
|
119
115
|
static _calculateIndex(roman: string, start: number, end: number): number;
|
|
120
116
|
static calculateIndex(roman: string): number;
|
|
121
117
|
}
|
|
122
|
-
declare class
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
constructor(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
declare class RomajiProcessor1 implements RomajiProcessor {
|
|
119
|
+
private roman_indexes;
|
|
120
|
+
private roman_entries;
|
|
121
|
+
constructor(entries: RomanEntry[]);
|
|
122
|
+
static build(): RomajiProcessor1;
|
|
123
|
+
romajiToHiragana(romaji: string): string;
|
|
124
|
+
findRomanEntryPredicatively(roman: string, offset: number): Set<RomanEntry>;
|
|
125
|
+
romajiToHiraganaPredictively(romaji: string): RomajiPredictiveResult;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
declare class RomajiProcessor2 implements RomajiProcessor {
|
|
129
|
+
trie: DoubleArray;
|
|
130
|
+
hiraganaList: Array<string>;
|
|
131
|
+
remainList: Int8Array;
|
|
132
|
+
constructor(trie: DoubleArray, hiraganaList: string[], remainList: Int8Array);
|
|
133
|
+
static build(): RomajiProcessor2;
|
|
134
|
+
romajiToHiragana(romaji: string): string;
|
|
135
|
+
romajiToHiraganaPredictively(romaji: string): RomajiPredictiveResult;
|
|
136
|
+
}
|
|
130
137
|
|
|
131
138
|
declare class TernaryRegexNode {
|
|
132
139
|
value: number;
|
|
@@ -160,4 +167,4 @@ declare function binarySearchString(a: string[], fromIndex: number, toIndex: num
|
|
|
160
167
|
declare function bitCount(i: number): number;
|
|
161
168
|
declare function numberOfTrailingZeros(i: number): number;
|
|
162
169
|
|
|
163
|
-
export { BitList, BitVector, CompactDictionary, CompactDictionaryBuilder, CompactHiraganaString, DoubleArray, LOUDSTrie, LOUDSTrieBuilder, Migemo, RomajiPredictiveResult
|
|
170
|
+
export { BitList, BitVector, CompactDictionary, CompactDictionaryBuilder, CompactHiraganaString, DoubleArray, LOUDSTrie, LOUDSTrieBuilder, Migemo, RomajiPredictiveResult, RomajiProcessor, RomajiProcessor1, RomajiProcessor2, RomanEntry, TernaryRegexGenerator, binarySearch, binarySearchString, binarySearchUint16, bitCount, han2zen_conv, hira2kata_conv, numberOfTrailingZeros, zen2han_conv };
|