Grammalecte  Diff

Differences From Artifact [8801cae354]:

To Artifact [299826c38f]:


287
288
289
290
291
292
293






















294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313


314
315



316
317
318
319
320
321
322
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333


334
335
336

337
338
339
340
341
342
343
344
345
346







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


















-
-
+
+

-
+
+
+







        if (this.bStorage) {
            this._dMorphologies.set(sWord, lMorph);
            this._dLemmas.set(sWord, Array.from(new Set(this.getMorph(sWord).map((sMorph) => { return sMorph.slice(1, sMorph.indexOf("/")); }))));
            //console.log(sWord, this._dLemmas.get(sWord));
        }
        return lMorph;
    }

    morph (sWord, sPattern, sNegPattern="") {
        // analyse a token, return True if <sNegPattern> not in morphologies and <sPattern> in morphologies
        let lMorph = this.getMorph(sWord);
        if (lMorph.length == 0) {
            return false;
        }
        // check negative condition
        if (sNegPattern) {
            if (sNegPattern == "*") {
                // all morph must match sPattern
                return lMorph.every(sMorph  =>  (sMorph.search(sPattern) !== -1));
            }
            else {
                if (lMorph.some(sMorph  =>  (sMorph.search(sNegPattern) !== -1))) {
                    return false;
                }
            }
        }
        // search sPattern
        return lMorph.some(sMorph  =>  (sMorph.search(sPattern) !== -1));
    }

    getLemma (sWord) {
        // retrieves lemmas
        if (this.bStorage) {
            if (!this._dLemmas.has(sWord)) {
                this.getMorph(sWord);
            }
            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.lexicographer) {
            if (this.lexicographer.dSugg.has(sWord)) {
                yield this.lexicographer.dSugg.get(sWord).split("|");
            } else if (sWord.gl_isTitle() && this.lexicographer.dSugg.has(sWord.toLowerCase())) {
                let lRes = this.lexicographer.dSugg.get(sWord.toLowerCase()).split("|");
                yield lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
                let lSuggs = this.lexicographer.dSugg.get(sWord.toLowerCase()).split("|");
                yield lSuggs.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
            } else {
                yield this.oMainDic.suggest(sWord, nSuggLimit, true);
                let lSuggs = this.oMainDic.suggest(sWord, nSuggLimit, true);
                lSuggs = lSuggs.filter((sSugg) => this.lexicographer.isValidSugg(sSugg, this));
                yield lSuggs;
            }
        } else {
            yield this.oMainDic.suggest(sWord, nSuggLimit, true);
        }
        if (this.bCommunityDic) {
            yield this.oCommunityDic.suggest(sWord, Math.floor(nSuggLimit/2)+1);
        }