Grammalecte  Check-in [7d93db4a3b]

Overview
Comment:[graphsell][js] ibdawg: fix sort in getSuggestions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | graphspell
Files: files | file ages | folders
SHA3-256: 7d93db4a3b2de718d3f977f8dfad744412c1dbb3b368b534c5077d36e6ce507a
User & Date: olr on 2020-09-07 17:42:27
Other Links: manifest | tags
Context
2020-09-08
08:12
[graphspell][js] remove useless parameter and useless get/set check-in: e53fd4ae0e user: olr tags: graphspell, trunk
2020-09-07
17:42
[graphsell][js] ibdawg: fix sort in getSuggestions check-in: 7d93db4a3b user: olr tags: graphspell, trunk
17:41
[fr] ajustements check-in: 254188803f user: olr tags: fr, trunk
Changes

Modified graphspell-js/ibdawg.js from [25fa8fe973] to [027be60102].

    55     55                   this.nDistLimit = Math.min(this.nDistLimit, this.nMinDist+1);
    56     56               }
    57     57           }
    58     58       }
    59     59   
    60     60       getSuggestions (nSuggLimit=10, nDistLimit=-1) {
    61     61           // return a list of suggestions
    62         -        let lRes = [];
    63         -        if (this.dSugg.get(0).length) {
           62  +        if (this.dSugg.get(0).length > 1) {
    64     63               // we sort the better results with the original word
    65         -            let dDistTemp = new Map();
    66         -            lRes.forEach((sSugg) => { dDistTemp.set(sSugg, str_transform.distanceDamerauLevenshtein(this.sWord, sSugg)); });
    67         -            lRes = lRes.sort((sA, sB) => { return dDistTemp.get(sA) - dDistTemp.get(sB); });
    68         -            dDistTemp.clear();
           64  +            this.dSugg.set(0, [...this.dSugg.get(0)].sort((a, b) => { return str_transform.distanceDamerauLevenshtein(this.sWord, a) - str_transform.distanceDamerauLevenshtein(this.sWord, b); }));
    69     65           }
           66  +        else if (this.dSugg.get(1).length > 1) {
           67  +            this.dSugg.set(1, [...this.dSugg.get(1)].sort((a, b) => { return str_transform.distanceDamerauLevenshtein(this.sWord, a) - str_transform.distanceDamerauLevenshtein(this.sWord, b); }));
           68  +        }
           69  +        let lRes = [];
    70     70           for (let [nDist, lSugg] of this.dSugg.entries()) {
    71     71               if (nDist > this.nDistLimit) {
    72     72                   break;
    73     73               }
    74     74               lRes.push(...lSugg);
    75     75               if (lRes.length > nSuggLimit) {
    76     76                   break;