Overview
Comment: | [core][js] ibdawg: object SuggResult |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | core | spellsugg |
Files: | files | file ages | folders |
SHA3-256: |
922f22848dd1438393b5495c4be12f30 |
User & Date: | olr on 2017-11-08 14:59:03 |
Other Links: | branch diff | manifest | tags |
Context
2017-11-08
| ||
15:14 | [core][js] ibdawg: use SuggResult check-in: 2f30b8f748 user: olr tags: core, spellsugg | |
14:59 | [core][js] ibdawg: object SuggResult check-in: 922f22848d user: olr tags: core, spellsugg | |
13:32 | [core][js] ibdawg: suggest (adaptation from Python code) check-in: 1ef26c175b user: olr tags: core, spellsugg | |
Changes
Modified gc_core/js/ibdawg.js from [bd697d0db3] to [f06dd595e9].
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | // Don’t remove <string>. Necessary in TB. ${string} ${map} ${set} class IBDAWG { // INDEXABLE BINARY DIRECT ACYCLIC WORD GRAPH constructor (sDicName, sPath="") { try { let sURL = (sPath !== "") ? sPath + "/" + sDicName : "resource://grammalecte/_dictionaries/"+sDicName; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | // Don’t remove <string>. Necessary in TB. ${string} ${map} ${set} class SuggResult { // Structure for storing, classifying and filtering suggestions constructor (sWord, nDistLimit=-1) { this.sWord = sWord; this.sCleanWord = char_player.cleanWord(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, []] ]); } addSugg (sSugg, nDeep=0) { // add a suggestion if (!this.aSugg.has(sSugg)) { let nDist = str_transform.distanceDamerauLevenshtein(this.sCleanWord, char_player.cleanWord(sSugg)); if (nDist <= this.nDistLimit) { if (!this.dSugg.has(nDist)) { this.dSugg.set(nDist, []); } this.dSugg.get(nDist).push(sSugg); this.aSugg.add(sSugg); if (nDist < this.nMinDist) { this.nMinDist = nDist; } this.nDistLimit = Math.min(this.nDistLimit, this.nMinDist+2); } } } getSuggestions (nSuggLimit=10, nDistLimit=-1) { // return a list of suggestions let lRes = []; if (this.dSugg.get(0).length) { // we sort the better results with the original word let dDistTemp = new Map(); lRes.forEach((sSugg) => { dDistTemp.set(sSugg, str_transform.distanceDamerauLevenshtein(this.sWord, sSugg)); }); lRes = lRes.sort((sA, sB) => { return dDistTemp.get(sA) - dDistTemp.get(sB); }); dDistTemp.clear(); } for (let lSugg of this.dSugg.values()) { for (let sSugg of lSugg) { lRes.push(sSugg); } if (lRes.length > nSuggLimit) { break; } } lRes = char_player.filterSugg(lRes); if (this.sWord.gl_isTitle()) { lRes = lRes.map((sSugg) => { return sSugg.gl_toCapitalize(); }); } else if (this.sWord.gl_isUpperCase()) { lRes = lRes.map((sSugg) => { return sSugg.toUpperCase(); }); } return lRes.slice(0, nSuggLimit); } reset () { this.aSugg.clear(); this.dSugg.clear(); } } class IBDAWG { // INDEXABLE BINARY DIRECT ACYCLIC WORD GRAPH constructor (sDicName, sPath="") { try { let sURL = (sPath !== "") ? sPath + "/" + sDicName : "resource://grammalecte/_dictionaries/"+sDicName; |
︙ | ︙ |