37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
*/
if (!this.sHeader.startsWith("/pyfsa/")) {
throw TypeError("# Error. Not a pyfsa binary dictionary. Header: " + this.sHeader);
}
if (!(this.nVersion == "1" || this.nVersion == "2" || this.nVersion == "3")) {
throw RangeError("# Error. Unknown dictionary version: " + this.nVersion);
}
this.dChar = helpers.objectToMap(this.dChar);
//this.byDic = new Uint8Array(this.byDic); // not quicker, even slower
if (this.cStemming == "S") {
this.funcStemming = str_transform.getStemFromSuffixCode;
} else if (this.cStemming == "A") {
this.funcStemming = str_transform.getStemFromAffixCode;
} else {
|
|
>
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
*/
if (!this.sHeader.startsWith("/pyfsa/")) {
throw TypeError("# Error. Not a pyfsa binary dictionary. Header: " + this.sHeader);
}
if (!(this.nVersion == "1" || this.nVersion == "2" || this.nVersion == "3")) {
throw RangeError("# Error. Unknown dictionary version: " + this.nVersion);
}
// <dChar> to get the value of an arc, <dCharVal> to get the char of an arc with its value
this.dChar = helpers.objectToMap(this.dChar);
this.dCharVal = this.dChar.gl_reverse();
//this.byDic = new Uint8Array(this.byDic); // not quicker, even slower
if (this.cStemming == "S") {
this.funcStemming = str_transform.getStemFromSuffixCode;
} else if (this.cStemming == "A") {
this.funcStemming = str_transform.getStemFromAffixCode;
} else {
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
_getTails (iAddr, sTail="", n=2) {
// return a list of suffixes ending at a distance of <n> from <iAddr>
let aTails = new Set();
for (let [nVal, jAddr] of this._getArcs(iAddr)) {
if (nVal < this.nChar) {
if (this._convBytesToInteger(this.byDic.slice(jAddr, jAddr+this.nBytesArc)) & this._finalNodeMask) {
aTails.add(sTail + this.dChar.get(nVal));
}
if (n && aTails.size == 0) {
aTails.gl_update(this._getTails(jAddr, sTail+this.dChar.get(nVal), n-1));
}
}
}
return aTails;
}
_suggestWithCrushedUselessChars (sWord, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=false) {
|
|
|
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
_getTails (iAddr, sTail="", n=2) {
// return a list of suffixes ending at a distance of <n> from <iAddr>
let aTails = new Set();
for (let [nVal, jAddr] of this._getArcs(iAddr)) {
if (nVal < this.nChar) {
if (this._convBytesToInteger(this.byDic.slice(jAddr, jAddr+this.nBytesArc)) & this._finalNodeMask) {
aTails.add(sTail + this.dCharVal.get(nVal));
}
if (n && aTails.size == 0) {
aTails.gl_update(this._getTails(jAddr, sTail+this.dCharVal.get(nVal), n-1));
}
}
}
return aTails;
}
_suggestWithCrushedUselessChars (sWord, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=false) {
|
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
}
return aSugg;
}
* _getSimilarArcsAndCrushedChars (cChar, iAddr) {
// generator: yield similar char of <cChar> and address of the following node
for (let [nVal, jAddr] of this._getArcs(iAddr)) {
if (this.dChar.get(nVal, null) in char_player.aVovels) {
yield [this.dChar[nVal], jAddr];
}
}
yield* this._getSimilarArcs(cChar, iAddr);
}
// morph (sWord) {
// is defined in constructor
|
|
|
|
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
}
return aSugg;
}
* _getSimilarArcsAndCrushedChars (cChar, iAddr) {
// generator: yield similar char of <cChar> and address of the following node
for (let [nVal, jAddr] of this._getArcs(iAddr)) {
if (this.dCharVal.get(nVal, null) in char_player.aVovels) {
yield [this.dCharVal[nVal], jAddr];
}
}
yield* this._getSimilarArcs(cChar, iAddr);
}
// morph (sWord) {
// is defined in constructor
|