Grammalecte  Diff

Differences From Artifact [88587ea88f]:

To Artifact [af4645de50]:


9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145


146
147
148
149
150
151
152
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global require, exports, console, IBDAWG, Tokenizer */

"use strict";

if(typeof(process) !== 'undefined') {
    var ibdawg = require("./ibdawg.js");
    var tokenizer = require("./tokenizer.js");
    var suggest = require("./suggest.js");

} else if (typeof(require) !== 'undefined') {
    var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js");
    var tokenizer = require("resource://grammalecte/graphspell/tokenizer.js");
    var suggest = require("resource://grammalecte/graphspell/suggest.js");
}

${map}


const dDefaultDictionaries = new Map([
    ["fr", "fr-allvars.json"],
................................................................................
        }
        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.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
    }

    _loadDictionary (dictionary, sPath="", bNecessary=false) {
................................................................................
    }

    deactivatePersonalDictionary () {
        this.bPersonalDic = false;
    }


    // Default suggestions

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

            }
        }
        catch (e) {
            console.error(e);


        }
    }


    // Storage

    activateStorage () {
................................................................................
            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.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);
        }







|


<
>
|


<







 







|
|
|







 







|

|

<
<
|
<
>
|
<
<
<
>
>







 







|
|
|
|
|







9
10
11
12
13
14
15
16
17
18

19
20
21
22

23
24
25
26
27
28
29
..
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
...
126
127
128
129
130
131
132
133
134
135
136


137

138
139



140
141
142
143
144
145
146
147
148
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global require, exports, console, IBDAWG, Tokenizer */

"use strict";

if (typeof(process) !== 'undefined') {
    var ibdawg = require("./ibdawg.js");
    var tokenizer = require("./tokenizer.js");

}
else if (typeof(require) !== 'undefined') {
    var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js");
    var tokenizer = require("resource://grammalecte/graphspell/tokenizer.js");

}

${map}


const dDefaultDictionaries = new Map([
    ["fr", "fr-allvars.json"],
................................................................................
        }
        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;
        // Lexicographer
        this.lexicographer = null;
        this.loadLexicographer(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
    }

    _loadDictionary (dictionary, sPath="", bNecessary=false) {
................................................................................
    }

    deactivatePersonalDictionary () {
        this.bPersonalDic = false;
    }


    // 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 () {
................................................................................
            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); });
            } else {
                yield this.oMainDic.suggest(sWord, nSuggLimit, true);
            }
        } else {
            yield this.oMainDic.suggest(sWord, nSuggLimit, true);
        }