Grammalecte  Check-in [90977551b1]

Overview
Comment:[graphspell] getSuggestions: always sort first list found, assuming that list 1 and 2 might be empty
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | graphspell
Files: files | file ages | folders
SHA3-256: 90977551b1bd19e3568548b4fb177c564daba4dadf855b91e17eeb2885539cac
User & Date: olr on 2020-09-09 08:37:02
Other Links: manifest | tags
Context
2020-09-09
11:30
[fr] faux positif check-in: dbb2b4e13c user: olr tags: fr, trunk
08:37
[graphspell] getSuggestions: always sort first list found, assuming that list 1 and 2 might be empty check-in: 90977551b1 user: olr tags: graphspell, trunk
08:35
[fr] ajustements check-in: bffc11601b user: olr tags: fr, trunk
Changes

Modified graphspell-js/ibdawg.js from [250621182e] to [544f660d8a].

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

Modified graphspell/ibdawg.py from [ca3736e14d] to [f1a1c3c7ab].

    69     69                   if nDist < self.nMinDist:
    70     70                       self.nMinDist = nDist
    71     71                   self.nDistLimit = min(self.nDistLimit, self.nMinDist+1)
    72     72   
    73     73       def getSuggestions (self, nSuggLimit=10):
    74     74           "return a list of suggestions"
    75     75           # we sort the better results with the original word
    76         -        if len(self.dSugg[0]) > 1:
    77         -            self.dSugg[0].sort(key=lambda sSugg: st.distanceDamerauLevenshtein(self.sWord, sSugg))
    78         -        elif len(self.dSugg[1]) > 1:
    79         -            self.dSugg[1].sort(key=lambda sSugg: st.distanceDamerauLevenshtein(self.sWord, sSugg))
    80         -        lRes = self.dSugg.pop(0)
           76  +        lRes = []
           77  +        bFirstListSorted = False
    81     78           for nDist, lSugg in self.dSugg.items():
    82         -            if nDist <= self.nDistLimit:
    83         -                lRes.extend(lSugg)
    84         -                if len(lRes) > nSuggLimit:
    85         -                    break
           79  +            if nDist > self.nDistLimit:
           80  +                break
           81  +            if not bFirstListSorted and len(lSugg) > 1:
           82  +                lSugg.sort(key=lambda sSugg: st.distanceDamerauLevenshtein(self.sWord, sSugg))
           83  +                bFirstListSorted = True
           84  +            lRes.extend(lSugg)
           85  +            if len(lRes) > nSuggLimit:
           86  +                break
    86     87           if self.sWord.isupper():
    87     88               lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg.upper(), lRes))) # use dict, when Python 3.6+
    88     89           elif self.sWord[0:1].isupper():
    89     90               # dont’ use <.istitle>
    90     91               lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes))) # use dict, when Python 3.6+
    91     92           return lRes[:nSuggLimit]
    92     93