24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
constructor (sWord, nDistLimit=-1) {
this.sWord = sWord;
this.sSimplifiedWord = char_player.simplifyWord(sWord);
this.nDistLimit = (nDistLimit >= 0) ? nDistLimit : Math.floor(sWord.length / 3) + 1;
this.nMinDist = 1000;
this.aSugg = new Set();
this.dSugg = new Map([ [0, []], [1, []], [2, []] ]);
}
addSugg (sSugg, nDeep=0) {
// add a suggestion
if (!this.aSugg.has(sSugg)) {
let nDist = str_transform.distanceDamerauLevenshtein(this.sSimplifiedWord, char_player.simplifyWord(sSugg));
if (nDist <= this.nDistLimit) {
if (!this.dSugg.has(nDist)) {
this.dSugg.set(nDist, []);
}
this.dSugg.get(nDist).push(sSugg);
|
>
>
>
>
>
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
constructor (sWord, nDistLimit=-1) {
this.sWord = sWord;
this.sSimplifiedWord = char_player.simplifyWord(sWord);
this.nDistLimit = (nDistLimit >= 0) ? nDistLimit : Math.floor(sWord.length / 3) + 1;
this.nMinDist = 1000;
this.aSugg = new Set();
this.dSugg = new Map([ [0, []], [1, []], [2, []] ]);
this.aAllSugg = new Set(); // all found words even those refused
}
addSugg (sSugg, nDeep=0) {
// add a suggestion
if (this.aAllSugg.has(sSugg)) {
return;
}
this.aAllSugg.add(sSugg);
if (!this.aSugg.has(sSugg)) {
let nDist = str_transform.distanceDamerauLevenshtein(this.sSimplifiedWord, char_player.simplifyWord(sSugg));
if (nDist <= this.nDistLimit) {
if (!this.dSugg.has(nDist)) {
this.dSugg.set(nDist, []);
}
this.dSugg.get(nDist).push(sSugg);
|