Grammalecte  Changes On Branch a43e8d10eb1aa500

Changes In Branch nodejs Through [a43e8d10eb] Excluding Merge-Ins

This is equivalent to a diff from 4d2953e2f6 to a43e8d10eb

2018-10-11
15:13
[js] Revert syntax change check-in: 9ae8f0a042 user: IllusionPerdu tags: njs, nodejs
2018-10-10
12:23
[js] Minimal file to use in node check-in: a43e8d10eb user: IllusionPerdu tags: njs, nodejs
12:08
[js] All Grammalecte work in node check-in: 2d5c0dce59 user: IllusionPerdu tags: njs, nodejs
09:19
Some change to javascript to work in node check-in: a3687f4fd3 user: IllusionPerdu tags: graphspell, njs, nodejs
09:03
[fr] test faux positif check-in: bdcc97b45b user: olr tags: trunk, fr
2018-10-09
11:07
[graphspell][js] useless comments check-in: 4d2953e2f6 user: olr tags: trunk, graphspell
08:54
[graphspell][js] performance tests check-in: 14ed269c7c user: olr tags: trunk, graphspell

Added gc_core/js/exemple-node.js version [393f0a3208].























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// JavaScript

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

"use strict";

//console.log('\x1B[2J\x1B[0f'); //Clear the console (cmd win)

var oGrammalecte = require('./fr/gc_engine.js');

oGrammalecte.load();

var sPhrase = 'Le silences s’amasses Étoile brillantesss';
console.log('\x1b[36m%s \x1b[32m%s\x1b[0m', 'Test de vérification de:', sPhrase);
console.log( oGrammalecte.parse(sPhrase) );

var sWord = 'toutt';
console.log('\x1b[36m%s \x1b[32m%s\x1b[0m', 'Test de suggestion:', sWord);
var oSpellCheckGramma = oGrammalecte.getSpellChecker();
console.log( Array.from( oSpellCheckGramma.suggest(sWord) ) );

Modified gc_core/js/lang_core/gc_engine.js from [e6dde271f2] to [47ef94b478].

1


2
3


4
5
6
7
8
9



10
11
12
13
14
15
16
17












18
19
20
21
22
23
24
1
2
3


4
5
6
7
8



9
10
11
12
13






14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

+
+
-
-
+
+



-
-
-
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







// Grammar checker engine

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

"use strict";

${string}
${regex}
${map}
//${string}
//${regex}
//${map}


if (typeof(require) !== 'undefined') {
    var gc_options = require("resource://grammalecte/${lang}/gc_options.js");
    var gc_rules = require("resource://grammalecte/${lang}/gc_rules.js");
    var gc_rules_graph = require("resource://grammalecte/${lang}/gc_rules_graph.js");
    var cregex = require("resource://grammalecte/${lang}/cregex.js");
    var text = require("resource://grammalecte/text.js");
if(typeof process !== 'undefined') {
    var gc_options = require('./gc_options.js');
    var gc_rules = require('./gc_rules.js');
    var gc_rules_graph = require('./gc_rules_graph.js');
    var cregex = require('./cregex.js');
    var text = require('../text.js');
} else if (typeof(require) !== 'undefined') {
    var gc_options = require('resource://grammalecte/${lang}/gc_options.js');
    var gc_rules = require('resource://grammalecte/${lang}/gc_rules.js');
    var gc_rules_graph = require('resource://grammalecte/${lang}/gc_rules_graph.js');
    var cregex = require('resource://grammalecte/${lang}/cregex.js');
    var text = require('resource://grammalecte/text.js');
}


function capitalizeArray (aArray) {
    // can’t map on user defined function??
    let aNew = [];
    for (let i = 0; i < aArray.length; i = i + 1) {
49
50
51
52
53
54
55
56
57





58
59
60
61
62
63
64
57
58
59
60
61
62
63


64
65
66
67
68
69
70
71
72
73
74
75







-
-
+
+
+
+
+







    version: "${version}",
    author: "${author}",

    //// Initialization

    load: function (sContext="JavaScript", sColorType="aRGB", sPath="") {
        try {
            if (typeof(require) !== 'undefined') {
                var spellchecker = require("resource://grammalecte/graphspell/spellchecker.js");
            if(typeof process !== 'undefined') {
                var spellchecker = require('../graphspell/spellchecker.js');
                _oSpellChecker = new spellchecker.SpellChecker("${lang}", "", "${dic_main_filename_js}", "${dic_extended_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}");
            } else if (typeof require !== 'undefined') {
                var spellchecker = require('resource://grammalecte/graphspell/spellchecker.js');
                _oSpellChecker = new spellchecker.SpellChecker("${lang}", "", "${dic_main_filename_js}", "${dic_extended_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}");
            } else {
                _oSpellChecker = new SpellChecker("${lang}", sPath, "${dic_main_filename_js}", "${dic_extended_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}");
            }
            _sAppContext = sContext;
            _dOptions = gc_options.getOptions(sContext).gl_shallowCopy();     // duplication necessary, to be able to reset to default
            _dOptionsColors = gc_options.getOptionsColors(sContext, sColorType);
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202







-
+







        this.dTokenPos = new Map();
        this.dTags = new Map();
        this.dError = new Map();
        this.dErrorPriority = new Map();  // Key = position; value = priority
    }

    asString () {
        let s = "===== TEXT =====\n"
        let s = "===== TEXT =====\n";
        s += "sentence: " + this.sSentence0 + "\n";
        s += "now:      " + this.sSentence  + "\n";
        for (let dToken of this.lToken) {
            s += `#${dToken["i"]}\t${dToken["nStart"]}:${dToken["nEnd"]}\t${dToken["sValue"]}\t${dToken["sType"]}`;
            if (dToken.hasOwnProperty("lMorph")) {
                s += "\t" + dToken["lMorph"].toString();
            }
1385
1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398
1399
1396
1397
1398
1399
1400
1401
1402

1403
1404
1405
1406
1407
1408
1409
1410







-
+







${callablesJS}

    // callables for graph rules
${graph_callablesJS}
}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.lang = gc_engine.lang;
    exports.locales = gc_engine.locales;
    exports.pkg = gc_engine.pkg;
    exports.name = gc_engine.name;
    exports.version = gc_engine.version;
    exports.author = gc_engine.author;
    // init

Modified gc_core/js/lang_core/gc_options.js from [aa3f5d62cd] to [a80ff5a6ee].

1


2
3


4
5
6
7
8
9
10
1
2
3


4
5
6
7
8
9
10
11
12

+
+
-
-
+
+







// Options for Grammalecte

/* jshint esversion:6 */
/*jslint esversion: 6*/
/*global exports*/
/* jslint esversion:6 */
/* global exports */

${map}


var gc_options = {
    getOptions: function (sContext="JavaScript") {
        if (this.dOpt.hasOwnProperty(sContext)) {
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48

49
50

51
52
53
54



55
56
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49

50
51

52
53



54
55
56
57
58







-
+
















-
+


-
+

-
+

-
-
-
+
+
+


            for (let [sOpt, sColor] of Object.entries(dOptColor)) {
                dColor[sOpt] = dColorType[sColor];
            }
            return dColor;
        }
        catch (e) {
            console.error(e);
            return {}
            return {};
        }
    },

    lStructOpt: ${lStructOpt},

    dOpt: {
        "JavaScript": new Map (${dOptJavaScript}),
        "Firefox": new Map (${dOptFirefox}),
        "Thunderbird": new Map (${dOptThunderbird}),
    },

    dColorType: ${dColorType},

    dOptColor: ${dOptColor},

    dOptLabel: ${dOptLabel}
}
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
	exports.getOptions = gc_options.getOptions;
    exports.getOptionsColors = gc_options.getOptionsColors;
	exports.getOptionsColors = gc_options.getOptionsColors;
	exports.lStructOpt = gc_options.lStructOpt;
    exports.dOpt = gc_options.dOpt;
    exports.dColorType = gc_options.dColorType;
    exports.dOptColor = gc_options.dOptColor;
	exports.dOpt = gc_options.dOpt;
	exports.dColorType = gc_options.dColorType;
	exports.dOptColor = gc_options.dOptColor;
	exports.dOptLabel = gc_options.dOptLabel;
}

Modified gc_core/js/lang_core/gc_rules.js from [cdb121423e] to [c719e5aff6].

1


2

3
4
5
6
7
8
9
10
11
12
13
14

15
16
17

18
19
20
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15

16
17
18

19
20
21
22

+
+
-
+











-
+


-
+



// Grammar checker rules

/* jshint esversion:6, -W097 */
/*jslint esversion: 6*/
/* jslint esversion:6 */
/*global exports*/

"use strict";

${string}
${regex}

var gc_rules = {
    lParagraphRules: ${paragraph_rules_JS},

    lSentenceRules: ${sentence_rules_JS}
}
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.lParagraphRules = gc_rules.lParagraphRules;
    exports.lSentenceRules = gc_rules.lSentenceRules;
}

Modified gc_core/js/lang_core/gc_rules_graph.js from [7405261f29] to [41e4864e6c].

1


2

3
4
5
6
7

8
9
10
11
12
13
14

15
16
17

18
19
20
1
2
3

4
5
6
7
8

9
10
11
12
13
14
15

16
17
18

19
20
21
22

+
+
-
+




-
+






-
+


-
+



// Grammar checker graph rules

/* jshint esversion:6, -W097 */
/*jslint esversion: 6*/
/* jslint esversion:6 */
/*global exports*/

"use strict";

${string}
//${string}


var gc_rules_graph = {
    dAllGraph: ${rules_graphsJS},

    dRule: ${rules_actionsJS}
}
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.dAllGraph = gc_rules_graph.dAllGraph;
    exports.dRule = gc_rules_graph.dRule;
}

Modified gc_core/js/tests.js from [1eda44faf6] to [2455a96fb4].

1


2
3


4
5
6
7
8
9




10
11
12
13
14
15
16
17
18
19
20
21
22




23


24
25
26
27
28
29
30
1
2
3


4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39

+
+
-
-
+
+




-
-
+
+
+
+













+
+
+
+
-
+
+







// JavaScript

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

"use strict";


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


class TestGrammarChecking {

    constructor (gce, spfTests="") {
        this.gce = gce;
        this.spfTests = spfTests;
        this._aRuleTested = new Set();
    }

    * testParse (bDebug=false) {
        const t0 = Date.now();
        let sURL;
        if(typeof process !== 'undefined') {
            sURL = (this.spfTests !== "") ? this.spfTests : "./"+this.gce.lang+"/tests_data.json";
        } else {
        let sURL = (this.spfTests !== "") ? this.spfTests : "resource://grammalecte/"+this.gce.lang+"/tests_data.json";
            sURL = (this.spfTests !== "") ? this.spfTests : "resource://grammalecte/"+this.gce.lang+"/tests_data.json";
        }
        const aData = JSON.parse(helpers.loadFile(sURL)).aData;
        let nInvalid = 0;
        let nTotal = 0;
        let sErrorText;
        let sSugg;
        let sExpectedErrors;
        let sTextToCheck;
149
150
151
152
153
154
155
156

157
158
158
159
160
161
162
163
164

165
166
167







-
+


        }
        return [" ".repeat(sLine.length), ""];
    }

}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.TestGrammarChecking = TestGrammarChecking;
}

Modified gc_core/js/text.js from [c9e7670db8] to [2540b2b127].

1


2
3


4
5
6
7
8
9
10
1
2
3


4
5
6
7
8
9
10
11
12

+
+
-
-
+
+







// JavaScript

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

"use strict";


var text = {
    getParagraph: function* (sText, sSepParagraph = "\n") {
        // generator: returns paragraphs of text
55
56
57
58
59
60
61
62

63
64
65
66
57
58
59
60
61
62
63

64
65
66
67
68







-
+




            console.error(e);
            return "\n# Error. Data: " + oErr.toString();
        }
    }
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.getParagraph = text.getParagraph;
    exports.wrap = text.wrap;
    exports.getReadableError = text.getReadableError;
}

Modified gc_lang/fr/modules-js/conj.js from [8124143953] to [9586582de9].

1
2


3
4


5
6
7
8

9
10
11
12




13
14
15
16
17
18
19
1
2
3
4


5
6
7
8
9

10
11
12


13
14
15
16
17
18
19
20
21
22
23


+
+
-
-
+
+



-
+


-
-
+
+
+
+







// Grammalecte - Conjugueur
// License: GPL 3

/* jshint esversion:6, -W097 */
/*jslint esversion: 6*/
/*global console,require,exports,self,browser*/
/* jslint esversion:6 */
/*global require, exports, console, self, browser, chrome, __dirname */

"use strict";

${map}
//${map}


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

var conj = {
    _lVtyp: [],
    _lTags: [],
    _dPatternConj: {},
    _dVerb: {},
492
493
494
495
496
497
498



499

500
501
502


503
504
505


506
507
508


509
510
511

512
513

514
515

516
517
518
519
520
521

522
523
524
525
526
527
528
496
497
498
499
500
501
502
503
504
505

506
507


508
509
510


511
512
513


514
515
516
517

518
519

520
521

522
523
524
525
526
527

528
529
530
531
532
533
534
535







+
+
+
-
+

-
-
+
+

-
-
+
+

-
-
+
+


-
+

-
+

-
+





-
+







        }
        return (this.dConj.get(":Q").get(":Q4")) ? this.dConj.get(":Q").get(":Q4") : this.dConj.get(":Q").get(":Q1");
    }
}


// Initialization
if(!conj.bInit && typeof process !== 'undefined') {
    // Work with nodejs
    conj.init(helpers.loadFile(__dirname+'/conj_data.json'));
if (!conj.bInit && typeof(browser) !== 'undefined') {
} else if (!conj.bInit && typeof(browser) !== 'undefined') {
    // WebExtension Standard (but not in Worker)
    conj.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/conj_data.json")));
} else if (!conj.bInit && typeof(chrome) !== 'undefined') {
    conj.init(helpers.loadFile(browser.extension.getURL('grammalecte/fr/conj_data.json')));
} else if (!conj.bInit && typeof chrome !== 'undefined') {
    // WebExtension Chrome (but not in Worker)
    conj.init(helpers.loadFile(chrome.extension.getURL("grammalecte/fr/conj_data.json")));
} else if (!conj.bInit && typeof(require) !== 'undefined') {
    conj.init(helpers.loadFile(chrome.extension.getURL('grammalecte/fr/conj_data.json')));
} else if (!conj.bInit && typeof require !== 'undefined') {
    // Add-on SDK and Thunderbird
    conj.init(helpers.loadFile("resource://grammalecte/fr/conj_data.json"));
} else if (!conj.bInit && typeof(self) !== 'undefined' && typeof(self.port) !== 'undefined' && typeof(self.port.on) !== "undefined") {
    conj.init(helpers.loadFile('resource://grammalecte/fr/conj_data.json'));
} else if (!conj.bInit && typeof self !== 'undefined' && typeof self.port !== 'undefined' && typeof self.port.on !== 'undefined') {
    // used within Firefox content script (conjugation panel).
    // can’t load JSON from here, so we do it in ui.js and send it here.
    self.port.on("provideConjData", function (sJSONData) {
    self.port.on('provideConjData', function (sJSONData) {
        conj.init(sJSONData);
    });    
    });
} else if (conj.bInit){
    console.log("Module conj déjà initialisé");
    console.log('Module conj déjà initialisé');
} else {
    //console.log("Module conj non initialisé");
}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports._lVtyp = conj._lVtyp;
    exports._lTags = conj._lTags;
    exports._dPatternConj = conj._dPatternConj;
    exports._dVerb = conj._dVerb;
    exports.init = conj.init;
    exports._zStartVoy = conj._zStartVoy;
    exports._zNeedTeuph = conj._zNeedTeuph;

Modified gc_lang/fr/modules-js/conj_generator.js from [058e3de2f7] to [5e8295b732].

1
2
3
4
5
6






7
8
9
10
11
12
13
1
2




3
4
5
6
7
8
9
10
11
12
13
14
15


-
-
-
-
+
+
+
+
+
+







//  JavaScript

/*
    Conjugation generator
    beta stage, unfinished, the root for a new way to generate flexions…
*/
//    Conjugation generator
//    beta stage, unfinished, the root for a new way to generate flexions…


/* jshint esversion:6, -W097 */
/* jslint esversion:6 */

"use strict";


var conj_generator = {

    conjugate: function (sVerb, sVerbTag="i_____a", bVarPpas=true) {
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151







-
+







            [2,     "isses",        ":Sp:Sq:2s/*",      false],
            [2,     "isse",         ":Sp:3s/*",         false],
            [2,     "ît",           ":Sq:3s/*",         false],
            [2,     "is",           ":E:2s/*",          false],
            [2,     "issons",       ":E:1p/*",          false],
            [2,     "issez",        ":E:2p/*",          false]
        ],
        

        // premier groupe (bien plus irrégulier que prétendu)
        "V1": {
            // a
            // verbes en -er, -ger, -yer, -cer
            "er": [
                [2,      "er",        ":Y/*",               false],
                [2,      "ant",       ":P/*",               false],

Modified gc_lang/fr/modules-js/cregex.js from [97d67d03aa] to [9727baa3eb].

1
2




3
4
5
6
7
8
9


1
2
3
4
5
6
7
8
9
10
11
-
-
+
+
+
+







//// Grammalecte - Compiled regular expressions
/*jslint esversion: 6*/
// Grammalecte - Compiled regular expressions

/* jshint esversion:6 */
/* jslint esversion:6 */


var cregex = {
    ///// Lemme
    _zLemma: new RegExp(">([a-zà-öø-ÿ0-9Ā-ʯ][a-zà-öø-ÿ0-9Ā-ʯ-]+)"),

    ///// Masculin / féminin / singulier / pluriel
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279







-
+







            return false;
        }
        return lMorph.some(s  =>  this._zNPm.test(s));
    }
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports._zLemma = cregex._zLemma;
    exports._zGender = cregex._zGender;
    exports._zNumber = cregex._zNumber;
    exports._zNA = cregex._zNA;
    exports._zNAs = cregex._zNAs;
    exports._zNAp = cregex._zNAp;
    exports._zNAi = cregex._zNAi;

Modified gc_lang/fr/modules-js/gce_analyseur.js from [427ee71140] to [09241345b5].

1
2




3
4
5
6
7
8
9


1
2
3
4
5
6
7
8
9
10
11
-
-
+
+
+
+







//// GRAMMAR CHECKING ENGINE PLUGIN: Parsing functions for French language
/*jslint esversion: 6*/
// GRAMMAR CHECKING ENGINE PLUGIN: Parsing functions for French language

/* jshint esversion:6 */
/* jslint esversion:6 */

function g_morphVC (dToken, sPattern, sNegPattern="") {
    let nEnd = dToken["sValue"].lastIndexOf("-");
    if (dToken["sValue"].includes("-t-")) {
        nEnd = nEnd - 2;
    }
    return g_morph(dToken, sPattern, sNegPattern, 0, nEnd, false);
126
127
128
129
130
131
132
133

134
135
136
137
138
128
129
130
131
132
133
134

135
136
137
138
139
140







-
+





    if (s.length > 1 && s.length < 16 && s.slice(0, 1).gl_isLowerCase() && (!s.slice(1).gl_isLowerCase() || /[0-9]/.test(s))) {
        return true;
    }
    return false;
}


//// Exceptions
// Exceptions

const aREGULARPLURAL = new Set(["abricot", "amarante", "aubergine", "acajou", "anthracite", "brique", "caca", "café",
                                "carotte", "cerise", "chataigne", "corail", "citron", "crème", "grave", "groseille",
                                "jonquille", "marron", "olive", "pervenche", "prune", "sable"]);
const aSHOULDBEVERB = new Set(["aller", "manger"]);

Modified gc_lang/fr/modules-js/gce_date_verif.js from [f30dbe242e] to [8555f52be9].

1

2
3
4

5
6


7
8
9
10
11
12
13

1

2
3
4
5

6
7
8
9
10
11
12
13
14
-
+
-


+

-
+
+







//// GRAMMAR CHECKING ENGINE PLUGIN
// GRAMMAR CHECKING ENGINE PLUGIN
/*jslint esversion: 6*/

// Check date validity
// WARNING: when creating a Date, month must be between 0 and 11

// WARNING: when creating a Date, month must be between 0 and 11
/* jshint esversion:6 */
/* jslint esversion:6 */


const _lDay = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"];
const _dMonth = new Map ([
    ["janvier", 1], ["février", 2], ["mars", 3], ["avril", 4], ["mai", 5], ["juin", 6], ["juillet", 7],
    ["août", 8], ["aout", 8], ["septembre", 9], ["octobre", 10], ["novembre", 11], ["décembre", 12]
]);

Modified gc_lang/fr/modules-js/gce_suggestions.js from [ae7eaca80b] to [b2f66a0847].

1
2
3





4
5
6
7
8








9
10
11
12
13
14
15



1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-
-
-
+
+
+
+
+

-
-
-
-
+
+
+
+
+
+
+
+







//// GRAMMAR CHECKING ENGINE PLUGIN: Suggestion mechanisms
/*jslint esversion: 6*/
/*global require*/
// GRAMMAR CHECKING ENGINE PLUGIN: Suggestion mechanisms

/* jshint esversion:6 */
/* jslint esversion:6 */
/* global require */

if (typeof(require) !== 'undefined') {
    var conj = require("resource://grammalecte/fr/conj.js");
    var mfsp = require("resource://grammalecte/fr/mfsp.js");
    var phonet = require("resource://grammalecte/fr/phonet.js");
if(typeof process !== 'undefined') {
    var conj = require('./conj.js');
    var mfsp = require('./mfsp.js');
    var phonet = require('./phonet.js');
} else if (typeof require !== 'undefined') {
    var conj = require('resource://grammalecte/fr/conj.js');
    var mfsp = require('resource://grammalecte/fr/mfsp.js');
    var phonet = require('resource://grammalecte/fr/phonet.js');
}


//// verbs

function splitVerb (sVerb) {
    // renvoie le verbe et les pronoms séparément

Modified gc_lang/fr/modules-js/lexicographe.js from [3f0da2f1ff] to [50f4dc02f6].

1
2


3
4


5
6
7
8
9
10
11
1
2
3
4


5
6
7
8
9
10
11
12
13


+
+
-
-
+
+







// Grammalecte - Lexicographe
// License: MPL 2

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

"use strict";

${string}
${map}


Modified gc_lang/fr/modules-js/mfsp.js from [9d6124ec70] to [d93c273b71].

1


2
3


4
5
6
7
8
9




10
11
12
13
14
15
16
1
2
3


4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20

+
+
-
-
+
+




-
-
+
+
+
+







// Grammalecte

/* jshint esversion:6, -W097 */
/*jslint esversion: 6*/
/*global console,require,exports,browser*/
/* jslint esversion:6 */
/* global require, exports, console, browser,__dirname */

"use strict";


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


var mfsp = {
    // list of affix codes
    _lTagMiscPlur: [],
    _lTagMasForm: [],
100
101
102
103
104
105
106



107

108
109

110
111
112

113
114

115
116

117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132
104
105
106
107
108
109
110
111
112
113

114
115

116
117
118

119
120

121
122

123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138
139







+
+
+
-
+

-
+


-
+

-
+

-
+



-
+












            return "## erreur, code : " + sSfx + " ##";
        }
    }
};


// Initialization
if(!mfsp.bInit && typeof process !== 'undefined') {
    //Nodejs
    mfsp.init(helpers.loadFile(__dirname+'/mfsp_data.json'));
if (!mfsp.bInit && typeof(browser) !== 'undefined') {
} else if (!mfsp.bInit && typeof(browser) !== 'undefined') {
    // WebExtension
    mfsp.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/mfsp_data.json")));
    mfsp.init(helpers.loadFile(browser.extension.getURL('grammalecte/fr/mfsp_data.json')));
} else if (!mfsp.bInit && typeof(require) !== 'undefined') {
    // Add-on SDK and Thunderbird
    mfsp.init(helpers.loadFile("resource://grammalecte/fr/mfsp_data.json"));
    mfsp.init(helpers.loadFile('resource://grammalecte/fr/mfsp_data.json'));
} else if (mfsp.bInit){
    console.log("Module mfsp déjà initialisé");
    console.log('Module mfsp déjà initialisé');
} else {
    //console.log("Module mfsp non initialisé");
    //console.log('Module mfsp non initialisé');
}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports._lTagMiscPlur = mfsp._lTagMiscPlur;
    exports._lTagMasForm = mfsp._lTagMasForm;
    exports._dMiscPlur = mfsp._dMiscPlur;
    exports._dMasForm = mfsp._dMasForm;
    exports.init = mfsp.init;
    exports.isFemForm = mfsp.isFemForm;
    exports.getMasForm = mfsp.getMasForm;
    exports.hasMiscPlural = mfsp.hasMiscPlural;
    exports.getMiscPlural = mfsp.getMiscPlural;
    exports._whatSuffixCode = mfsp._whatSuffixCode;
    exports._modifyStringWithSuffixCode = mfsp._modifyStringWithSuffixCode;
}

Modified gc_lang/fr/modules-js/phonet.js from [07bba03053] to [fb94b7fe43].

1


2


3
4



5
6
7
8
9
10
11
1
2
3

4
5
6

7
8
9
10
11
12
13
14
15
16

+
+
-
+
+

-
+
+
+







// Grammalecte - Suggestion phonétique

/* jshint esversion:6 */
/*jslint esversion: 6*/
/* jslint esversion:6 */
/* global __dirname */

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


var phonet = {
    _dWord: new Map(),
    _lSet: [],
80
81
82
83
84
85
86
87




88
89
90


91
92

93
94

95
96

97
98
99
100

101
102
103
104
105
106
107
108
85
86
87
88
89
90
91

92
93
94
95
96


97
98
99

100
101

102
103

104
105
106
107

108
109
110
111
112
113
114
115
116







-
+
+
+
+

-
-
+
+

-
+

-
+

-
+



-
+








        }
        return aSelect;
    }
};


// Initialization
if (!phonet.bInit && typeof(browser) !== 'undefined') {
if (!phonet.bInit && typeof process !== 'undefined') {
    //Nodejs
    phonet.init(helpers.loadFile(__dirname+'/phonet_data.json'));
} else if (!phonet.bInit && typeof browser !== 'undefined') {
    // WebExtension
    phonet.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/phonet_data.json")));
} else if (!phonet.bInit && typeof(require) !== 'undefined') {
    phonet.init(helpers.loadFile(browser.extension.getURL('grammalecte/fr/phonet_data.json')));
} else if (!phonet.bInit && typeof require !== 'undefined') {
    // Add-on SDK and Thunderbird
    phonet.init(helpers.loadFile("resource://grammalecte/fr/phonet_data.json"));
    phonet.init(helpers.loadFile('resource://grammalecte/fr/phonet_data.json'));
} else if (phonet.bInit){
    console.log("Module phonet déjà initialisé");
    console.log('Module phonet déjà initialisé');
} else {
    //console.log("Module phonet non initialisé");
    //console.log('Module phonet non initialisé');
}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports._dWord = phonet._dWord;
    exports._lSet = phonet._lSet;
    exports._dMorph = phonet._dMorph;
    exports.init = phonet.init;
    exports.hasSimil = phonet.hasSimil;
    exports.getSimil = phonet.getSimil;
    exports.selectSimil = phonet.selectSimil;
}

Modified gc_lang/fr/modules-js/textformatter.js from [a9dd9e148e] to [526f0b2382].

1


2
3


4
5
6
7
8
9
10
1
2
3


4
5
6
7
8
9
10
11
12

+
+
-
-
+
+







// Grammalecte - text formatter

/* jshint esversion:6, -W097 */
/*jslint esversion: 6*/
/*global exports*/
/* jslint esversion:6 */
/* global exports */

"use strict";

${map}


// Latin letters: http://unicode-table.com/fr/
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97







-
+







    "erase_non_breaking_hyphens": [ [/­/g, ""] ],
    //// typographic signs
    "ts_apostrophe":              [ [/\b([ldnjmtscç])['´‘′`](?=[a-zA-Zà-ö0-9À-Öø-ÿØ-ßĀ-ʯ])/ig, "$1’"],
                                    [/\b(qu|jusqu|lorsqu|puisqu|quoiqu|quelqu|presqu|entr|aujourd|prud)['´‘′`]/ig, "$1’"] ],
    "ts_ellipsis":                [ [/\.\.\./g, "…"],
                                    [/…\.\./g, "……"],
                                    [/…\.(?!\.)/g, "…"] ],
    "ts_n_dash_middle":           [ [/ [-—] /g, " – "], 
    "ts_n_dash_middle":           [ [/ [-—] /g, " – "],
                                    [/ [-—],/g, " –,"] ],
    "ts_m_dash_middle":           [ [/ [-–] /g, " — "],
                                    [/ [-–],/g, " —,"] ],
    "ts_n_dash_start":            [ [/^[-—][  ]/gm, "– "],
                                    [/^– /gm, "– "],
                                    [/^[-–—](?=[a-zA-Zà-ö0-9À-Öø-ÿØ-ßĀ-ʯ.…])/gm, "– "] ],
    "ts_m_dash_start":            [ [/^[-–][  ]/gm, "— "],
283
284
285
286
287
288
289
290

291
292
293
285
286
287
288
289
290
291

292
293
294
295







-
+




    getDefaultOptions () {
        return dTFDefaultOptions;
    }
}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.TextFormatter = TextFormatter;
    exports.oReplTable = oReplTable;
}

Modified graphspell-js/char_player.js from [626d7d161b] to [27827e9132].

1
2
3



4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
11
12
13



+
+
+







// list of similar chars
// useful for suggestion mechanism

/* jshint esversion:6 */
/* jslint esversion:6 */

${map}


var char_player = {

    _xTransCharsForSpelling: new Map([
        ['ſ', 's'],  ['ffi', 'ffi'],  ['ffl', 'ffl'],  ['ff', 'ff'],  ['ſt', 'ft'],  ['fi', 'fi'],  ['fl', 'fl'],  ['st', 'st']
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38







-
+







    _xTransCharsForSimplification: new Map([
        ['à', 'a'],  ['é', 'e'],  ['î', 'i'],  ['ô', 'o'],  ['û', 'u'],  ['ÿ', 'i'],  ['y', 'i'],
        ['â', 'a'],  ['è', 'e'],  ['ï', 'i'],  ['ö', 'o'],  ['ù', 'u'],  ['ŷ', 'i'],
        ['ä', 'a'],  ['ê', 'e'],  ['í', 'i'],  ['ó', 'o'],  ['ü', 'u'],  ['ý', 'i'],
        ['á', 'a'],  ['ë', 'e'],  ['ì', 'i'],  ['ò', 'o'],  ['ú', 'u'],  ['ỳ', 'i'],
        ['ā', 'a'],  ['ē', 'e'],  ['ī', 'i'],  ['ō', 'o'],  ['ū', 'u'],  ['ȳ', 'i'],
        ['ç', 'c'],  ['ñ', 'n'],  ['k', 'q'],  ['w', 'v'],
        ['œ', 'oe'], ['æ', 'ae'], 
        ['œ', 'oe'], ['æ', 'ae'],
        ['ſ', 's'],  ['ffi', 'ffi'],  ['ffl', 'ffl'],  ['ff', 'ff'],  ['ſt', 'ft'],  ['fi', 'fi'],  ['fl', 'fl'],  ['st', 'st']
    ]),

    simplifyWord: function (sWord) {
        // word simplication before calculating distance between words
        sWord = sWord.toLowerCase();
        sWord = [...sWord].map(c => this._xTransCharsForSimplification.gl_get(c, c)).join('');
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117







-
+







        ["Ë", "EeÉéÈèÊêËëĒēŒœ"],

        ["f", "fF"],
        ["F", "Ff"],

        ["g", "gGjJĵĴ"],
        ["G", "GgJjĴĵ"],
        

        ["h", "hH"],
        ["H", "Hh"],

        ["i", "iIîÎïÏyYíÍìÌīĪÿŸ"],
        ["I", "IiÎîÏïYyÍíÌìĪīŸÿ"],
        ["î", "iIîÎïÏyYíÍìÌīĪÿŸ"],
        ["Î", "IiÎîÏïYyÍíÌìĪīŸÿ"],
378
379
380
381
382
383
384
385

386
387
388

389
390
391
392
393
394
395
381
382
383
384
385
386
387

388
389
390

391
392
393
394
395
396
397
398







-
+


-
+







    },

    // Other functions
    filterSugg: function (aSugg) {
        return aSugg.filter((sSugg) => { return !sSugg.endsWith("è") && !sSugg.endsWith("È"); });
    }

}
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports._xTransCharsForSpelling = char_player._xTransCharsForSpelling;
    exports.spellingNormalization = char_player.spellingNormalization;
    exports._xTransCharsForSimplification = char_player._xTransCharsForSimplification;
    exports.simplifyWord = char_player.simplifyWord;
    exports.aVowel = char_player.aVowel;
    exports.aConsonant = char_player.aConsonant;
    exports.aDouble = char_player.aDouble;

Modified graphspell-js/dawg.js from [d94e6b7163] to [56edbc7aa3].

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15




16
17
18
19
20
21
22
23
24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16



17
18
19
20
21

22
23
24
25
26
27
28










+
+
+
+


-
-
-
+
+
+
+

-







// JavaScript

// FSA DICTIONARY BUILDER
//
// by Olivier R.
// License: MPL 2
//
// This tool encodes lexicon into an indexable binary dictionary
// Input files MUST be encoded in UTF-8.

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

"use strict";


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


${map}


class DAWG {
    /*  DIRECT ACYCLIC WORD GRAPH
        This code is inspired from Steve Hanov’s DAWG, 2011. (http://stevehanov.ca/blog/index.php?id=115)
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114







-
+







        let lWord = [];
        for (let [sFlex, iAff, iTag] of lEntry) {
            let lTemp = [];
            for (let c of sFlex) {
                lTemp.push(dChar.get(c));
            }
            lTemp.push(iAff+nChar);
            lTemp.push(iTag+nChar+nAff)
            lTemp.push(iTag+nChar+nAff);
            lWord.push(lTemp);
        }
        lEntry.length = 0; // clear the array

        // Dictionary of arc values occurrency, to sort arcs of each node
        let lKeyVal = [];
        for (let c of dChar.keys()) { lKeyVal.push([dChar.get(c), dCharOccur.get(c)]); }
426
427
428
429
430
431
432
433

434
435
436
437
438
439
440
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444







-
+







        this.nNextId += 1;
        return this.nNextId-1;
    },

    reset: function () {
        this.nNextId = 0;
    }
}
};


class DawgNode {

    constructor () {
        this.i = oNodeCounter.getId();
        this.final = false;
540
541
542
543
544
545
546
547

548
549
550
551
552
553
554
544
545
546
547
548
549
550

551
552
553
554
555
556
557
558







-
+







    convValueToHexString (nVal, nByte) {
        // nVal: value to convert, nByte: number of bytes
        let sHexVal = nVal.toString(16); // conversion to hexadecimal string
        //console.log(`value: ${nVal} in ${nByte} bytes`);
        if (sHexVal.length < (nByte*2)) {
            return "0".repeat((nByte*2) - sHexVal.length) + sHexVal;
        } else if (sHexVal.length == (nByte*2)) {
            return sHexVal
            return sHexVal;
        } else {
            throw "Conversion to byte string: value bigger than allowed.";
        }
    }
}


Modified graphspell-js/helpers.js from [6ccb02c60d] to [2ed0ee7e88].

1
2


3
4


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24





25
26
27
28
29
30
31








32
33
34
35
36
37
38

1
2
3


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-

+
+
-
-
+
+




















+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+








// HELPERS

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

"use strict";


var helpers = {

    inspect: function (o) {
        let sMsg = "__inspect__: " + typeof o;
        for (let sParam in o) {
            sMsg += "\n" + sParam + ": " + o.sParam;
        }
        sMsg += "\n" + JSON.stringify(o) + "\n__end__";
        console.log(sMsg);
    },

    loadFile: function (spf) {
        // load ressources in workers (suggested by Mozilla extensions reviewers)
        // for more options have a look here: https://gist.github.com/Noitidart/ec1e6b9a593ec7e3efed
        // if not in workers, use sdk/data.load() instead
        try {
            if(typeof process !== 'undefined' && typeof require !== 'undefined') {
                //console.log('loadFile(disque): ' + spf);
                let fs = require('fs');
                return fs.readFileSync(spf, 'utf8');
            } else {
            console.log("loadFile: " + spf);
            let xRequest;
            xRequest = new XMLHttpRequest();
            xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers
            xRequest.overrideMimeType('text/json');
            xRequest.send();
            return xRequest.responseText;
                //console.log('loadFile: ' + spf);
                let xRequest;
                xRequest = new XMLHttpRequest();
                xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers
                xRequest.overrideMimeType('text/json');
                xRequest.send();
                return xRequest.responseText;
            }
        }
        catch (e) {
            console.error(e);
            return null;
        }
    },

57
58
59
60
61
62
63
64

65
66
67
68
69
64
65
66
67
68
69
70

71
72
73
74
75
76







-
+





            obj[k] = v;
        }
        return obj;
    }
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.inspect = helpers.inspect;
    exports.loadFile = helpers.loadFile;
    exports.objectToMap = helpers.objectToMap;
    exports.mapToObject = helpers.mapToObject;
}

Modified graphspell-js/ibdawg.js from [26e5034903] to [3da9a9daaf].

1
2
3





4
5
6
7
8
9
10
11








12
13
14
15
16
17
18
19
20



1
2
3
4
5
6
7
8





9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
-
-
-
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+
+
+
+

-







//// IBDAWG
/*jslint esversion: 6*/
/*global console,require,exports*/
// IBDAWG

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

"use strict";


if (typeof(require) !== 'undefined') {
    var str_transform = require("resource://grammalecte/graphspell/str_transform.js");
    var helpers = require("resource://grammalecte/graphspell/helpers.js");
    var char_player = require("resource://grammalecte/graphspell/char_player.js");
if(typeof process !== 'undefined') {
    var str_transform = require('./str_transform.js');
    var helpers = require('./helpers.js');
    var char_player = require('./char_player.js');
} else if (typeof require !== 'undefined') {
    var str_transform = require('resource://grammalecte/graphspell/str_transform.js');
    var helpers = require('resource://grammalecte/graphspell/helpers.js');
    var char_player = require('resource://grammalecte/graphspell/char_player.js');
}


// Don’t remove <string>. Necessary in TB.
${string}
${map}
${set}


93
94
95
96
97
98
99




100


101
102
103
104
105
106
107
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115
116







+
+
+
+
-
+
+







    // INDEXABLE BINARY DIRECT ACYCLIC WORD GRAPH

    constructor (param1, sPath="") {
        // param1 can be a filename or a object with all the necessary data.
        try {
            let oData = null;
            if (typeof(param1) == "string") {
                let sURL;
                if(typeof process !== 'undefined') {
                    sURL = (sPath !== "") ? sPath + "/" + param1 : __dirname + "/_dictionaries/"+param1;
                } else {
                let sURL = (sPath !== "") ? sPath + "/" + param1 : "resource://grammalecte/graphspell/_dictionaries/"+param1;
                    sURL = (sPath !== "") ? sPath + "/" + param1 : "resource://grammalecte/graphspell/_dictionaries/"+param1;
                }
                oData = JSON.parse(helpers.loadFile(sURL));
            } else {
                oData = param1;
            }
            Object.assign(this, oData);
        }
        catch (e) {
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242







-
+







            "l2grams": this.l2grams
        };
        return oJSON;
    }

    isValidToken (sToken) {
        // checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked)
        sToken = char_player.spellingNormalization(sToken)
        sToken = char_player.spellingNormalization(sToken);
        if (this.isValid(sToken)) {
            return true;
        }
        if (sToken.includes("-")) {
            if (sToken.gl_count("-") > 4) {
                return true;
            }
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
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
347
348







-
+












-
-
+
+












-
+

-
-
+







            }
        }
        return Boolean(this._convBytesToInteger(this.byDic.slice(iAddr, iAddr+this.nBytesArc)) & this._finalNodeMask);
    }

    getMorph (sWord) {
        // retrieves morphologies list, different casing allowed
        sWord = char_player.spellingNormalization(sWord)
        sWord = char_player.spellingNormalization(sWord);
        let l = this.morph(sWord);
        if (sWord[0].gl_isUpperCase()) {
            l.push(...this.morph(sWord.toLowerCase()));
            if (sWord.gl_isUpperCase() && sWord.length > 1) {
                l.push(...this.morph(sWord.gl_toCapitalize()));
            }
        }
        return l;
    }

    suggest (sWord, nSuggLimit=10) {
        // returns a array of suggestions for <sWord>
        //const t0 = Date.now();
        sWord = char_player.spellingNormalization(sWord)
	//console.time("Suggestions for " + sWord + ");
        sWord = char_player.spellingNormalization(sWord);
        let sPfx = "";
        let sSfx = "";
        [sPfx, sWord, sSfx] = char_player.cut(sWord);
        let nMaxSwitch = Math.max(Math.floor(sWord.length / 3), 1);
        let nMaxDel = Math.floor(sWord.length / 5);
        let nMaxHardRepl = Math.max(Math.floor((sWord.length - 5) / 4), 1);
        let nMaxJump = Math.max(Math.floor(sWord.length / 4), 1);
        let oSuggResult = new SuggResult(sWord);
        this._suggest(oSuggResult, sWord, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump);
        let aSugg = oSuggResult.getSuggestions(nSuggLimit);
        if (sSfx || sPfx) {
            // we add what we removed
            return aSugg.map( (sSugg) => { return sPfx + sSugg + sSfx } );
            return aSugg.map( (sSugg) => { return sPfx + sSugg + sSfx; } );
        }
        //const t1 = Date.now();
        //console.log("Suggestions for " + sWord + " in " + ((t1-t0)/1000).toString() + " s");
	//console.timeEnd("Suggestions for " + sWord + ");
        return aSugg;
    }

    _suggest (oSuggResult, sRemain, nMaxSwitch=0, nMaxDel=0, nMaxHardRepl=0, nMaxJump=0, nDist=0, nDeep=0, iAddr=0, sNewWord="", bAvoidLoop=false) {
        // returns a set of suggestions
        // recursive function
        if (sRemain == "") {
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
595
596
597
598
599
600
601

602
603
604
605
606
607
608
609







-
+







                }
                iAddr = iEndArcAddr + this.nBytesNodeAddress;
            }
        }
    }

    * _getArcs1 (iAddr) {
        "generator: return all arcs at <iAddr> as tuples of (nVal, iAddr)"
        // generator: return all arcs at <iAddr> as tuples of (nVal, iAddr)
        while (true) {
            let iEndArcAddr = iAddr+this.nBytesArc;
            let nRawArc = this._convBytesToInteger(this.byDic.slice(iAddr, iEndArcAddr));
            yield [nRawArc & this._arcMask, this._convBytesToInteger(this.byDic.slice(iEndArcAddr, iEndArcAddr+this.nBytesNodeAddress))];
            if (nRawArc & this._lastArcMask) {
                break;
            }
628
629
630
631
632
633
634
635

636
637
636
637
638
639
640
641
642

643
644
645







-
+



    _lookupArcNode3 (nVal, iAddr) {
        // to do
    }
}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.IBDAWG = IBDAWG;
}

Modified graphspell-js/spellchecker.js from [b26374afa0] to [6b69161b99].

1
2
3
4
5
6
7
8
9
10



11
12
13
14
15
16
17






18
19
20
21
22
23
24
25
26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16




17
18
19
20
21
22
23

24
25
26
27
28
29
30










+
+
+



-
-
-
-
+
+
+
+
+
+

-







// Spellchecker
// Wrapper for the IBDAWG class.
// Useful to check several dictionaries at once.

// To avoid iterating over a pile of dictionaries, it is assumed that 3 are enough:
// - the main dictionary, bundled with the package
// - the extended dictionary
// - the community dictionary, added by an organization
// - the personal dictionary, created by the user for its own convenience

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

"use strict";


if (typeof(require) !== 'undefined') {
    var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js");
    var tokenizer = require("resource://grammalecte/graphspell/tokenizer.js");
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"],
    ["en", "en.json"]
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
+







            }
        }
        catch (e) {
            let sfDictionary = (typeof(dictionary) == "string") ? dictionary : dictionary.sLangName + "/" + dictionary.sFileName;
            if (bNecessary) {
                throw "Error: <" + sfDictionary + "> not loaded. " + e.message;
            }
            console.log("Error: <" + sfDictionary + "> not loaded.")
            console.log("Error: <" + sfDictionary + "> not loaded.");
            console.log(e.message);
            return null;
        }
    }

    loadTokenizer () {
        if (typeof(tokenizer) !== 'undefined') {
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228







-
+
















-
+







        // checks if sWord is valid (different casing tested if the first letter is a capital)
        if (this.oMainDic.isValid(sWord)) {
            return true;
        }
        if (this.bExtendedDic && this.oExtendedDic.isValid(sWord)) {
            return true;
        }
        if (this.bCommunityDic && this.oCommunityDic.isValid(sToken)) {
        if (this.bCommunityDic && this.oCommunityDic.isValid(sWord)) {
            return true;
        }
        if (this.bPersonalDic && this.oPersonalDic.isValid(sWord)) {
            return true;
        }
        return false;
    }

    lookup (sWord) {
        // checks if sWord is in dictionary as is (strict verification)
        if (this.oMainDic.lookup(sWord)) {
            return true;
        }
        if (this.bExtendedDic && this.oExtendedDic.lookup(sWord)) {
            return true;
        }
        if (this.bCommunityDic && this.oCommunityDic.lookup(sToken)) {
        if (this.bCommunityDic && this.oCommunityDic.lookup(sWord)) {
            return true;
        }
        if (this.bPersonalDic && this.oPersonalDic.lookup(sWord)) {
            return true;
        }
        return false;
    }
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287







-
+







        if (this.bPersonalDic) {
            yield this.oPersonalDic.suggest(sWord, nSuggLimit);
        }
    }

    * select (sFlexPattern="", sTagsPattern="") {
        // generator: returns all entries which flexion fits <sFlexPattern> and morphology fits <sTagsPattern>
        yield* this.oMainDic.select(sFlexPattern, sTagsPattern)
        yield* this.oMainDic.select(sFlexPattern, sTagsPattern);
        if (this.bExtendedDic) {
            yield* this.oExtendedDic.select(sFlexPattern, sTagsPattern);
        }
        if (this.bCommunityDic) {
            yield* this.oCommunityDic.select(sFlexPattern, sTagsPattern);
        }
        if (this.bPersonalDic) {
297
298
299
300
301
302
303
304

305
306
301
302
303
304
305
306
307

308
309
310







-
+


        if (this.bPersonalDic) {
            lResult.push(...this.oPersonalDic.getSimilarEntries(sWord, nSuggLimit));
        }
        return lResult;
    }
}

if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.SpellChecker = SpellChecker;
}

Modified graphspell-js/str_transform.js from [63ae767339] to [2ff1a56a97].

1
2





3
4
5
6
7
8
9


1
2
3
4
5
6
7
8
9
10
11
12
-
-
+
+
+
+
+







//// STRING TRANSFORMATION
/*jslint esversion: 6*/
// STRING TRANSFORMATION

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

"use strict";


// Note: 48 is the ASCII code for "0"

var str_transform = {
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235







-
+









        let [sPfxCode, sSfxCode] = sAffCode.split('/');
        sWord = sPfxCode.slice(1) + sWord.slice(sPfxCode.charCodeAt(0)-48);
        return sSfxCode[0] == '0' ? sWord + sSfxCode.slice(1) : sWord.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1);
    }
};


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.longestCommonSubstring = str_transform.longestCommonSubstring;
    exports.distanceDamerauLevenshtein = str_transform.distanceDamerauLevenshtein;
    exports.distanceDamerauLevenshtein2 = str_transform.distanceDamerauLevenshtein2;
    exports.showDistance = str_transform.showDistance;
    exports.changeWordWithSuffixCode = str_transform.changeWordWithSuffixCode;
    exports.changeWordWithAffixCode = str_transform.changeWordWithAffixCode;
    exports.defineAffixCode = str_transform.defineAffixCode;
    exports.defineSuffixCode = str_transform.defineSuffixCode;
}

Added graphspell-js/test/minimal.js version [9a28cea93b].


























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global require, console */

"use strict";

/*
Reset = "\x1b[0m"
Bright = "\x1b[1m"
Dim = "\x1b[2m"
Underscore = "\x1b[4m"
Blink = "\x1b[5m"
Reverse = "\x1b[7m"
Hidden = "\x1b[8m"

FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"

BgBlack = "\x1b[40m"
BgRed = "\x1b[41m"
BgGreen = "\x1b[42m"
BgYellow = "\x1b[43m"
BgBlue = "\x1b[44m"
BgMagenta = "\x1b[45m"
BgCyan = "\x1b[46m"
BgWhite = "\x1b[47m"
*/

//console.log('\x1B[2J\x1B[0f'); //Clear the console (cmd win)

var spellCheck = require("../spellchecker.js");
var checker = new spellCheck.SpellChecker('fr', '../_dictionaries');

function perf(sWord){
    console.log('\x1b[1m\x1b[31m%s\x1b[0m', '--------------------------------');

    console.log('\x1b[36m%s \x1b[32m%s\x1b[0m', 'Vérification de:', sWord);
    console.time('Valid:'+sWord);
    console.log(sWord, checker.isValid(sWord) );
    console.timeEnd('Valid:'+sWord);

    console.log('\x1b[36m%s \x1b[32m%s\x1b[0m', 'Suggestion de:', sWord);
    console.time('Suggestion:'+sWord);
    console.log( JSON.stringify( Array.from(checker.suggest(sWord)) ) );
    console.timeEnd('Suggestion:'+sWord);
}

perf('binjour');
perf('saluté');
perf('graphspell');
perf('dicollecte');

Modified graphspell-js/tokenizer.js from [88bacac87d] to [541689c69f].

1
2


3
4


5
6
7
8
9
10
11
1
2
3
4


5
6
7
8
9
10
11
12
13


+
+
-
-
+
+







// JavaScript
// Very simple tokenizer

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

"use strict";


const aTkzPatterns = {
    // All regexps must start with ^.
    "default":
68
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
94
95

96
97
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99







-
+



















-
+


        while (sText) {
            let iCut = 1;
            for (let [zRegex, sType] of this.aRules) {
                if (sType !== "SPACE"  ||  bWithSpaces) {
                    try {
                        if ((m = zRegex.exec(sText)) !== null) {
                            iToken += 1;
                            yield { "i": iToken, "sType": sType, "sValue": m[0], "nStart": iNext, "nEnd": iNext + m[0].length }
                            yield { "i": iToken, "sType": sType, "sValue": m[0], "nStart": iNext, "nEnd": iNext + m[0].length };
                            iCut = m[0].length;
                            break;
                        }
                    }
                    catch (e) {
                        console.error(e);
                    }
                }
            }
            iNext += iCut;
            sText = sText.slice(iCut);
        }
        if (bStartEndToken) {
            yield { "i": iToken+1, "sType": "INFO", "sValue": "<end>", "nStart": iEnd, "nEnd": iEnd, "lMorph": ["<end>"] };
        }
    }
}


if (typeof(exports) !== 'undefined') {
if (typeof exports !== 'undefined') {
    exports.Tokenizer = Tokenizer;
}