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: trunk, fr
08:37
[graphspell] getSuggestions: always sort first list found, assuming that list 1 and 2 might be empty check-in: 90977551b1 user: olr tags: trunk, graphspell
08:35
[fr] ajustements check-in: bffc11601b user: olr tags: trunk, fr
Changes

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

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
                this.nDistLimit = Math.min(this.nDistLimit, this.nMinDist+1);
            }
        }
    }

    getSuggestions (nSuggLimit=10) {
        // return a list of suggestions
        if (this.dSugg.get(0).length > 1) {
            // we sort the better results with the original word
            this.dSugg.get(0).sort((a, b) => { return str_transform.distanceDamerauLevenshtein(this.sWord, a) - str_transform.distanceDamerauLevenshtein(this.sWord, b); });
        }
        else if (this.dSugg.get(1).length > 1) {
            this.dSugg.get(1).sort((a, b) => { return str_transform.distanceDamerauLevenshtein(this.sWord, a) - str_transform.distanceDamerauLevenshtein(this.sWord, b); });
        }
        let lRes = [];

        for (let [nDist, lSugg] of this.dSugg.entries()) {
            if (nDist > this.nDistLimit) {
                break;




            }
            lRes.push(...lSugg);
            if (lRes.length > nSuggLimit) {
                break;
            }
        }
        if (this.sWord.gl_isUpperCase()) {







<
<
<
<
<
<
<

>



>
>
>
>







55
56
57
58
59
60
61







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
                this.nDistLimit = Math.min(this.nDistLimit, this.nMinDist+1);
            }
        }
    }

    getSuggestions (nSuggLimit=10) {
        // return a list of suggestions







        let lRes = [];
        let bFirstListSorted = false;
        for (let [nDist, lSugg] of this.dSugg.entries()) {
            if (nDist > this.nDistLimit) {
                break;
            }
            if (!bFirstListSorted && lSugg.length > 1) {
                lRes.sort((a, b) => { return str_transform.distanceDamerauLevenshtein(this.sWord, a) - str_transform.distanceDamerauLevenshtein(this.sWord, b); });
                bFirstListSorted = true;
            }
            lRes.push(...lSugg);
            if (lRes.length > nSuggLimit) {
                break;
            }
        }
        if (this.sWord.gl_isUpperCase()) {

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

69
70
71
72
73
74
75
76
77
78
79
80

81
82




83
84
85
86
87
88
89
90
91
92
                if nDist < self.nMinDist:
                    self.nMinDist = nDist
                self.nDistLimit = min(self.nDistLimit, self.nMinDist+1)

    def getSuggestions (self, nSuggLimit=10):
        "return a list of suggestions"
        # we sort the better results with the original word
        if len(self.dSugg[0]) > 1:
            self.dSugg[0].sort(key=lambda sSugg: st.distanceDamerauLevenshtein(self.sWord, sSugg))
        elif len(self.dSugg[1]) > 1:
            self.dSugg[1].sort(key=lambda sSugg: st.distanceDamerauLevenshtein(self.sWord, sSugg))
        lRes = self.dSugg.pop(0)

        for nDist, lSugg in self.dSugg.items():
            if nDist <= self.nDistLimit:




                lRes.extend(lSugg)
                if len(lRes) > nSuggLimit:
                    break
        if self.sWord.isupper():
            lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg.upper(), lRes))) # use dict, when Python 3.6+
        elif self.sWord[0:1].isupper():
            # dont’ use <.istitle>
            lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes))) # use dict, when Python 3.6+
        return lRes[:nSuggLimit]








<
<
<
<
|
>

|
>
>
>
>
|
|
|







69
70
71
72
73
74
75




76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
                if nDist < self.nMinDist:
                    self.nMinDist = nDist
                self.nDistLimit = min(self.nDistLimit, self.nMinDist+1)

    def getSuggestions (self, nSuggLimit=10):
        "return a list of suggestions"
        # we sort the better results with the original word




        lRes = []
        bFirstListSorted = False
        for nDist, lSugg in self.dSugg.items():
            if nDist > self.nDistLimit:
                break
            if not bFirstListSorted and len(lSugg) > 1:
                lSugg.sort(key=lambda sSugg: st.distanceDamerauLevenshtein(self.sWord, sSugg))
                bFirstListSorted = True
            lRes.extend(lSugg)
            if len(lRes) > nSuggLimit:
                break
        if self.sWord.isupper():
            lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg.upper(), lRes))) # use dict, when Python 3.6+
        elif self.sWord[0:1].isupper():
            # dont’ use <.istitle>
            lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes))) # use dict, when Python 3.6+
        return lRes[:nSuggLimit]