jsmigemo 0.3.1
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 +97 -0
- package/bin/jsmigemo-cli.js +122 -0
- package/bin/jsmigemo-dict.js +37 -0
- package/bin/jsmigemo-skk2migemo.js +61 -0
- package/demo-list.html +116 -0
- package/demo-text.html +65 -0
- package/esm/BitList.d.ts +8 -0
- package/esm/BitList.js +39 -0
- package/esm/BitList.js.map +1 -0
- package/esm/BitVector.d.ts +15 -0
- package/esm/BitVector.js +150 -0
- package/esm/BitVector.js.map +1 -0
- package/esm/CharacterConverter.d.ts +3 -0
- package/esm/CharacterConverter.js +382 -0
- package/esm/CharacterConverter.js.map +1 -0
- package/esm/CompactDictionary.d.ts +17 -0
- package/esm/CompactDictionary.js +124 -0
- package/esm/CompactDictionary.js.map +1 -0
- package/esm/CompactDictionaryBuilder.d.ts +3 -0
- package/esm/CompactDictionaryBuilder.js +118 -0
- package/esm/CompactDictionaryBuilder.js.map +1 -0
- package/esm/CompactHiraganaString.d.ts +6 -0
- package/esm/CompactHiraganaString.js +41 -0
- package/esm/CompactHiraganaString.js.map +1 -0
- package/esm/DoubleArray.d.ts +12 -0
- package/esm/DoubleArray.js +70 -0
- package/esm/DoubleArray.js.map +1 -0
- package/esm/LOUDSTrie.d.ts +13 -0
- package/esm/LOUDSTrie.js +67 -0
- package/esm/LOUDSTrie.js.map +1 -0
- package/esm/LOUDSTrieBuilder.d.ts +4 -0
- package/esm/LOUDSTrieBuilder.js +69 -0
- package/esm/LOUDSTrieBuilder.js.map +1 -0
- package/esm/Migemo.d.ts +13 -0
- package/esm/Migemo.js +71 -0
- package/esm/Migemo.js.map +1 -0
- package/esm/RomajiProcessor.d.ts +18 -0
- package/esm/RomajiProcessor.js +478 -0
- package/esm/RomajiProcessor.js.map +1 -0
- package/esm/RomajiProcessor2.d.ts +15 -0
- package/esm/RomajiProcessor2.js +91 -0
- package/esm/RomajiProcessor2.js.map +1 -0
- package/esm/SimpleDictionary.d.ts +1 -0
- package/esm/SimpleDictionary.js +54 -0
- package/esm/SimpleDictionary.js.map +1 -0
- package/esm/TernaryRegexGenerator.d.ts +27 -0
- package/esm/TernaryRegexGenerator.js +202 -0
- package/esm/TernaryRegexGenerator.js.map +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -0
- package/esm/utils.d.ts +5 -0
- package/esm/utils.js +88 -0
- package/esm/utils.js.map +1 -0
- package/index.html +55 -0
- package/jest.config.js +12 -0
- package/lib/BitList.d.ts +8 -0
- package/lib/BitList.js +43 -0
- package/lib/BitList.js.map +1 -0
- package/lib/BitVector.d.ts +15 -0
- package/lib/BitVector.js +154 -0
- package/lib/BitVector.js.map +1 -0
- package/lib/CharacterConverter.d.ts +3 -0
- package/lib/CharacterConverter.js +388 -0
- package/lib/CharacterConverter.js.map +1 -0
- package/lib/CompactDictionary.d.ts +17 -0
- package/lib/CompactDictionary.js +128 -0
- package/lib/CompactDictionary.js.map +1 -0
- package/lib/CompactDictionaryBuilder.d.ts +3 -0
- package/lib/CompactDictionaryBuilder.js +122 -0
- package/lib/CompactDictionaryBuilder.js.map +1 -0
- package/lib/CompactHiraganaString.d.ts +6 -0
- package/lib/CompactHiraganaString.js +45 -0
- package/lib/CompactHiraganaString.js.map +1 -0
- package/lib/DoubleArray.d.ts +12 -0
- package/lib/DoubleArray.js +74 -0
- package/lib/DoubleArray.js.map +1 -0
- package/lib/LOUDSTrie.d.ts +13 -0
- package/lib/LOUDSTrie.js +71 -0
- package/lib/LOUDSTrie.js.map +1 -0
- package/lib/LOUDSTrieBuilder.d.ts +4 -0
- package/lib/LOUDSTrieBuilder.js +73 -0
- package/lib/LOUDSTrieBuilder.js.map +1 -0
- package/lib/Migemo.d.ts +13 -0
- package/lib/Migemo.js +75 -0
- package/lib/Migemo.js.map +1 -0
- package/lib/RegexGenerator.d.ts +21 -0
- package/lib/RegexGenerator.js +150 -0
- package/lib/RegexGenerator.js.map +1 -0
- package/lib/RomajiProcessor.d.ts +18 -0
- package/lib/RomajiProcessor.js +484 -0
- package/lib/RomajiProcessor.js.map +1 -0
- package/lib/RomajiProcessor2.d.ts +15 -0
- package/lib/RomajiProcessor2.js +96 -0
- package/lib/RomajiProcessor2.js.map +1 -0
- package/lib/RomanEntry.d.ts +1 -0
- package/lib/RomanEntry.js +481 -0
- package/lib/RomanEntry.js.map +1 -0
- package/lib/SimpleDictionary.d.ts +1 -0
- package/lib/SimpleDictionary.js +56 -0
- package/lib/SimpleDictionary.js.map +1 -0
- package/lib/TernaryRegexGenerator.d.ts +27 -0
- package/lib/TernaryRegexGenerator.js +206 -0
- package/lib/TernaryRegexGenerator.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +96 -0
- package/lib/utils.js.map +1 -0
- package/migemo-compact-dict +0 -0
- package/package.json +37 -0
- package/tsconfig.esm.json +9 -0
- package/umd/jsmigemo.js +1 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class RegexNode {
|
|
4
|
+
constructor(code) {
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.child = null;
|
|
7
|
+
this.next = null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.RegexNode = RegexNode;
|
|
11
|
+
class RegexGenerator {
|
|
12
|
+
constructor(or, beginGroup, endGroup, beginClass, endClass, newline) {
|
|
13
|
+
this.or = or;
|
|
14
|
+
this.beginGroup = beginGroup;
|
|
15
|
+
this.endGroup = endGroup;
|
|
16
|
+
this.beginClass = beginClass;
|
|
17
|
+
this.endClass = endClass;
|
|
18
|
+
this.newline = newline;
|
|
19
|
+
this.root = null;
|
|
20
|
+
}
|
|
21
|
+
static getDEFAULT() {
|
|
22
|
+
return new RegexGenerator("|", "(", ")", "[", "]", "");
|
|
23
|
+
}
|
|
24
|
+
static _add(node, word, offset) {
|
|
25
|
+
if (node == null) {
|
|
26
|
+
if (offset >= word.length) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
node = new RegexNode(word[offset]);
|
|
30
|
+
if (offset < word.length - 1) {
|
|
31
|
+
node.child = RegexGenerator._add(null, word, offset + 1);
|
|
32
|
+
}
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
35
|
+
let thisNode = node;
|
|
36
|
+
const code = word[offset];
|
|
37
|
+
if (code < node.code) {
|
|
38
|
+
let newNode = new RegexNode(code);
|
|
39
|
+
newNode.next = node;
|
|
40
|
+
node = newNode;
|
|
41
|
+
if (offset < word.length) {
|
|
42
|
+
node.child = RegexGenerator._add(null, word, offset + 1);
|
|
43
|
+
}
|
|
44
|
+
thisNode = node;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
while (node.next != null && node.next.code <= code) {
|
|
48
|
+
node = node.next;
|
|
49
|
+
}
|
|
50
|
+
if (node.code == code) {
|
|
51
|
+
if (node.child == null) {
|
|
52
|
+
return thisNode;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
let newNode = new RegexNode(code);
|
|
57
|
+
newNode.next = node.next;
|
|
58
|
+
node.next = newNode;
|
|
59
|
+
node = newNode;
|
|
60
|
+
}
|
|
61
|
+
if (word.length == offset + 1) {
|
|
62
|
+
node.child = null;
|
|
63
|
+
return thisNode;
|
|
64
|
+
}
|
|
65
|
+
node.child = RegexGenerator._add(node.child, word, offset + 1);
|
|
66
|
+
}
|
|
67
|
+
return thisNode;
|
|
68
|
+
}
|
|
69
|
+
add(word) {
|
|
70
|
+
if (word.length == 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.root = RegexGenerator._add(this.root, word, 0);
|
|
74
|
+
}
|
|
75
|
+
_generateStub(node) {
|
|
76
|
+
const escapeCharacters = "\\.[]{}()*+-?^$|";
|
|
77
|
+
let brother = 1;
|
|
78
|
+
let haschild = 0;
|
|
79
|
+
let buf = "";
|
|
80
|
+
for (let tmp = node; tmp != null; tmp = tmp.next) {
|
|
81
|
+
if (tmp.next != null) {
|
|
82
|
+
brother++;
|
|
83
|
+
}
|
|
84
|
+
if (tmp.child != null) {
|
|
85
|
+
haschild++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let nochild = brother - haschild;
|
|
89
|
+
if (brother > 1 && haschild > 0) {
|
|
90
|
+
buf += this.beginGroup;
|
|
91
|
+
}
|
|
92
|
+
if (nochild > 0) {
|
|
93
|
+
if (nochild > 1) {
|
|
94
|
+
buf = buf + this.beginClass;
|
|
95
|
+
}
|
|
96
|
+
for (let tmp = node; tmp != null; tmp = tmp.next) {
|
|
97
|
+
if (tmp.child != null) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (escapeCharacters.indexOf(tmp.code) != -1) {
|
|
101
|
+
buf = buf + "\\";
|
|
102
|
+
}
|
|
103
|
+
buf = buf + tmp.code;
|
|
104
|
+
}
|
|
105
|
+
if (nochild > 1) {
|
|
106
|
+
buf += this.endClass;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (haschild > 0) {
|
|
110
|
+
if (nochild > 0) {
|
|
111
|
+
buf += this.or;
|
|
112
|
+
}
|
|
113
|
+
let tmp = null;
|
|
114
|
+
for (tmp = node; tmp.child == null; tmp = tmp.next) {
|
|
115
|
+
}
|
|
116
|
+
while (true) {
|
|
117
|
+
if (escapeCharacters.indexOf(tmp.code) != -1) {
|
|
118
|
+
buf += "\\";
|
|
119
|
+
}
|
|
120
|
+
buf = buf + tmp.code;
|
|
121
|
+
if (this.newline != null) {
|
|
122
|
+
buf += this.newline;
|
|
123
|
+
}
|
|
124
|
+
buf = buf + this._generateStub(tmp.child);
|
|
125
|
+
for (tmp = tmp.next; tmp != null && tmp.child == null; tmp = tmp.next) {
|
|
126
|
+
}
|
|
127
|
+
if (tmp == null) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (haschild > 1) {
|
|
131
|
+
buf += this.or;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (brother > 1 && haschild > 0) {
|
|
136
|
+
buf += this.endGroup;
|
|
137
|
+
}
|
|
138
|
+
return buf;
|
|
139
|
+
}
|
|
140
|
+
generate() {
|
|
141
|
+
if (this.root == null) {
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return this._generateStub(this.root);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.RegexGenerator = RegexGenerator;
|
|
150
|
+
//# sourceMappingURL=RegexGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RegexGenerator.js","sourceRoot":"","sources":["../src/RegexGenerator.ts"],"names":[],"mappings":";;AAAA,MAAa,SAAS;IAIrB,YAAY,IAAY;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AATD,8BASC;AAED,MAAa,cAAc;IAQ1B,YAAY,EAAU,EAAE,UAAkB,EAAE,QAAgB,EAAE,UAAkB,EAAE,QAAgB,EAAE,OAAe;QAClH,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,UAAU;QAChB,OAAO,IAAI,cAAc,CAAC,GA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AAO,IAAI,IAAI,EAAE;oBACzB,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC;iBACpB;gBACD,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,GAAI,CAAC,KAAK,CAAC,CAAC;gBAC3C,KAAK,GAAG,GAAG,GAAI,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE;iBACvE;gBACD,IAAI,GAAG,IAAI,IAAI,EAAE;oBAChB,MAAM;iBACN;gBACD,IAAI,QAAQ,GAAG,CAAC,EAAE;oBACjB,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;iBACf;aACD;SACD;QACD,IAAI,OAAO,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE;YAChC,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC;SACrB;QACD,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,QAAQ;QACP,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE;YACtB,OAAO,EAAE,CAAC;SACV;aACI;YACJ,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrC;IACF,CAAC;CACD;AAvJD,wCAuJC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare class RomanEntry {
|
|
2
|
+
roman: string;
|
|
3
|
+
hiragana: string;
|
|
4
|
+
remain: number;
|
|
5
|
+
index: number;
|
|
6
|
+
constructor(roman: string, hiragana: string, remain: number);
|
|
7
|
+
static _calculateIndex(roman: string, start: number, end: number): number;
|
|
8
|
+
static calculateIndex(roman: string): number;
|
|
9
|
+
}
|
|
10
|
+
declare class RomajiPredictiveResult {
|
|
11
|
+
estaglishedHiragana: string;
|
|
12
|
+
predictiveSuffixes: Set<string>;
|
|
13
|
+
constructor(estaglishedHiragana: string, predictiveSuffixes: Set<string>);
|
|
14
|
+
}
|
|
15
|
+
export declare function romajiToHiragana(romaji: string): string;
|
|
16
|
+
export declare function findRomanEntryPredicatively(roman: string, offset: number): Set<RomanEntry>;
|
|
17
|
+
export declare function romajiToHiraganaPredictively(romaji: string): RomajiPredictiveResult;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.romajiToHiraganaPredictively = exports.findRomanEntryPredicatively = exports.romajiToHiragana = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class RomanEntry {
|
|
6
|
+
constructor(roman, hiragana, remain) {
|
|
7
|
+
this.roman = roman;
|
|
8
|
+
this.hiragana = hiragana;
|
|
9
|
+
this.remain = remain;
|
|
10
|
+
this.index = RomanEntry.calculateIndex(roman);
|
|
11
|
+
}
|
|
12
|
+
static _calculateIndex(roman, start, end) {
|
|
13
|
+
let result = 0;
|
|
14
|
+
for (let i = 0; i < 4; i++) {
|
|
15
|
+
const index = i + start;
|
|
16
|
+
const c = index < roman.length && index < end ? roman.charCodeAt(index) : 0;
|
|
17
|
+
result |= c;
|
|
18
|
+
if (i < 3) {
|
|
19
|
+
result <<= 8;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
static calculateIndex(roman) {
|
|
25
|
+
return RomanEntry._calculateIndex(roman, 0, 4);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const ROMAN_ENTRIES = [
|
|
29
|
+
new RomanEntry("-", "ー", 0),
|
|
30
|
+
new RomanEntry("~", "〜", 0),
|
|
31
|
+
new RomanEntry(".", "。", 0),
|
|
32
|
+
new RomanEntry(",", "、", 0),
|
|
33
|
+
new RomanEntry("z/", "・", 0),
|
|
34
|
+
new RomanEntry("z.", "…", 0),
|
|
35
|
+
new RomanEntry("z,", "‥", 0),
|
|
36
|
+
new RomanEntry("zh", "←", 0),
|
|
37
|
+
new RomanEntry("zj", "↓", 0),
|
|
38
|
+
new RomanEntry("zk", "↑", 0),
|
|
39
|
+
new RomanEntry("zl", "→", 0),
|
|
40
|
+
new RomanEntry("z-", "〜", 0),
|
|
41
|
+
new RomanEntry("z[", "『", 0),
|
|
42
|
+
new RomanEntry("z]", "』", 0),
|
|
43
|
+
new RomanEntry("[", "「", 0),
|
|
44
|
+
new RomanEntry("]", "」", 0),
|
|
45
|
+
new RomanEntry("va", "ゔぁ", 0),
|
|
46
|
+
new RomanEntry("vi", "ゔぃ", 0),
|
|
47
|
+
new RomanEntry("vu", "ゔ", 0),
|
|
48
|
+
new RomanEntry("ve", "ゔぇ", 0),
|
|
49
|
+
new RomanEntry("vo", "ゔぉ", 0),
|
|
50
|
+
new RomanEntry("vya", "ゔゃ", 0),
|
|
51
|
+
new RomanEntry("vyi", "ゔぃ", 0),
|
|
52
|
+
new RomanEntry("vyu", "ゔゅ", 0),
|
|
53
|
+
new RomanEntry("vye", "ゔぇ", 0),
|
|
54
|
+
new RomanEntry("vyo", "ゔょ", 0),
|
|
55
|
+
new RomanEntry("qq", "っ", 1),
|
|
56
|
+
new RomanEntry("vv", "っ", 1),
|
|
57
|
+
new RomanEntry("ll", "っ", 1),
|
|
58
|
+
new RomanEntry("xx", "っ", 1),
|
|
59
|
+
new RomanEntry("kk", "っ", 1),
|
|
60
|
+
new RomanEntry("gg", "っ", 1),
|
|
61
|
+
new RomanEntry("ss", "っ", 1),
|
|
62
|
+
new RomanEntry("zz", "っ", 1),
|
|
63
|
+
new RomanEntry("jj", "っ", 1),
|
|
64
|
+
new RomanEntry("tt", "っ", 1),
|
|
65
|
+
new RomanEntry("dd", "っ", 1),
|
|
66
|
+
new RomanEntry("hh", "っ", 1),
|
|
67
|
+
new RomanEntry("ff", "っ", 1),
|
|
68
|
+
new RomanEntry("bb", "っ", 1),
|
|
69
|
+
new RomanEntry("pp", "っ", 1),
|
|
70
|
+
new RomanEntry("mm", "っ", 1),
|
|
71
|
+
new RomanEntry("yy", "っ", 1),
|
|
72
|
+
new RomanEntry("rr", "っ", 1),
|
|
73
|
+
new RomanEntry("ww", "っ", 1),
|
|
74
|
+
new RomanEntry("www", "w", 2),
|
|
75
|
+
new RomanEntry("cc", "っ", 1),
|
|
76
|
+
new RomanEntry("kya", "きゃ", 0),
|
|
77
|
+
new RomanEntry("kyi", "きぃ", 0),
|
|
78
|
+
new RomanEntry("kyu", "きゅ", 0),
|
|
79
|
+
new RomanEntry("kye", "きぇ", 0),
|
|
80
|
+
new RomanEntry("kyo", "きょ", 0),
|
|
81
|
+
new RomanEntry("gya", "ぎゃ", 0),
|
|
82
|
+
new RomanEntry("gyi", "ぎぃ", 0),
|
|
83
|
+
new RomanEntry("gyu", "ぎゅ", 0),
|
|
84
|
+
new RomanEntry("gye", "ぎぇ", 0),
|
|
85
|
+
new RomanEntry("gyo", "ぎょ", 0),
|
|
86
|
+
new RomanEntry("sya", "しゃ", 0),
|
|
87
|
+
new RomanEntry("syi", "しぃ", 0),
|
|
88
|
+
new RomanEntry("syu", "しゅ", 0),
|
|
89
|
+
new RomanEntry("sye", "しぇ", 0),
|
|
90
|
+
new RomanEntry("syo", "しょ", 0),
|
|
91
|
+
new RomanEntry("sha", "しゃ", 0),
|
|
92
|
+
new RomanEntry("shi", "し", 0),
|
|
93
|
+
new RomanEntry("shu", "しゅ", 0),
|
|
94
|
+
new RomanEntry("she", "しぇ", 0),
|
|
95
|
+
new RomanEntry("sho", "しょ", 0),
|
|
96
|
+
new RomanEntry("zya", "じゃ", 0),
|
|
97
|
+
new RomanEntry("zyi", "じぃ", 0),
|
|
98
|
+
new RomanEntry("zyu", "じゅ", 0),
|
|
99
|
+
new RomanEntry("zye", "じぇ", 0),
|
|
100
|
+
new RomanEntry("zyo", "じょ", 0),
|
|
101
|
+
new RomanEntry("tya", "ちゃ", 0),
|
|
102
|
+
new RomanEntry("tyi", "ちぃ", 0),
|
|
103
|
+
new RomanEntry("tyu", "ちゅ", 0),
|
|
104
|
+
new RomanEntry("tye", "ちぇ", 0),
|
|
105
|
+
new RomanEntry("tyo", "ちょ", 0),
|
|
106
|
+
new RomanEntry("cha", "ちゃ", 0),
|
|
107
|
+
new RomanEntry("chi", "ち", 0),
|
|
108
|
+
new RomanEntry("chu", "ちゅ", 0),
|
|
109
|
+
new RomanEntry("che", "ちぇ", 0),
|
|
110
|
+
new RomanEntry("cho", "ちょ", 0),
|
|
111
|
+
new RomanEntry("cya", "ちゃ", 0),
|
|
112
|
+
new RomanEntry("cyi", "ちぃ", 0),
|
|
113
|
+
new RomanEntry("cyu", "ちゅ", 0),
|
|
114
|
+
new RomanEntry("cye", "ちぇ", 0),
|
|
115
|
+
new RomanEntry("cyo", "ちょ", 0),
|
|
116
|
+
new RomanEntry("dya", "ぢゃ", 0),
|
|
117
|
+
new RomanEntry("dyi", "ぢぃ", 0),
|
|
118
|
+
new RomanEntry("dyu", "ぢゅ", 0),
|
|
119
|
+
new RomanEntry("dye", "ぢぇ", 0),
|
|
120
|
+
new RomanEntry("dyo", "ぢょ", 0),
|
|
121
|
+
new RomanEntry("tsa", "つぁ", 0),
|
|
122
|
+
new RomanEntry("tsi", "つぃ", 0),
|
|
123
|
+
new RomanEntry("tse", "つぇ", 0),
|
|
124
|
+
new RomanEntry("tso", "つぉ", 0),
|
|
125
|
+
new RomanEntry("tha", "てゃ", 0),
|
|
126
|
+
new RomanEntry("thi", "てぃ", 0),
|
|
127
|
+
new RomanEntry("t'i", "てぃ", 0),
|
|
128
|
+
new RomanEntry("thu", "てゅ", 0),
|
|
129
|
+
new RomanEntry("the", "てぇ", 0),
|
|
130
|
+
new RomanEntry("tho", "てょ", 0),
|
|
131
|
+
new RomanEntry("t'yu", "てゅ", 0),
|
|
132
|
+
new RomanEntry("dha", "でゃ", 0),
|
|
133
|
+
new RomanEntry("dhi", "でぃ", 0),
|
|
134
|
+
new RomanEntry("d'i", "でぃ", 0),
|
|
135
|
+
new RomanEntry("dhu", "でゅ", 0),
|
|
136
|
+
new RomanEntry("dhe", "でぇ", 0),
|
|
137
|
+
new RomanEntry("dho", "でょ", 0),
|
|
138
|
+
new RomanEntry("d'yu", "でゅ", 0),
|
|
139
|
+
new RomanEntry("twa", "とぁ", 0),
|
|
140
|
+
new RomanEntry("twi", "とぃ", 0),
|
|
141
|
+
new RomanEntry("twu", "とぅ", 0),
|
|
142
|
+
new RomanEntry("twe", "とぇ", 0),
|
|
143
|
+
new RomanEntry("two", "とぉ", 0),
|
|
144
|
+
new RomanEntry("t'u", "とぅ", 0),
|
|
145
|
+
new RomanEntry("dwa", "どぁ", 0),
|
|
146
|
+
new RomanEntry("dwi", "どぃ", 0),
|
|
147
|
+
new RomanEntry("dwu", "どぅ", 0),
|
|
148
|
+
new RomanEntry("dwe", "どぇ", 0),
|
|
149
|
+
new RomanEntry("dwo", "どぉ", 0),
|
|
150
|
+
new RomanEntry("d'u", "どぅ", 0),
|
|
151
|
+
new RomanEntry("nya", "にゃ", 0),
|
|
152
|
+
new RomanEntry("nyi", "にぃ", 0),
|
|
153
|
+
new RomanEntry("nyu", "にゅ", 0),
|
|
154
|
+
new RomanEntry("nye", "にぇ", 0),
|
|
155
|
+
new RomanEntry("nyo", "にょ", 0),
|
|
156
|
+
new RomanEntry("hya", "ひゃ", 0),
|
|
157
|
+
new RomanEntry("hyi", "ひぃ", 0),
|
|
158
|
+
new RomanEntry("hyu", "ひゅ", 0),
|
|
159
|
+
new RomanEntry("hye", "ひぇ", 0),
|
|
160
|
+
new RomanEntry("hyo", "ひょ", 0),
|
|
161
|
+
new RomanEntry("bya", "びゃ", 0),
|
|
162
|
+
new RomanEntry("byi", "びぃ", 0),
|
|
163
|
+
new RomanEntry("byu", "びゅ", 0),
|
|
164
|
+
new RomanEntry("bye", "びぇ", 0),
|
|
165
|
+
new RomanEntry("byo", "びょ", 0),
|
|
166
|
+
new RomanEntry("pya", "ぴゃ", 0),
|
|
167
|
+
new RomanEntry("pyi", "ぴぃ", 0),
|
|
168
|
+
new RomanEntry("pyu", "ぴゅ", 0),
|
|
169
|
+
new RomanEntry("pye", "ぴぇ", 0),
|
|
170
|
+
new RomanEntry("pyo", "ぴょ", 0),
|
|
171
|
+
new RomanEntry("fa", "ふぁ", 0),
|
|
172
|
+
new RomanEntry("fi", "ふぃ", 0),
|
|
173
|
+
new RomanEntry("fu", "ふ", 0),
|
|
174
|
+
new RomanEntry("fe", "ふぇ", 0),
|
|
175
|
+
new RomanEntry("fo", "ふぉ", 0),
|
|
176
|
+
new RomanEntry("fya", "ふゃ", 0),
|
|
177
|
+
new RomanEntry("fyu", "ふゅ", 0),
|
|
178
|
+
new RomanEntry("fyo", "ふょ", 0),
|
|
179
|
+
new RomanEntry("hwa", "ふぁ", 0),
|
|
180
|
+
new RomanEntry("hwi", "ふぃ", 0),
|
|
181
|
+
new RomanEntry("hwe", "ふぇ", 0),
|
|
182
|
+
new RomanEntry("hwo", "ふぉ", 0),
|
|
183
|
+
new RomanEntry("hwyu", "ふゅ", 0),
|
|
184
|
+
new RomanEntry("mya", "みゃ", 0),
|
|
185
|
+
new RomanEntry("myi", "みぃ", 0),
|
|
186
|
+
new RomanEntry("myu", "みゅ", 0),
|
|
187
|
+
new RomanEntry("mye", "みぇ", 0),
|
|
188
|
+
new RomanEntry("myo", "みょ", 0),
|
|
189
|
+
new RomanEntry("rya", "りゃ", 0),
|
|
190
|
+
new RomanEntry("ryi", "りぃ", 0),
|
|
191
|
+
new RomanEntry("ryu", "りゅ", 0),
|
|
192
|
+
new RomanEntry("rye", "りぇ", 0),
|
|
193
|
+
new RomanEntry("ryo", "りょ", 0),
|
|
194
|
+
new RomanEntry("n'", "ん", 0),
|
|
195
|
+
new RomanEntry("nn", "ん", 0),
|
|
196
|
+
new RomanEntry("n", "ん", 0),
|
|
197
|
+
new RomanEntry("xn", "ん", 0),
|
|
198
|
+
new RomanEntry("a", "あ", 0),
|
|
199
|
+
new RomanEntry("i", "い", 0),
|
|
200
|
+
new RomanEntry("u", "う", 0),
|
|
201
|
+
new RomanEntry("wu", "う", 0),
|
|
202
|
+
new RomanEntry("e", "え", 0),
|
|
203
|
+
new RomanEntry("o", "お", 0),
|
|
204
|
+
new RomanEntry("xa", "ぁ", 0),
|
|
205
|
+
new RomanEntry("xi", "ぃ", 0),
|
|
206
|
+
new RomanEntry("xu", "ぅ", 0),
|
|
207
|
+
new RomanEntry("xe", "ぇ", 0),
|
|
208
|
+
new RomanEntry("xo", "ぉ", 0),
|
|
209
|
+
new RomanEntry("la", "ぁ", 0),
|
|
210
|
+
new RomanEntry("li", "ぃ", 0),
|
|
211
|
+
new RomanEntry("lu", "ぅ", 0),
|
|
212
|
+
new RomanEntry("le", "ぇ", 0),
|
|
213
|
+
new RomanEntry("lo", "ぉ", 0),
|
|
214
|
+
new RomanEntry("lyi", "ぃ", 0),
|
|
215
|
+
new RomanEntry("xyi", "ぃ", 0),
|
|
216
|
+
new RomanEntry("lye", "ぇ", 0),
|
|
217
|
+
new RomanEntry("xye", "ぇ", 0),
|
|
218
|
+
new RomanEntry("ye", "いぇ", 0),
|
|
219
|
+
new RomanEntry("ka", "か", 0),
|
|
220
|
+
new RomanEntry("ki", "き", 0),
|
|
221
|
+
new RomanEntry("ku", "く", 0),
|
|
222
|
+
new RomanEntry("ke", "け", 0),
|
|
223
|
+
new RomanEntry("ko", "こ", 0),
|
|
224
|
+
new RomanEntry("xka", "ヵ", 0),
|
|
225
|
+
new RomanEntry("xke", "ヶ", 0),
|
|
226
|
+
new RomanEntry("lka", "ヵ", 0),
|
|
227
|
+
new RomanEntry("lke", "ヶ", 0),
|
|
228
|
+
new RomanEntry("ga", "が", 0),
|
|
229
|
+
new RomanEntry("gi", "ぎ", 0),
|
|
230
|
+
new RomanEntry("gu", "ぐ", 0),
|
|
231
|
+
new RomanEntry("ge", "げ", 0),
|
|
232
|
+
new RomanEntry("go", "ご", 0),
|
|
233
|
+
new RomanEntry("sa", "さ", 0),
|
|
234
|
+
new RomanEntry("si", "し", 0),
|
|
235
|
+
new RomanEntry("su", "す", 0),
|
|
236
|
+
new RomanEntry("se", "せ", 0),
|
|
237
|
+
new RomanEntry("so", "そ", 0),
|
|
238
|
+
new RomanEntry("ca", "か", 0),
|
|
239
|
+
new RomanEntry("ci", "し", 0),
|
|
240
|
+
new RomanEntry("cu", "く", 0),
|
|
241
|
+
new RomanEntry("ce", "せ", 0),
|
|
242
|
+
new RomanEntry("co", "こ", 0),
|
|
243
|
+
new RomanEntry("qa", "くぁ", 0),
|
|
244
|
+
new RomanEntry("qi", "くぃ", 0),
|
|
245
|
+
new RomanEntry("qu", "く", 0),
|
|
246
|
+
new RomanEntry("qe", "くぇ", 0),
|
|
247
|
+
new RomanEntry("qo", "くぉ", 0),
|
|
248
|
+
new RomanEntry("kwa", "くぁ", 0),
|
|
249
|
+
new RomanEntry("kwi", "くぃ", 0),
|
|
250
|
+
new RomanEntry("kwu", "くぅ", 0),
|
|
251
|
+
new RomanEntry("kwe", "くぇ", 0),
|
|
252
|
+
new RomanEntry("kwo", "くぉ", 0),
|
|
253
|
+
new RomanEntry("gwa", "ぐぁ", 0),
|
|
254
|
+
new RomanEntry("gwi", "ぐぃ", 0),
|
|
255
|
+
new RomanEntry("gwu", "ぐぅ", 0),
|
|
256
|
+
new RomanEntry("gwe", "ぐぇ", 0),
|
|
257
|
+
new RomanEntry("gwo", "ぐぉ", 0),
|
|
258
|
+
new RomanEntry("za", "ざ", 0),
|
|
259
|
+
new RomanEntry("zi", "じ", 0),
|
|
260
|
+
new RomanEntry("zu", "ず", 0),
|
|
261
|
+
new RomanEntry("ze", "ぜ", 0),
|
|
262
|
+
new RomanEntry("zo", "ぞ", 0),
|
|
263
|
+
new RomanEntry("ja", "じゃ", 0),
|
|
264
|
+
new RomanEntry("ji", "じ", 0),
|
|
265
|
+
new RomanEntry("ju", "じゅ", 0),
|
|
266
|
+
new RomanEntry("je", "じぇ", 0),
|
|
267
|
+
new RomanEntry("jo", "じょ", 0),
|
|
268
|
+
new RomanEntry("jya", "じゃ", 0),
|
|
269
|
+
new RomanEntry("jyi", "じぃ", 0),
|
|
270
|
+
new RomanEntry("jyu", "じゅ", 0),
|
|
271
|
+
new RomanEntry("jye", "じぇ", 0),
|
|
272
|
+
new RomanEntry("jyo", "じょ", 0),
|
|
273
|
+
new RomanEntry("ta", "た", 0),
|
|
274
|
+
new RomanEntry("ti", "ち", 0),
|
|
275
|
+
new RomanEntry("tu", "つ", 0),
|
|
276
|
+
new RomanEntry("tsu", "つ", 0),
|
|
277
|
+
new RomanEntry("te", "て", 0),
|
|
278
|
+
new RomanEntry("to", "と", 0),
|
|
279
|
+
new RomanEntry("da", "だ", 0),
|
|
280
|
+
new RomanEntry("di", "ぢ", 0),
|
|
281
|
+
new RomanEntry("du", "づ", 0),
|
|
282
|
+
new RomanEntry("de", "で", 0),
|
|
283
|
+
new RomanEntry("do", "ど", 0),
|
|
284
|
+
new RomanEntry("xtu", "っ", 0),
|
|
285
|
+
new RomanEntry("xtsu", "っ", 0),
|
|
286
|
+
new RomanEntry("ltu", "っ", 0),
|
|
287
|
+
new RomanEntry("ltsu", "っ", 0),
|
|
288
|
+
new RomanEntry("na", "な", 0),
|
|
289
|
+
new RomanEntry("ni", "に", 0),
|
|
290
|
+
new RomanEntry("nu", "ぬ", 0),
|
|
291
|
+
new RomanEntry("ne", "ね", 0),
|
|
292
|
+
new RomanEntry("no", "の", 0),
|
|
293
|
+
new RomanEntry("ha", "は", 0),
|
|
294
|
+
new RomanEntry("hi", "ひ", 0),
|
|
295
|
+
new RomanEntry("hu", "ふ", 0),
|
|
296
|
+
new RomanEntry("fu", "ふ", 0),
|
|
297
|
+
new RomanEntry("he", "へ", 0),
|
|
298
|
+
new RomanEntry("ho", "ほ", 0),
|
|
299
|
+
new RomanEntry("ba", "ば", 0),
|
|
300
|
+
new RomanEntry("bi", "び", 0),
|
|
301
|
+
new RomanEntry("bu", "ぶ", 0),
|
|
302
|
+
new RomanEntry("be", "べ", 0),
|
|
303
|
+
new RomanEntry("bo", "ぼ", 0),
|
|
304
|
+
new RomanEntry("pa", "ぱ", 0),
|
|
305
|
+
new RomanEntry("pi", "ぴ", 0),
|
|
306
|
+
new RomanEntry("pu", "ぷ", 0),
|
|
307
|
+
new RomanEntry("pe", "ぺ", 0),
|
|
308
|
+
new RomanEntry("po", "ぽ", 0),
|
|
309
|
+
new RomanEntry("ma", "ま", 0),
|
|
310
|
+
new RomanEntry("mi", "み", 0),
|
|
311
|
+
new RomanEntry("mu", "む", 0),
|
|
312
|
+
new RomanEntry("me", "め", 0),
|
|
313
|
+
new RomanEntry("mo", "も", 0),
|
|
314
|
+
new RomanEntry("xya", "ゃ", 0),
|
|
315
|
+
new RomanEntry("lya", "ゃ", 0),
|
|
316
|
+
new RomanEntry("ya", "や", 0),
|
|
317
|
+
new RomanEntry("wyi", "ゐ", 0),
|
|
318
|
+
new RomanEntry("xyu", "ゅ", 0),
|
|
319
|
+
new RomanEntry("lyu", "ゅ", 0),
|
|
320
|
+
new RomanEntry("yu", "ゆ", 0),
|
|
321
|
+
new RomanEntry("wye", "ゑ", 0),
|
|
322
|
+
new RomanEntry("xyo", "ょ", 0),
|
|
323
|
+
new RomanEntry("lyo", "ょ", 0),
|
|
324
|
+
new RomanEntry("yo", "よ", 0),
|
|
325
|
+
new RomanEntry("ra", "ら", 0),
|
|
326
|
+
new RomanEntry("ri", "り", 0),
|
|
327
|
+
new RomanEntry("ru", "る", 0),
|
|
328
|
+
new RomanEntry("re", "れ", 0),
|
|
329
|
+
new RomanEntry("ro", "ろ", 0),
|
|
330
|
+
new RomanEntry("xwa", "ゎ", 0),
|
|
331
|
+
new RomanEntry("lwa", "ゎ", 0),
|
|
332
|
+
new RomanEntry("wa", "わ", 0),
|
|
333
|
+
new RomanEntry("wi", "うぃ", 0),
|
|
334
|
+
new RomanEntry("we", "うぇ", 0),
|
|
335
|
+
new RomanEntry("wo", "を", 0),
|
|
336
|
+
new RomanEntry("wha", "うぁ", 0),
|
|
337
|
+
new RomanEntry("whi", "うぃ", 0),
|
|
338
|
+
new RomanEntry("whu", "う", 0),
|
|
339
|
+
new RomanEntry("whe", "うぇ", 0),
|
|
340
|
+
new RomanEntry("who", "うぉ", 0)
|
|
341
|
+
]
|
|
342
|
+
.sort((a, b) => a.index - b.index);
|
|
343
|
+
const ROMAN_INDEXES = ROMAN_ENTRIES.map(e => e.index);
|
|
344
|
+
class RomajiPredictiveResult {
|
|
345
|
+
constructor(estaglishedHiragana, predictiveSuffixes) {
|
|
346
|
+
this.estaglishedHiragana = estaglishedHiragana;
|
|
347
|
+
this.predictiveSuffixes = predictiveSuffixes;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function romajiToHiragana(romaji) {
|
|
351
|
+
if (romaji.length == 0) {
|
|
352
|
+
return "";
|
|
353
|
+
}
|
|
354
|
+
let hiragana = "";
|
|
355
|
+
let start = 0;
|
|
356
|
+
let end = 1;
|
|
357
|
+
while (start < romaji.length) {
|
|
358
|
+
let lastFound = -1;
|
|
359
|
+
let lower = 0;
|
|
360
|
+
let upper = ROMAN_INDEXES.length;
|
|
361
|
+
while (upper - lower > 1 && end <= romaji.length) {
|
|
362
|
+
const lowerKey = RomanEntry._calculateIndex(romaji, start, end);
|
|
363
|
+
lower = (0, utils_1.binarySearch)(ROMAN_INDEXES, lower, upper, lowerKey);
|
|
364
|
+
if (lower >= 0) {
|
|
365
|
+
lastFound = lower;
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
lower = -lower - 1;
|
|
369
|
+
}
|
|
370
|
+
const upperKey = lowerKey + (1 << (32 - 8 * (end - start)));
|
|
371
|
+
upper = (0, utils_1.binarySearch)(ROMAN_INDEXES, lower, upper, upperKey);
|
|
372
|
+
if (upper < 0) {
|
|
373
|
+
upper = -upper - 1;
|
|
374
|
+
}
|
|
375
|
+
end++;
|
|
376
|
+
}
|
|
377
|
+
if (lastFound >= 0) {
|
|
378
|
+
const entry = ROMAN_ENTRIES[lastFound];
|
|
379
|
+
hiragana = hiragana + entry.hiragana;
|
|
380
|
+
start = start + entry.roman.length - entry.remain;
|
|
381
|
+
end = start + 1;
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
hiragana = hiragana + romaji.charAt(start);
|
|
385
|
+
start++;
|
|
386
|
+
end = start + 1;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return hiragana;
|
|
390
|
+
}
|
|
391
|
+
exports.romajiToHiragana = romajiToHiragana;
|
|
392
|
+
function findRomanEntryPredicatively(roman, offset) {
|
|
393
|
+
let lastFound = -1;
|
|
394
|
+
let startIndex = 0;
|
|
395
|
+
let endIndex = ROMAN_INDEXES.length;
|
|
396
|
+
for (let i = 0; i < 4; i++) {
|
|
397
|
+
if (roman.length <= offset + i) {
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
const startKey = RomanEntry._calculateIndex(roman, offset, offset + i + 1);
|
|
401
|
+
startIndex = (0, utils_1.binarySearch)(ROMAN_INDEXES, startIndex, endIndex, startKey);
|
|
402
|
+
if (startIndex >= 0) {
|
|
403
|
+
lastFound = startIndex;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
startIndex = -startIndex - 1;
|
|
407
|
+
}
|
|
408
|
+
const endKey = startKey + (1 << (24 - 8 * i));
|
|
409
|
+
endIndex = (0, utils_1.binarySearch)(ROMAN_INDEXES, startIndex, endIndex, endKey);
|
|
410
|
+
if (endIndex < 0) {
|
|
411
|
+
endIndex = -endIndex - 1;
|
|
412
|
+
}
|
|
413
|
+
if (endIndex - startIndex == 1) {
|
|
414
|
+
return new Set([ROMAN_ENTRIES[startIndex]]);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const result = new Set();
|
|
418
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
419
|
+
result.add(ROMAN_ENTRIES[i]);
|
|
420
|
+
}
|
|
421
|
+
return result;
|
|
422
|
+
}
|
|
423
|
+
exports.findRomanEntryPredicatively = findRomanEntryPredicatively;
|
|
424
|
+
function romajiToHiraganaPredictively(romaji) {
|
|
425
|
+
if (romaji.length == 0) {
|
|
426
|
+
return new RomajiPredictiveResult("", new Set([""]));
|
|
427
|
+
}
|
|
428
|
+
let hiragana = "";
|
|
429
|
+
let start = 0;
|
|
430
|
+
let end = 1;
|
|
431
|
+
while (start < romaji.length) {
|
|
432
|
+
let lastFound = -1;
|
|
433
|
+
let lower = 0;
|
|
434
|
+
let upper = ROMAN_INDEXES.length;
|
|
435
|
+
while (upper - lower > 1 && end <= romaji.length) {
|
|
436
|
+
const lowerKey = RomanEntry._calculateIndex(romaji, start, end);
|
|
437
|
+
lower = (0, utils_1.binarySearch)(ROMAN_INDEXES, lower, upper, lowerKey);
|
|
438
|
+
if (lower >= 0) {
|
|
439
|
+
lastFound = lower;
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
lower = -lower - 1;
|
|
443
|
+
}
|
|
444
|
+
const upperKey = lowerKey + (1 << (32 - 8 * (end - start)));
|
|
445
|
+
upper = (0, utils_1.binarySearch)(ROMAN_INDEXES, lower, upper, upperKey);
|
|
446
|
+
if (upper < 0) {
|
|
447
|
+
upper = -upper - 1;
|
|
448
|
+
}
|
|
449
|
+
end++;
|
|
450
|
+
}
|
|
451
|
+
if (end > romaji.length && upper - lower > 1) {
|
|
452
|
+
const set = new Set();
|
|
453
|
+
for (let i = lower; i < upper; i++) {
|
|
454
|
+
const re = ROMAN_ENTRIES[i];
|
|
455
|
+
if (re.remain > 0) {
|
|
456
|
+
let set2 = findRomanEntryPredicatively(romaji, end - 1 - re.remain);
|
|
457
|
+
for (let re2 of set2) {
|
|
458
|
+
if (re2.remain == 0) {
|
|
459
|
+
set.add(re.hiragana + re2.hiragana);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
set.add(re.hiragana);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return new RomajiPredictiveResult(hiragana.toString(), set);
|
|
468
|
+
}
|
|
469
|
+
if (lastFound >= 0) {
|
|
470
|
+
const entry = ROMAN_ENTRIES[lastFound];
|
|
471
|
+
hiragana = hiragana + entry.hiragana;
|
|
472
|
+
start = start + entry.roman.length - entry.remain;
|
|
473
|
+
end = start + 1;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
hiragana = hiragana + romaji.charAt(start);
|
|
477
|
+
start++;
|
|
478
|
+
end = start + 1;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return new RomajiPredictiveResult(hiragana.toString(), new Set([""]));
|
|
482
|
+
}
|
|
483
|
+
exports.romajiToHiraganaPredictively = romajiToHiraganaPredictively;
|
|
484
|
+
//# sourceMappingURL=RomajiProcessor.js.map
|