Overview
Comment: | [graphspell] new suggestion mechanism for Javascript too |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | graphspell |
Files: | files | file ages | folders |
SHA3-256: |
ec295f726fa6ef8aa64ca1da7f22d2f3 |
User & Date: | olr on 2025-09-14 14:31:40 |
Other Links: | manifest | tags |
Context
2025-09-14
| ||
16:01 | [fr] config.ini: dictionnaires 7.7, Grammalecte 2.3 Leaf check-in: a74fcc98bb user: olr tags: trunk, fr | |
14:31 | [graphspell] new suggestion mechanism for Javascript too check-in: ec295f726f user: olr tags: trunk, graphspell | |
13:10 | [build][core][lo] update minimal requirements: Python 3.7, LO 6.4 check-in: 3e14557ae0 user: olr tags: trunk, core, build, lo | |
Changes
Modified graphspell-js/ibdawg.js from [9375ebc47a] to [abe9c98a1b].
︙ | ︙ | |||
21 22 23 24 25 26 27 | class SuggResult { // Structure for storing, classifying and filtering suggestions constructor (sWord, nSuggLimit=10, nDistLimit=-1) { this.sWord = sWord; this.sSimplifiedWord = str_transform.simplifyWord(sWord); | | < | | < < | | | < | | < < < | < < > | | | > | > < < | | | | < < < < < < < < < < < < < < < < < < | 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 | class SuggResult { // Structure for storing, classifying and filtering suggestions constructor (sWord, nSuggLimit=10, nDistLimit=-1) { this.sWord = sWord; this.sSimplifiedWord = str_transform.simplifyWord(sWord); this.nDistLimit = (nDistLimit >= 0) ? nDistLimit : Math.floor(sWord.length / 3) + 1; // maximum accepted distance, used in suggest() this.nMinDist = 1000; // Temporary sets this.aAllSugg = new Set(); // All suggestions, even the one rejected this.dAccSugg = new Map(); // Accepted suggestions // Parameters this.nSuggLimit = nSuggLimit; // number of returned suggestions this.nTempSuggLimit = nSuggLimit * 6; // limit of accepted suggestions (ends search over this limit) } addSugg (sSugg) { // add a suggestion if (this.aAllSugg.has(sSugg)) { return; } this.aAllSugg.add(sSugg); //console.log("Grammalecte: " + sSugg); let nSimDist = str_transform.distanceSift4(this.sSimplifiedWord, str_transform.simplifyWord(sSugg)); if (nSimDist < this.nMinDist) { this.nMinDist = nSimDist; } if (nSimDist <= this.nMinDist+1) { let nDist = Math.min(str_transform.distanceDamerauLevenshtein(this.sWord, sSugg), str_transform.distanceDamerauLevenshtein(this.sSimplifiedWord, str_transform.simplifyWord(sSugg))); this.dAccSugg.set(sSugg, Math.min(nDist, nSimDist+1)); if (this.dAccSugg.size > this.nTempSuggLimit) { this.nDistLimit = -1; // suggest() ends searching when this variable = -1 } } this.nDistLimit = Math.min(this.nDistLimit, this.nMinDist+1); //console.log(this.dAccSugg); } getSuggestions () { //// return a list of suggestions // sort according to distance let lRes = []; let lResTmp = [...this.dAccSugg.entries()].sort((a, b) => { return a[1] - b[1]; }); let nSize = Math.min(this.nSuggLimit, lResTmp.length); for (let i=0; i < nSize; i++){ lRes.push(lResTmp[i][0]); } // casing 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()) { |
︙ | ︙ |
Modified graphspell/ibdawg.py from [979c697260] to [a6af4bb96b].
︙ | ︙ | |||
39 40 41 42 43 44 45 | class SuggResult: """Structure for storing, classifying and filtering suggestions""" def __init__ (self, sWord, nSuggLimit=10, nDistLimit=-1): self.sWord = sWord self.sSimplifiedWord = st.simplifyWord(sWord) | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | class SuggResult: """Structure for storing, classifying and filtering suggestions""" def __init__ (self, sWord, nSuggLimit=10, nDistLimit=-1): self.sWord = sWord self.sSimplifiedWord = st.simplifyWord(sWord) self.nDistLimit = nDistLimit if nDistLimit >= 0 else (len(sWord) // 3) + 1 # maximum accepted distance, used in suggest() self.nMinDist = 1000 # Temporary sets self.aAllSugg = set() # All suggestions, even the one rejected self.dAccSugg = {} # Accepted suggestions # Parameters self.nSuggLimit = nSuggLimit # number of returned suggestions self.nTempSuggLimit = nSuggLimit * 6 # limit of accepted suggestions (ends search over this limit) |
︙ | ︙ |