317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
-
+
+
+
+
-
+
-
+
+
+
|
if (sWord.gl_isUpperCase() && sWord.length > 1) {
l.push(...this.morph(sWord.gl_toCapitalize()));
}
}
return l;
}
suggest (sWord, nSuggLimit=10) {
suggest (sWord, nSuggLimit=10, bSplitTrailingNumbers=false) {
// returns a array of suggestions for <sWord>
//console.time("Suggestions for " + sWord);
sWord = char_player.spellingNormalization(sWord);
let sPfx = "";
let sSfx = "";
[sPfx, sWord, sSfx] = char_player.cut(sWord);
let nMaxSwitch = Math.max(Math.floor(sWord.length / 3), 1);
let nMaxDel = Math.floor(sWord.length / 5);
let nMaxHardRepl = Math.max(Math.floor((sWord.length - 5) / 4), 1);
let nMaxJump = Math.max(Math.floor(sWord.length / 4), 1);
let oSuggResult = new SuggResult(sWord);
if (bSplitTrailingNumbers) {
this._splitTrailingNumbers(oSuggResult, sWord);
}
this._splitSuggest(oSuggResult, sWord);
this._suggest(oSuggResult, sWord, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump);
let aSugg = oSuggResult.getSuggestions(nSuggLimit);
if (sSfx || sPfx) {
// we add what we removed
return aSugg.map( (sSugg) => { return sPfx + sSugg + sSfx; } );
}
//console.timeEnd("Suggestions for " + sWord);
return aSugg;
}
_splitSuggest (oSuggResult, sWord) {
_splitTrailingNumbers (oSuggResult, sWord) {
// split trailing numbers
let m = /^([a-zA-Zà-öÀ-Ö_ø-ÿØ-ßĀ-ʯfi-st][a-zA-Zà-öÀ-Ö_ø-ÿØ-ßĀ-ʯfi-st-]+)([0-9]+)$/.exec(sWord);
if (m) {
oSuggResult.addSugg(m[1] + " " + char_player.numbersToExponent(m[2]));
}
}
_splitSuggest (oSuggResult, sWord) {
// split at apostrophes
for (let cSplitter of "'’") {
if (sWord.includes(cSplitter)) {
let [sWord1, sWord2] = sWord.split(cSplitter, 2);
if (this.isValid(sWord1) && this.isValid(sWord2)) {
oSuggResult.addSugg(sWord1+" "+sWord2);
}
|