Grammalecte  Check-in [ebdbe42659]

Overview
Comment:[graphspell] function readableMorph()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | graphspell | salxg
Files: files | file ages | folders
SHA3-256: ebdbe426597f2d1349be216e0a30cb5ab7259756173e92415ee92bfe6396c92d
User & Date: olr on 2020-08-23 05:28:57
Other Links: branch diff | manifest | tags
Context
2020-08-23
06:26
merge trunk check-in: b4b3569231 user: olr tags: salxg
05:28
[graphspell] function readableMorph() check-in: ebdbe42659 user: olr tags: graphspell, salxg
05:28
[graphspell][js] update tags check-in: f6092331a8 user: olr tags: graphspell, salxg
Changes

Modified graphspell-js/spellchecker.js from [be4f6fe289] to [e42b82b880].

130
131
132
133
134
135
136
137
138
139
140
141
































142
143
144
145
146
147
148
    // Lexicographer

    loadLexicographer (sLangCode) {
        // load default suggestion module for <sLangCode>
        if (typeof(process) !== 'undefined') {
            this.lexicographer = require(`./lexgraph_${sLangCode}.js`);
        }
        else if (typeof(require) !== 'undefined') {
            this.lexicographer = require(`resource://grammalecte/graphspell/lexgraph_${sLangCode}.js`);
        }
    }


































    // Storage

    activateStorage () {
        this.bStorage = true;
    }








|
|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
    // Lexicographer

    loadLexicographer (sLangCode) {
        // load default suggestion module for <sLangCode>
        if (typeof(process) !== 'undefined') {
            this.lexicographer = require(`./lexgraph_${sLangCode}.js`);
        }
        else if (self && self.hasOwnProperty("lexgraph_"+sLangCode)) { // self is the Worker
            this.lexicographer = self["lexgraph_"+sLangCode];
        }
    }

    analyze (sWord) {
        // returns a list of words and their morphologies
        if (!this.lexicographer) {
            return [];
        }
        let lWordAndMorph = [];
        for (let sElem of this.lexicographer.split(sWord)) {
            if (sElem) {
                let lMorph = this.getMorph(sElem);
                let sLex = this.lexicographer.analyze(sElem)
                let aRes = [];
                if (sLex) {
                    aRes = [ [lMorph.join(" | "), sLex] ];
                } else {
                    for (let sMorph of lMorph) {
                        aRes.push([sMorph, this.lexicographer.formatTags(sMorph)]);
                    }
                }
                if (aRes.length > 0) {
                    lWordAndMorph.push([sElem, aRes]);
                }
            }
        }
        return lWordAndMorph;
    }

    readableMorph (sMorph) {
        if (!this.lexicographer) {
            return [];
        }
        return this.lexicographer.formatTags(sMorph);
    }

    // Storage

    activateStorage () {
        this.bStorage = true;
    }

Modified graphspell/spellchecker.py from [b9cca64fbd] to [ca24473f67].

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
123
124
125
126
127
128
129





130
131
132
133
134
135
136
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
        self.bCommunityDic = False

    def deactivatePersonalDictionary (self):
        "deactivate personal dictionary"
        self.bPersonalDic = False


    # Default suggestions

    def loadLexicographer (self, sLangCode):
        "load default suggestion module for <sLangCode>"
        try:
            self.lexicographer = importlib.import_module(".lexgraph_"+sLangCode, "grammalecte.graphspell")
        except ImportError:
            print("No suggestion module for language <"+sLangCode+">")
................................................................................
                    aRes = [ (" | ".join(lMorph), sLex) ]
                else:
                    aRes = [ (sMorph, self.lexicographer.formatTags(sMorph)) for sMorph in lMorph ]
                if aRes:
                    lWordAndMorph.append((sElem, aRes))
        return lWordAndMorph







    # Storage

    def activateStorage (self):
        "store all lemmas and morphologies retrieved from the word graph"
        self.bStorage = True

................................................................................
            if sWord not in self._dLemmas:
                self.getMorph(sWord)
            return self._dLemmas[sWord]
        return { s[1:s.find("/")]  for s in self.getMorph(sWord) }

    def suggest (self, sWord, nSuggLimit=10):
        "generator: returns 1, 2 or 3 lists of suggestions"
        if self.lexicographer.dSugg:
            if sWord in self.lexicographer.dSugg:
                yield self.lexicographer.dSugg[sWord].split("|")
            elif sWord.istitle() and sWord.lower() in self.lexicographer.dSugg:
                lRes = self.lexicographer.dSugg[sWord.lower()].split("|")
                yield list(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes))
            else:
                yield self.oMainDic.suggest(sWord, nSuggLimit, True)







|







 







>
>
>
>
>







 







|







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
        self.bCommunityDic = False

    def deactivatePersonalDictionary (self):
        "deactivate personal dictionary"
        self.bPersonalDic = False


    # Lexicographer

    def loadLexicographer (self, sLangCode):
        "load default suggestion module for <sLangCode>"
        try:
            self.lexicographer = importlib.import_module(".lexgraph_"+sLangCode, "grammalecte.graphspell")
        except ImportError:
            print("No suggestion module for language <"+sLangCode+">")
................................................................................
                    aRes = [ (" | ".join(lMorph), sLex) ]
                else:
                    aRes = [ (sMorph, self.lexicographer.formatTags(sMorph)) for sMorph in lMorph ]
                if aRes:
                    lWordAndMorph.append((sElem, aRes))
        return lWordAndMorph

    def readableMorph (self, sMorph):
        if not self.lexicographer:
            return []
        return self.lexicographer.formatTags(sMorph)


    # Storage

    def activateStorage (self):
        "store all lemmas and morphologies retrieved from the word graph"
        self.bStorage = True

................................................................................
            if sWord not in self._dLemmas:
                self.getMorph(sWord)
            return self._dLemmas[sWord]
        return { s[1:s.find("/")]  for s in self.getMorph(sWord) }

    def suggest (self, sWord, nSuggLimit=10):
        "generator: returns 1, 2 or 3 lists of suggestions"
        if self.lexicographer:
            if sWord in self.lexicographer.dSugg:
                yield self.lexicographer.dSugg[sWord].split("|")
            elif sWord.istitle() and sWord.lower() in self.lexicographer.dSugg:
                lRes = self.lexicographer.dSugg[sWord.lower()].split("|")
                yield list(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes))
            else:
                yield self.oMainDic.suggest(sWord, nSuggLimit, True)