Grammalecte  Check-in [ecae0c75b7]

Overview
Comment:[core][js] calculate Damerau-Levenshtein distance only once
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: ecae0c75b7de0f6014ffadfb162a50b0a1b1d1919a0ad7a0b88ee4696771c71b
User & Date: olr on 2017-09-15 13:33:37
Other Links: manifest | tags
Context
2017-09-15
14:58
[fx] WebExt: smaller text formatter check-in: d4a86b753d user: olr tags: trunk, fx
13:33
[core][js] calculate Damerau-Levenshtein distance only once check-in: ecae0c75b7 user: olr tags: trunk, core
13:12
[core][js] fix Damerau-Levenshtein distance check-in: 4486055937 user: olr tags: trunk, core
Changes

Modified gc_core/js/char_player.js from [6d45a56753] to [cdf575879a].

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
                        matrix[i-1][j-1] + nCost    // Substitution
                    );
                    if (i > 1 && j > 1 && s1[i] == s2[j-1] && s1[i-1] == s2[j]) {
                        matrix[i][j] = Math.min(matrix[i][j], matrix[i-2][j-2] + nCost);  // Transposition
                    }
                }
            }
            console.log(s2 + ": " + matrix[nLen1][nLen2]);
            return matrix[nLen1][nLen2];
        }
        catch (e) {
            helpers.logerror(e);
        }
    },








|







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
                        matrix[i-1][j-1] + nCost    // Substitution
                    );
                    if (i > 1 && j > 1 && s1[i] == s2[j-1] && s1[i-1] == s2[j]) {
                        matrix[i][j] = Math.min(matrix[i][j], matrix[i-2][j-2] + nCost);  // Transposition
                    }
                }
            }
            //console.log(s2 + ": " + matrix[nLen1][nLen2]);
            return matrix[nLen1][nLen2];
        }
        catch (e) {
            helpers.logerror(e);
        }
    },

Modified gc_core/js/ibdawg.js from [8f764d2989] to [8b6ee4e0fe].

188
189
190
191
192
193
194
195
196
197


198
199
200
201
202
203
204
        }
        // Set to Array
        aSugg = Array.from(aSugg);
        aSugg = aSugg.filter((sSugg) => { return !sSugg.endsWith("è") && !sSugg.endsWith("È"); }); // fr language 
        if (sWord.gl_isTitle()) {
            aSugg = aSugg.map((sSugg) => { return sSugg.gl_toCapitalize(); });
        }
        return aSugg.sort((sA, sB) => {
            return char_player.distanceDamerauLevenshtein(sWord, sA) - char_player.distanceDamerauLevenshtein(sWord, sB);
        }).slice(0, nMaxSugg);


    }

    _suggest (sRemain, nMaxDel=0, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=false) {
        // returns a set of suggestions
        // recursive function
        //show(nDeep, sNewWord + ":" + sRemain)
        let aSugg = new Set();







|
|
|
>
>







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
        }
        // Set to Array
        aSugg = Array.from(aSugg);
        aSugg = aSugg.filter((sSugg) => { return !sSugg.endsWith("è") && !sSugg.endsWith("È"); }); // fr language 
        if (sWord.gl_isTitle()) {
            aSugg = aSugg.map((sSugg) => { return sSugg.gl_toCapitalize(); });
        }
        let dDistTemp = new Map();
        aSugg.forEach((sSugg) => { dDistTemp.set(sSugg, char_player.distanceDamerauLevenshtein(sWord, sSugg)); });
        aSugg = aSugg.sort((sA, sB) => { return dDistTemp.get(sA) - dDistTemp.get(sB); }).slice(0, nMaxSugg);
        dDistTemp.clear();
        return aSugg;
    }

    _suggest (sRemain, nMaxDel=0, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=false) {
        // returns a set of suggestions
        // recursive function
        //show(nDeep, sNewWord + ":" + sRemain)
        let aSugg = new Set();