jsmigemo 0.4.2 → 0.4.4
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 +40 -2
- package/bin/jsmigemo-cli.mjs +0 -0
- package/dist/jsmigemo.cjs +152 -141
- package/dist/jsmigemo.d.ts +25 -18
- package/dist/jsmigemo.js +152 -141
- package/dist/jsmigemo.min.cjs +1 -2
- package/dist/jsmigemo.min.js +1 -2
- package/dist/jsmigemo.min.mjs +1 -2
- package/dist/jsmigemo.mjs +150 -136
- package/package.json +12 -10
- package/a.txt +0 -1794
- package/dist/jsmigemo.cjs.map +0 -1
- package/dist/jsmigemo.js.map +0 -1
- package/dist/jsmigemo.min.cjs.map +0 -1
- package/dist/jsmigemo.min.js.map +0 -1
- package/dist/jsmigemo.min.mjs.map +0 -1
- package/dist/jsmigemo.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -5,6 +5,31 @@
|
|
|
5
5
|
|
|
6
6
|
JavaScriptでMigemoを利用するためのライブラリ
|
|
7
7
|
|
|
8
|
+
## Install from npm
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
$ npm install jsmigemo
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Install from CDN
|
|
15
|
+
|
|
16
|
+
`https://cdn.jsdelivr.net/npm/jsmigemo/dist/<filename>` の `<filename>` の部分に、用途に応じて以下のファイル名を指定してください。
|
|
17
|
+
|
|
18
|
+
| Format | Default | Minified |
|
|
19
|
+
|:------:|---------|----------|
|
|
20
|
+
| ESModule | jsmigemo.mjs | jsmigemo.min.mjs |
|
|
21
|
+
| CommonJS | jsmigemo.cjs | jsmigemo.min.cjs |
|
|
22
|
+
| IIFE | jsmigemo.js | jsmigemo.min.js |
|
|
23
|
+
|
|
24
|
+
DefaultとMinifiedの違いは以下です。
|
|
25
|
+
- Defaultは、ソースコードを1つにまとめただけの、変数名もそのまま残っているJSファイルです。開発時にはこちらをご利用ください。
|
|
26
|
+
- Minifiedは、ファイルサイズを小さくするための様々な処理をしたJSファイルです。配布時にはこちらをご利用ください。
|
|
27
|
+
|
|
28
|
+
ESModuleとCommonJS、IIFEの違いは以下です。
|
|
29
|
+
- ESModuleは、最近のバンドラやNode.JS、モダンブラウザなど幅広く利用できるフォーマットです。
|
|
30
|
+
- CommonJSは、browserifyやwebpack1のような古いバンドラでの利用を意図したフォーマットです。
|
|
31
|
+
- IIFEは、レガシーブラウザやESModuleの利用できない環境(例えばローカルのJSファイル)での利用を意図したフォーマットです。
|
|
32
|
+
|
|
8
33
|
## HOW TO USE
|
|
9
34
|
|
|
10
35
|
### CLI
|
|
@@ -23,7 +48,7 @@ const migemo = require('jsmigemo');
|
|
|
23
48
|
const path = require('path');
|
|
24
49
|
const fs = require('fs');
|
|
25
50
|
|
|
26
|
-
const buffer = fs.readFileSync(
|
|
51
|
+
const buffer = fs.readFileSync('migemo-compact-dict');
|
|
27
52
|
const dict = new migemo.CompactDictionary(buffer.buffer);
|
|
28
53
|
const m = new migemo.Migemo();
|
|
29
54
|
m.setDict(dict);
|
|
@@ -31,6 +56,19 @@ console.log(m.query('kensaku'));
|
|
|
31
56
|
//=> (kensaku|けんさく|ケンサク|建策|憲[作冊]|検索|献策|研削|羂索|kensaku|ケンサク)
|
|
32
57
|
```
|
|
33
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
|
+
|
|
34
72
|
### Browser
|
|
35
73
|
|
|
36
74
|
`jsmigemo.js` と `migemo-compact-dict` を本リポジトリから用意します。
|
|
@@ -70,7 +108,7 @@ queryメソッドはステートレスのため、複数のスレッドから同
|
|
|
70
108
|
## 辞書ファイルの生成
|
|
71
109
|
|
|
72
110
|
```shell
|
|
73
|
-
> node bin/jsmigemo-dict.
|
|
111
|
+
> node bin/jsmigemo-dict.mjs <text-dict-file> <compact-dict-file>
|
|
74
112
|
```
|
|
75
113
|
|
|
76
114
|
`<text-dict-file>` は、C/Miemoで使われているテキスト形式の辞書ファイルです。
|
package/bin/jsmigemo-cli.mjs
CHANGED
|
File without changes
|
package/dist/jsmigemo.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
class BitList {
|
|
6
4
|
constructor(size) {
|
|
7
5
|
if (size == undefined) {
|
|
@@ -672,18 +670,18 @@ class LOUDSTrie {
|
|
|
672
670
|
if (index <= 0 || this.edges.length <= index) {
|
|
673
671
|
throw new RangeError();
|
|
674
672
|
}
|
|
675
|
-
|
|
673
|
+
const sb = new Array();
|
|
676
674
|
while (index > 1) {
|
|
677
675
|
sb.push(this.edges[index]);
|
|
678
676
|
index = this.parent(index);
|
|
679
677
|
}
|
|
680
|
-
return
|
|
678
|
+
return String.fromCharCode(...sb.reverse());
|
|
681
679
|
}
|
|
682
680
|
parent(x) {
|
|
683
681
|
return this.bitVector.rank(this.bitVector.select(x, true), false);
|
|
684
682
|
}
|
|
685
683
|
firstChild(x) {
|
|
686
|
-
|
|
684
|
+
const y = this.bitVector.select(x, false) + 1;
|
|
687
685
|
if (this.bitVector.get(y)) {
|
|
688
686
|
return this.bitVector.rank(y, true) + 1;
|
|
689
687
|
}
|
|
@@ -692,20 +690,20 @@ class LOUDSTrie {
|
|
|
692
690
|
}
|
|
693
691
|
}
|
|
694
692
|
traverse(index, c) {
|
|
695
|
-
|
|
693
|
+
const firstChild = this.firstChild(index);
|
|
696
694
|
if (firstChild == -1) {
|
|
697
695
|
return -1;
|
|
698
696
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
697
|
+
const childStartBit = this.bitVector.select(firstChild, true);
|
|
698
|
+
const childEndBit = this.bitVector.nextClearBit(childStartBit);
|
|
699
|
+
const childSize = childEndBit - childStartBit;
|
|
700
|
+
const result = binarySearchUint16(this.edges, firstChild, firstChild + childSize, c);
|
|
703
701
|
return result >= 0 ? result : -1;
|
|
704
702
|
}
|
|
705
703
|
lookup(key) {
|
|
706
704
|
let nodeIndex = 1;
|
|
707
705
|
for (let i = 0; i < key.length; i++) {
|
|
708
|
-
|
|
706
|
+
const c = key.charCodeAt(i);
|
|
709
707
|
nodeIndex = this.traverse(nodeIndex, c);
|
|
710
708
|
if (nodeIndex == -1) {
|
|
711
709
|
break;
|
|
@@ -824,11 +822,9 @@ class CompactDictionary {
|
|
|
824
822
|
const size = valueEndPos - valueStartPos - 1;
|
|
825
823
|
if (size > 0) {
|
|
826
824
|
const offset = this.mappingBitVector.rank(valueStartPos, false);
|
|
827
|
-
|
|
828
|
-
for (let i = 0; i < result.length; i++) {
|
|
825
|
+
for (let i = 0; i < size; i++) {
|
|
829
826
|
yield this.valueTrie.reverseLookup(this.mapping[valueStartPos - offset + i]);
|
|
830
827
|
}
|
|
831
|
-
return result;
|
|
832
828
|
}
|
|
833
829
|
}
|
|
834
830
|
}
|
|
@@ -1343,19 +1339,20 @@ class TernaryRegexGenerator {
|
|
|
1343
1339
|
}
|
|
1344
1340
|
}
|
|
1345
1341
|
|
|
1346
|
-
class RomajiPredictiveResult
|
|
1342
|
+
class RomajiPredictiveResult {
|
|
1347
1343
|
constructor(prefix, suffixes) {
|
|
1348
1344
|
this.prefix = prefix;
|
|
1349
1345
|
this.suffixes = suffixes;
|
|
1350
1346
|
}
|
|
1351
|
-
}
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1352
1349
|
class RomajiProcessor2 {
|
|
1353
1350
|
constructor(trie, hiraganaList, remainList) {
|
|
1354
1351
|
this.trie = trie;
|
|
1355
1352
|
this.hiraganaList = hiraganaList;
|
|
1356
1353
|
this.remainList = remainList;
|
|
1357
1354
|
}
|
|
1358
|
-
static
|
|
1355
|
+
static build() {
|
|
1359
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]);
|
|
1360
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]);
|
|
1361
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]);
|
|
@@ -1414,10 +1411,10 @@ class RomajiProcessor2 {
|
|
|
1414
1411
|
}
|
|
1415
1412
|
if (list.length == 1) {
|
|
1416
1413
|
builder = builder + list[0];
|
|
1417
|
-
return new RomajiPredictiveResult
|
|
1414
|
+
return new RomajiPredictiveResult(builder, [""]);
|
|
1418
1415
|
}
|
|
1419
1416
|
else {
|
|
1420
|
-
return new RomajiPredictiveResult
|
|
1417
|
+
return new RomajiPredictiveResult(builder, list);
|
|
1421
1418
|
}
|
|
1422
1419
|
}
|
|
1423
1420
|
else if (longestNode >= 0) {
|
|
@@ -1429,7 +1426,7 @@ class RomajiProcessor2 {
|
|
|
1429
1426
|
cursor++;
|
|
1430
1427
|
}
|
|
1431
1428
|
}
|
|
1432
|
-
return new RomajiPredictiveResult
|
|
1429
|
+
return new RomajiPredictiveResult(builder, [""]);
|
|
1433
1430
|
}
|
|
1434
1431
|
}
|
|
1435
1432
|
|
|
@@ -1437,7 +1434,7 @@ class Migemo {
|
|
|
1437
1434
|
constructor() {
|
|
1438
1435
|
this.dict = null;
|
|
1439
1436
|
this.rxop = null;
|
|
1440
|
-
this.processor = RomajiProcessor2.
|
|
1437
|
+
this.processor = RomajiProcessor2.build();
|
|
1441
1438
|
}
|
|
1442
1439
|
queryAWord(word) {
|
|
1443
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]);
|
|
@@ -1492,6 +1489,9 @@ class Migemo {
|
|
|
1492
1489
|
setRxop(rxop) {
|
|
1493
1490
|
this.rxop = rxop;
|
|
1494
1491
|
}
|
|
1492
|
+
setRomajiProcessor(processor) {
|
|
1493
|
+
this.processor = processor;
|
|
1494
|
+
}
|
|
1495
1495
|
*parseQuery(query) {
|
|
1496
1496
|
const re = /[^A-Z\s]+|[A-Z]{2,}|([A-Z][^A-Z\s]+)|([A-Z]\s*$)/g;
|
|
1497
1497
|
let myArray;
|
|
@@ -1839,140 +1839,153 @@ const ROMAN_ENTRIES = [
|
|
|
1839
1839
|
new RomanEntry("who", "うぉ", 0)
|
|
1840
1840
|
]
|
|
1841
1841
|
.sort((a, b) => a.index - b.index);
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
this.
|
|
1846
|
-
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);
|
|
1847
1848
|
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
let
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
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++;
|
|
1865
1878
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
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;
|
|
1868
1884
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1885
|
+
else {
|
|
1886
|
+
hiragana = hiragana + romaji.charAt(start);
|
|
1887
|
+
start++;
|
|
1888
|
+
end = start + 1;
|
|
1873
1889
|
}
|
|
1874
|
-
end++;
|
|
1875
|
-
}
|
|
1876
|
-
if (lastFound >= 0) {
|
|
1877
|
-
const entry = ROMAN_ENTRIES[lastFound];
|
|
1878
|
-
hiragana = hiragana + entry.hiragana;
|
|
1879
|
-
start = start + entry.roman.length - entry.remain;
|
|
1880
|
-
end = start + 1;
|
|
1881
|
-
}
|
|
1882
|
-
else {
|
|
1883
|
-
hiragana = hiragana + romaji.charAt(start);
|
|
1884
|
-
start++;
|
|
1885
|
-
end = start + 1;
|
|
1886
1890
|
}
|
|
1891
|
+
return hiragana;
|
|
1887
1892
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
if (roman.length <= offset + i) {
|
|
1895
|
-
break;
|
|
1896
|
-
}
|
|
1897
|
-
const startKey = RomanEntry._calculateIndex(roman, offset, offset + i + 1);
|
|
1898
|
-
startIndex = binarySearch(ROMAN_INDEXES, startIndex, endIndex, startKey);
|
|
1899
|
-
if (startIndex >= 0) ;
|
|
1900
|
-
else {
|
|
1901
|
-
startIndex = -startIndex - 1;
|
|
1902
|
-
}
|
|
1903
|
-
const endKey = startKey + (1 << (24 - 8 * i));
|
|
1904
|
-
endIndex = binarySearch(ROMAN_INDEXES, startIndex, endIndex, endKey);
|
|
1905
|
-
if (endIndex < 0) {
|
|
1906
|
-
endIndex = -endIndex - 1;
|
|
1907
|
-
}
|
|
1908
|
-
if (endIndex - startIndex == 1) {
|
|
1909
|
-
return new Set([ROMAN_ENTRIES[startIndex]]);
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
const result = new Set();
|
|
1913
|
-
for (let i = startIndex; i < endIndex; i++) {
|
|
1914
|
-
result.add(ROMAN_ENTRIES[i]);
|
|
1915
|
-
}
|
|
1916
|
-
return result;
|
|
1917
|
-
}
|
|
1918
|
-
function romajiToHiraganaPredictively(romaji) {
|
|
1919
|
-
if (romaji.length == 0) {
|
|
1920
|
-
return new RomajiPredictiveResult("", new Set([""]));
|
|
1921
|
-
}
|
|
1922
|
-
let hiragana = "";
|
|
1923
|
-
let start = 0;
|
|
1924
|
-
let end = 1;
|
|
1925
|
-
while (start < romaji.length) {
|
|
1926
|
-
let lastFound = -1;
|
|
1927
|
-
let lower = 0;
|
|
1928
|
-
let upper = ROMAN_INDEXES.length;
|
|
1929
|
-
while (upper - lower > 1 && end <= romaji.length) {
|
|
1930
|
-
const lowerKey = RomanEntry._calculateIndex(romaji, start, end);
|
|
1931
|
-
lower = binarySearch(ROMAN_INDEXES, lower, upper, lowerKey);
|
|
1932
|
-
if (lower >= 0) {
|
|
1933
|
-
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;
|
|
1934
1899
|
}
|
|
1900
|
+
const startKey = RomanEntry._calculateIndex(roman, offset, offset + i + 1);
|
|
1901
|
+
startIndex = binarySearch(this.roman_indexes, startIndex, endIndex, startKey);
|
|
1902
|
+
if (startIndex >= 0) ;
|
|
1935
1903
|
else {
|
|
1936
|
-
|
|
1904
|
+
startIndex = -startIndex - 1;
|
|
1905
|
+
}
|
|
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;
|
|
1937
1910
|
}
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
if (upper < 0) {
|
|
1941
|
-
upper = -upper - 1;
|
|
1911
|
+
if (endIndex - startIndex == 1) {
|
|
1912
|
+
return new Set([this.roman_entries[startIndex]]);
|
|
1942
1913
|
}
|
|
1943
|
-
end++;
|
|
1944
1914
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
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
|
+
}
|
|
1954
1958
|
}
|
|
1955
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], [""]);
|
|
1956
1970
|
}
|
|
1957
1971
|
else {
|
|
1958
|
-
|
|
1972
|
+
return new RomajiPredictiveResult(hiragana, list);
|
|
1959
1973
|
}
|
|
1960
1974
|
}
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
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
|
+
}
|
|
1973
1986
|
}
|
|
1987
|
+
return new RomajiPredictiveResult(hiragana, [""]);
|
|
1974
1988
|
}
|
|
1975
|
-
return new RomajiPredictiveResult(hiragana.toString(), new Set([""]));
|
|
1976
1989
|
}
|
|
1977
1990
|
|
|
1978
1991
|
exports.BitList = BitList;
|
|
@@ -1984,18 +1997,16 @@ exports.DoubleArray = DoubleArray;
|
|
|
1984
1997
|
exports.LOUDSTrie = LOUDSTrie;
|
|
1985
1998
|
exports.LOUDSTrieBuilder = LOUDSTrieBuilder;
|
|
1986
1999
|
exports.Migemo = Migemo;
|
|
1987
|
-
exports.RomajiPredictiveResult = RomajiPredictiveResult
|
|
2000
|
+
exports.RomajiPredictiveResult = RomajiPredictiveResult;
|
|
2001
|
+
exports.RomajiProcessor1 = RomajiProcessor1;
|
|
1988
2002
|
exports.RomajiProcessor2 = RomajiProcessor2;
|
|
2003
|
+
exports.RomanEntry = RomanEntry;
|
|
1989
2004
|
exports.TernaryRegexGenerator = TernaryRegexGenerator;
|
|
1990
2005
|
exports.binarySearch = binarySearch;
|
|
1991
2006
|
exports.binarySearchString = binarySearchString;
|
|
1992
2007
|
exports.binarySearchUint16 = binarySearchUint16;
|
|
1993
2008
|
exports.bitCount = bitCount;
|
|
1994
|
-
exports.findRomanEntryPredicatively = findRomanEntryPredicatively;
|
|
1995
2009
|
exports.han2zen_conv = han2zen_conv;
|
|
1996
2010
|
exports.hira2kata_conv = hira2kata_conv;
|
|
1997
2011
|
exports.numberOfTrailingZeros = numberOfTrailingZeros;
|
|
1998
|
-
exports.romajiToHiragana = romajiToHiragana;
|
|
1999
|
-
exports.romajiToHiraganaPredictively = romajiToHiraganaPredictively;
|
|
2000
2012
|
exports.zen2han_conv = zen2han_conv;
|
|
2001
|
-
//# sourceMappingURL=jsmigemo.cjs.map
|
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 };
|