Grammalecte  Diff

Differences From Artifact [2c21818f72]:

To Artifact [be57805d79]:


43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57







-
+







        this.oMainDic = this._loadDictionary(mainDic, sPath, true);
        this.oCommunityDic = this._loadDictionary(communityDic, sPath);
        this.oPersonalDic = this._loadDictionary(personalDic, sPath);
        this.bCommunityDic = Boolean(this.oCommunityDic);
        this.bPersonalDic = Boolean(this.oPersonalDic);
        this.oTokenizer = null;
        // Default suggestions
        this.oDefaultSugg = null;
        this.dDefaultSugg = null;
        this.loadSuggestions(sLangCode)
        // storage
        this.bStorage = false;
        this._dMorphologies = new Map();            // key: flexion, value: list of morphologies
        this._dLemmas = new Map();                  // key: flexion, value: list of lemmas
    }

131
132
133
134
135
136
137

138
139






140
141
142
143
144
145
146
131
132
133
134
135
136
137
138


139
140
141
142
143
144
145
146
147
148
149
150
151







+
-
-
+
+
+
+
+
+









    // Default suggestions

    loadSuggestions (sLangCode) {
        // load default suggestion module for <sLangCode>
        // When “import” works everywhere, do like with Python
        try {
        if (suggest && suggest.hasOwnProperty(sLangCode)) {
            this.oDefaultSugg = suggest[sLangCode];
            if (typeof(suggest) !== 'undefined') {
                this.dDefaultSugg = suggest[sLangCode];
            }
        }
        catch (e) {
            console.error(e);
        }
    }


    // Storage

    activateStorage () {
245
246
247
248
249
250
251
252
253
254
255
256





257
258
259
260
261
262
263
250
251
252
253
254
255
256





257
258
259
260
261
262
263
264
265
266
267
268







-
-
-
-
-
+
+
+
+
+







            return this._dLemmas.get(sWord);
        }
        return Array.from(new Set(this.getMorph(sWord).map((sMorph) => { return sMorph.slice(1, sMorph.indexOf("/")); })));
    }

    * suggest (sWord, nSuggLimit=10) {
        // generator: returns 1, 2 or 3 lists of suggestions
        if (this.oDefaultSugg) {
            if (this.oDefaultSugg.hasOwnProperty(sWord)) {
                yield this.oDefaultSugg[sWord].split("|");
            } else if (sWord.gl_isTitle() && this.oDefaultSugg.hasOwnProperty(sWord.toLowerCase())) {
                let lRes = this.oDefaultSugg[sWord.toLowerCase()].split("|");
        if (this.dDefaultSugg) {
            if (this.dDefaultSugg.has(sWord)) {
                yield this.dDefaultSugg.get(sWord).split("|");
            } else if (sWord.gl_isTitle() && this.dDefaultSugg.has(sWord.toLowerCase())) {
                let lRes = this.dDefaultSugg.get(sWord.toLowerCase()).split("|");
                yield lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
            } else {
                yield this.oMainDic.suggest(sWord, nSuggLimit, true);
            }
        } else {
            yield this.oMainDic.suggest(sWord, nSuggLimit, true);
        }