@@ -25,11 +25,11 @@ class SuggResult { // Structure for storing, classifying and filtering suggestions constructor (sWord, nDistLimit=-1) { this.sWord = sWord; - this.sSimplifiedWord = char_player.simplifyWord(sWord); + this.sSimplifiedWord = str_transform.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 @@ -40,11 +40,11 @@ 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)); + let nDist = str_transform.distanceDamerauLevenshtein(this.sSimplifiedWord, str_transform.simplifyWord(sSugg)); if (nDist <= this.nDistLimit) { if (sSugg.includes(" ")) { // add 1 to distance for split suggestions nDist += 1; } if (!this.dSugg.has(nDist)) { @@ -77,11 +77,10 @@ lRes.push(...lSugg); if (lRes.length > nSuggLimit) { break; } } - lRes = char_player.filterSugg(lRes); if (this.sWord.gl_isUpperCase()) { lRes = lRes.map((sSugg) => { return sSugg.toUpperCase(); }); lRes = [...new Set(lRes)]; } else if (this.sWord.slice(0,1).gl_isUpperCase()) { @@ -195,10 +194,18 @@ throw ValueError("# Error: unknown code: " + this.nCompressionMethod); } //console.log(this.getInfo()); this.bAcronymValid = true; this.bNumAtLastValid = false; + + // lexicographer module ? + this.lexicographer = null; + // JS still sucks: we’ll try importation when importation will be available in Workers. Still waiting... + if (self && self.hasOwnProperty("lexgraph_"+this.sLangCode)) { // self is the Worker + this.lexicographer = self["lexgraph_"+this.sLangCode]; + } + } getInfo () { return ` Language: ${this.sLangName} Lang code: ${this.sLangCode} Dictionary name: ${this.sDicName}\n` + ` Compression method: ${this.nCompressionMethod} Date: ${this.sDate} Stemming: ${this.cStemming}FX\n` + @@ -326,11 +333,13 @@ // returns a array of suggestions for //console.time("Suggestions for " + sWord); sWord = str_transform.spellingNormalization(sWord); let sPfx = ""; let sSfx = ""; - [sPfx, sWord, sSfx] = char_player.cut(sWord); + if (this.lexicographer) { + [sPfx, sWord, sSfx] = this.lexicographer.split(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); @@ -338,10 +347,13 @@ this._splitTrailingNumbers(oSuggResult, sWord); } this._splitSuggest(oSuggResult, sWord); this._suggest(oSuggResult, sWord, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump); let aSugg = oSuggResult.getSuggestions(nSuggLimit); + if (this.lexicographer) { + aSugg = this.lexicographer.filterSugg(aSugg); + } if (sSfx || sPfx) { // we add what we removed return aSugg.map( (sSugg) => { return sPfx + sSugg + sSfx; } ); } //console.timeEnd("Suggestions for " + sWord); @@ -349,11 +361,11 @@ } _splitTrailingNumbers (oSuggResult, sWord) { let m = /^([a-zA-Zà-öÀ-Ö_ø-ÿØ-ßĀ-ʯfi-st][a-zA-Zà-öÀ-Ö_ø-ÿØ-ßĀ-ʯfi-st-]+)([0-9]+)$/.exec(sWord); if (m && !m[1].endsWith("-") && !m[1].endsWith("_")) { - oSuggResult.addSugg(m[1] + " " + char_player.numbersToExponent(m[2])); + oSuggResult.addSugg(m[1] + " " + str_transform.numbersToExponent(m[2])); } } _splitSuggest (oSuggResult, sWord) { // split at apostrophes