Overview
Comment: | [graphspell][js] performance tests |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | graphspell |
Files: | files | file ages | folders |
SHA3-256: |
14ed269c7ca9ee20dd366bccbd48c13e |
User & Date: | olr on 2018-10-09 08:54:06 |
Other Links: | manifest | tags |
Context
2018-10-09
| ||
11:07 | [graphspell][js] useless comments check-in: 4d2953e2f6 user: olr tags: trunk, graphspell | |
08:54 | [graphspell][js] performance tests check-in: 14ed269c7c user: olr tags: trunk, graphspell | |
2018-10-06
| ||
13:46 | [graphspell] better quicker spelling suggestions: check 2grams existence check-in: f3f1cc9e30 user: olr tags: trunk, graphspell | |
Changes
Modified graphspell-js/ibdawg.js from [c786a97f15] to [c77827bdfd].
︙ | ︙ | |||
136 137 138 139 140 141 142 143 144 145 146 147 148 149 | if (!(this.nCompressionMethod == 1 || this.nCompressionMethod == 2 || this.nCompressionMethod == 3)) { throw RangeError("# Error. Unknown dictionary compression method: " + this.nCompressionMethod); } // <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.a2grams = new Set(this.l2grams); if (this.cStemming == "S") { this.funcStemming = str_transform.changeWordWithSuffixCode; } else if (this.cStemming == "A") { this.funcStemming = str_transform.changeWordWithAffixCode; } else { this.funcStemming = str_transform.noStemming; | > | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | if (!(this.nCompressionMethod == 1 || this.nCompressionMethod == 2 || this.nCompressionMethod == 3)) { throw RangeError("# Error. Unknown dictionary compression method: " + this.nCompressionMethod); } // <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.a2grams = new Set(this.l2grams); //console.log(this.l2grams); if (this.cStemming == "S") { this.funcStemming = str_transform.changeWordWithSuffixCode; } else if (this.cStemming == "A") { this.funcStemming = str_transform.changeWordWithAffixCode; } else { this.funcStemming = str_transform.noStemming; |
︙ | ︙ | |||
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | } } return l; } suggest (sWord, nSuggLimit=10) { // returns a array of 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); 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 } ); } return aSugg; } _suggest (oSuggResult, sRemain, nMaxSwitch=0, nMaxDel=0, nMaxHardRepl=0, nMaxJump=0, nDist=0, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=false) { // returns a set of suggestions // recursive function if (sRemain == "") { | > > > | 310 311 312 313 314 315 316 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 | } } return l; } suggest (sWord, nSuggLimit=10) { // returns a array of suggestions for <sWord> //const t0 = Date.now(); 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); 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 } ); } //const t1 = Date.now(); //console.log("Suggestions for " + sWord + " in " + ((t1-t0)/1000).toString() + " s"); return aSugg; } _suggest (oSuggResult, sRemain, nMaxSwitch=0, nMaxDel=0, nMaxHardRepl=0, nMaxJump=0, nDist=0, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=false) { // returns a set of suggestions // recursive function if (sRemain == "") { |
︙ | ︙ | |||
400 401 402 403 404 405 406 | } } isNgramsOK (sChars) { if (sChars.length != 2) { return true; } | | > | 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | } } isNgramsOK (sChars) { if (sChars.length != 2) { return true; } return this.a2grams.has(sChars); //slower than indexOf in an Array? //return this.l2grams.indexOf(sChars) !== false; } * _getCharArcs (iAddr) { // generator: yield all chars and addresses from node at address <iAddr> for (let [nVal, jAddr] of this._getArcs(iAddr)) { if (nVal <= this.nChar) { yield [this.dCharVal.get(nVal), jAddr]; |
︙ | ︙ |