Grammalecte  Check-in [4d1ac4562e]

Overview
Comment:[tb] update gce_worker (still not working)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tb | gcerw
Files: files | file ages | folders
SHA3-256: 4d1ac4562e41e6236cbb60ab7f9643f5047429044828b0a71689fc21bac38f73
User & Date: olr on 2020-04-17 20:01:50
Other Links: branch diff | manifest | tags
Context
2020-04-17
20:46
[tb] small update check-in: e85aa05f71 user: olr tags: gcerw, tb
20:01
[tb] update gce_worker (still not working) check-in: 4d1ac4562e user: olr tags: gcerw, tb
19:25
[fr] update Thunderbird path in config.ini check-in: 7d87d0d5dd user: olr tags: fr, gcerw
Changes

Modified gc_core/js/lang_core/gc_engine.js from [0042161b38] to [588d7fb4c8].

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
....
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
            }
            else {
                this.oSpellChecker = new SpellChecker("${lang}", sPath, "${dic_main_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}");
            }
            this.oOptionsColors = gc_options.getOptionsColors(sContext, sColorType);
            this.oTokenizer = this.oSpellChecker.getTokenizer();
            this.oSpellChecker.activateStorage();
            gc_engine_func.load(sContext, this.oSpellChecker)
            gc_options.load(sContext)
        }
        catch (e) {
            console.error(e);
        }
    },

    getSpellChecker: function () {
................................................................................
    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;
    // objects

    exports.oSpellChecker = gc_engine.oSpellChecker;
    exports.oTokenizer = gc_engine.oTokenizer;
    exports.aIgnoredRules = gc_engine.aIgnoredRules;
    exports.oOptionsColors = gc_engine.oOptionsColors;
    // init
    exports.load = gc_engine.load;
    exports.parse = gc_engine.parse;







|
|







 







>







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
....
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
            }
            else {
                this.oSpellChecker = new SpellChecker("${lang}", sPath, "${dic_main_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}");
            }
            this.oOptionsColors = gc_options.getOptionsColors(sContext, sColorType);
            this.oTokenizer = this.oSpellChecker.getTokenizer();
            this.oSpellChecker.activateStorage();
            gc_engine_func.load(sContext, this.oSpellChecker);
            gc_options.load(sContext);
        }
        catch (e) {
            console.error(e);
        }
    },

    getSpellChecker: function () {
................................................................................
    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;
    // objects
    exports.getSpellChecker = gc_engine.getSpellChecker;
    exports.oSpellChecker = gc_engine.oSpellChecker;
    exports.oTokenizer = gc_engine.oTokenizer;
    exports.aIgnoredRules = gc_engine.aIgnoredRules;
    exports.oOptionsColors = gc_engine.oOptionsColors;
    // init
    exports.load = gc_engine.load;
    exports.parse = gc_engine.parse;

Modified gc_lang/fr/mailext/worker/gce_worker.js from [420e3521e3] to [19b6bbcbb9].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
..
98
99
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
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
// JavaScript

// Grammar checker engine
// PromiseWorker
// This code is executed in a separate thread (×20 faster too!!!)

// Firefox WTF: it’s impossible to use require as in the main thread here,
// so it is required to declare a resource in the file “chrome.manifest”.


"use strict";

// copy/paste
// https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/PromiseWorker.jsm

................................................................................

// Connect it to message port.
self.addEventListener("message", msg => worker.handleMessage(msg));

// end of copy/paste


// no console here, use “dump”

let gce = null; // module: grammar checker engine
let gco = null;

let text = null;
let tkz = null; // module: tokenizer
let lxg = null; // module: lexicographer
let helpers = null;

let oTokenizer = null;
let oSpellChecker = null;
let oLxg = null;


function loadGrammarChecker (sGCOptions="", sContext="JavaScript") {
    if (gce === null) {
        try {
            gco = require("resource://grammalecte/fr/gc_options.js");
            gce = require("resource://grammalecte/fr/gc_engine.js");
            helpers = require("resource://grammalecte/graphspell/helpers.js");
            text = require("resource://grammalecte/text.js");
            tkz = require("resource://grammalecte/graphspell/tokenizer.js");
            //lxg = require("resource://grammalecte/fr/lexicographe.js");
            oTokenizer = new tkz.Tokenizer("fr");
            gce.load(sContext, "sCSS");
            oSpellChecker = gce.getSpellChecker();
            if (sGCOptions !== "") {

                gco.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
            }
            // we always retrieve options from the gce, for setOptions filters obsolete options
            return gco.getOptions().gl_toString();
        }
        catch (e) {
            console.log("# Error: " + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
        }
    }
}

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

function parse (sText, sCountry, bDebug, bContext) {
    let aGrammErr = gce.parse(sText, sCountry, bDebug, bContext);
    return JSON.stringify(aGrammErr);
}

function parseAndSpellcheck (sText, sCountry, bDebug, bContext) {
    let aGrammErr = gce.parse(sText, sCountry, bDebug, null, bContext);
    let aSpellErr = oSpellChecker.parseParagraph(sText);
    return JSON.stringify({ aGrammErr: aGrammErr, aSpellErr: aSpellErr });
}

function suggest (sWord, nSuggLimit=10) {
    let lSugg = []
    for (let aSugg of oSpellChecker.suggest(sWord, nSuggLimit)) {
        lSugg.push(...aSugg);
    }
    return lSugg.join("|");
}

function getOptions () {
    return gco.getOptions().gl_toString();
}

function getDefaultOptions () {
    return gco.getDefaultOptions().gl_toString();
}

function setOptions (sGCOptions) {
    gco.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    return gco.getOptions().gl_toString();
}

function setOption (sOptName, bValue) {
    gco.setOptions(new Map([ [sOptName, bValue] ]));
    return gco.getOptions().gl_toString();
}

function resetOptions () {
    gco.resetOptions();
    return gco.getOptions().gl_toString();
}

function fullTests (sGCOptions="") {
    if (!gce || !oSpellChecker || !gco) {
        return "# Error: grammar checker or dictionary not loaded."
    }
    let dMemoOptions = gco.getOptions();
    if (sGCOptions) {
        gco.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    }
    let tests = require("resource://grammalecte/tests.js");
    let oTest = new tests.TestGrammarChecking(gce);
    let sAllRes = "";
    for (let sRes of oTest.testParse()) {
        console.log(sRes+"\n");
        sAllRes += sRes+"\n";
    }
    gco.setOptions(dMemoOptions);
    return sAllRes;
}




<
<
<
<







 







<
<
|
<
>
|
<
|


<

<

>

|

|
|


|
<
<
|
|

>
|

|
|







 







|




|













|



|



|
|



|
|



|
|



|


|

|


|





|


1
2
3
4




5
6
7
8
9
10
11
..
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
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
117
118
119
120
121
122
123
124
125
126
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
153
154
// JavaScript

// Grammar checker engine
// PromiseWorker






"use strict";

// copy/paste
// https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/PromiseWorker.jsm

................................................................................

// Connect it to message port.
self.addEventListener("message", msg => worker.handleMessage(msg));

// end of copy/paste




let gc_engine = null; // module: grammar checker engine

let gc_options = null; // module: grammar checker options
let text = null; // module: text

let lexgraph_fr = null; // module: lexicographer
let helpers = null;


let oSpellChecker = null;



function loadGrammarChecker (sGCOptions="", sContext="JavaScript") {
    if (gc_engine === null) {
        try {
            gc_options = require("resource://grammalecte/fr/gc_options.js");
            gc_engine = require("resource://grammalecte/fr/gc_engine.js");
            helpers = require("resource://grammalecte/graphspell/helpers.js");
            text = require("resource://grammalecte/text.js");
            //lexgraph_fr = require("resource://grammalecte/graphspell/lexgraph_fr.js");


            gc_engine.load(sContext, "sCSS");
            oSpellChecker = gc_engine.getSpellChecker();
            if (sGCOptions !== "") {
                console.log(sGCOptions);
                gc_options.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
            }
            // we always retrieve options from the gc_engine, for setOptions filters obsolete options
            return gc_options.getOptions().gl_toString();
        }
        catch (e) {
            console.log("# Error: " + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
        }
    }
}

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

function parse (sText, sCountry, bDebug, bContext) {
    let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
    return JSON.stringify(aGrammErr);
}

function parseAndSpellcheck (sText, sCountry, bDebug, bContext) {
    let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, null, bContext);
    let aSpellErr = oSpellChecker.parseParagraph(sText);
    return JSON.stringify({ aGrammErr: aGrammErr, aSpellErr: aSpellErr });
}

function suggest (sWord, nSuggLimit=10) {
    let lSugg = []
    for (let aSugg of oSpellChecker.suggest(sWord, nSuggLimit)) {
        lSugg.push(...aSugg);
    }
    return lSugg.join("|");
}

function getOptions () {
    return gc_options.getOptions().gl_toString();
}

function getDefaultOptions () {
    return gc_options.getDefaultOptions().gl_toString();
}

function setOptions (sGCOptions) {
    gc_options.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    return gc_options.getOptions().gl_toString();
}

function setOption (sOptName, bValue) {
    gc_options.setOptions(new Map([ [sOptName, bValue] ]));
    return gc_options.getOptions().gl_toString();
}

function resetOptions () {
    gc_options.resetOptions();
    return gc_options.getOptions().gl_toString();
}

function fullTests (sGCOptions="") {
    if (!gc_engine || !oSpellChecker || !gc_options) {
        return "# Error: grammar checker or dictionary not loaded."
    }
    let dMemoOptions = gc_options.getOptions();
    if (sGCOptions) {
        gc_options.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    }
    let tests = require("resource://grammalecte/tests.js");
    let oTest = new tests.TestGrammarChecking(gc_engine, gc_options);
    let sAllRes = "";
    for (let sRes of oTest.testParse()) {
        console.log(sRes+"\n");
        sAllRes += sRes+"\n";
    }
    gc_options.setOptions(dMemoOptions);
    return sAllRes;
}