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
|
//console.log("[Worker] GC Engine Worker [start]");
//console.log(self);
importScripts("grammalecte/graphspell/helpers.js");
importScripts("grammalecte/graphspell/str_transform.js");
importScripts("grammalecte/graphspell/char_player.js");
importScripts("grammalecte/graphspell/suggest.js");
importScripts("grammalecte/graphspell/ibdawg.js");
importScripts("grammalecte/graphspell/spellchecker.js");
importScripts("grammalecte/text.js");
importScripts("grammalecte/graphspell/tokenizer.js");
importScripts("grammalecte/fr/conj.js");
importScripts("grammalecte/fr/mfsp.js");
importScripts("grammalecte/fr/phonet.js");
importScripts("grammalecte/fr/cregex.js");
importScripts("grammalecte/fr/gc_options.js");
importScripts("grammalecte/fr/gc_rules.js");
importScripts("grammalecte/fr/gc_rules_graph.js");
importScripts("grammalecte/fr/gc_engine.js");
importScripts("grammalecte/fr/lexicographe.js");
importScripts("grammalecte/tests.js");
/*
Warning.
Initialization can’t be completed at startup of the worker,
for we need the path of the extension to load data stored in JSON files.
|
|
>
|
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
|
//console.log("[Worker] GC Engine Worker [start]");
//console.log(self);
importScripts("grammalecte/graphspell/helpers.js");
importScripts("grammalecte/graphspell/str_transform.js");
importScripts("grammalecte/graphspell/char_player.js");
importScripts("grammalecte/graphspell/lexgraph_fr.js");
importScripts("grammalecte/graphspell/ibdawg.js");
importScripts("grammalecte/graphspell/spellchecker.js");
importScripts("grammalecte/text.js");
importScripts("grammalecte/graphspell/tokenizer.js");
importScripts("grammalecte/fr/conj.js");
importScripts("grammalecte/fr/mfsp.js");
importScripts("grammalecte/fr/phonet.js");
importScripts("grammalecte/fr/cregex.js");
importScripts("grammalecte/fr/gc_options.js");
importScripts("grammalecte/fr/gc_rules.js");
importScripts("grammalecte/fr/gc_rules_graph.js");
importScripts("grammalecte/fr/gc_engine_func.js");
importScripts("grammalecte/fr/gc_engine.js");
importScripts("grammalecte/fr/lexicographe.js");
importScripts("grammalecte/tests.js");
/*
Warning.
Initialization can’t be completed at startup of the worker,
for we need the path of the extension to load data stored in JSON files.
|
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
let bInitDone = false;
let oSpellChecker = null;
let oTokenizer = null;
let oLxg = null;
let oTest = null;
let oLocution = null;
/*
Technical note:
This worker don’t work as a PromiseWorker (which returns a promise), so when we send request
|
<
|
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
let bInitDone = false;
let oSpellChecker = null;
let oTokenizer = null;
let oTest = null;
let oLocution = null;
/*
Technical note:
This worker don’t work as a PromiseWorker (which returns a promise), so when we send request
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json"));
//console.log("[Worker] Modules have been initialized…");
gc_engine.load(sContext, "aHSL", sExtensionPath+"grammalecte/graphspell/_dictionaries");
oSpellChecker = gc_engine.getSpellChecker();
oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
oTokenizer = new Tokenizer("fr");
oLocution = helpers.loadFile(sExtensionPath + "/grammalecte/fr/locutions_data.json");
oLxg = new Lexicographe(oSpellChecker, oTokenizer, oLocution);
if (dOptions !== null) {
if (!(dOptions instanceof Map)) {
dOptions = helpers.objectToMap(dOptions);
}
gc_engine.setOptions(dOptions);
}
//tests();
bInitDone = true;
} else {
console.log("[Worker] Already initialized…")
}
// we always retrieve options from the gc_engine, for setOptions filters obsolete options
dOptions = helpers.mapToObject(gc_engine.getOptions());
postMessage(createResponse("init", dOptions, oInfo, true));
}
catch (e) {
console.error(e);
postMessage(createResponse("init", createErrorResult(e, "init failed"), oInfo, true, true));
}
}
|
|
|
|
|
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json"));
//console.log("[Worker] Modules have been initialized…");
gc_engine.load(sContext, "aHSL", sExtensionPath+"grammalecte/graphspell/_dictionaries");
oSpellChecker = gc_engine.getSpellChecker();
oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
oTokenizer = new Tokenizer("fr");
oLocution = helpers.loadFile(sExtensionPath + "/grammalecte/fr/locutions_data.json");
lexgraph_fr.load(oSpellChecker, oTokenizer, oLocution);
if (dOptions !== null) {
if (!(dOptions instanceof Map)) {
dOptions = helpers.objectToMap(dOptions);
}
gc_options.setOptions(dOptions);
}
//tests();
bInitDone = true;
} else {
console.log("[Worker] Already initialized…")
}
// we always retrieve options from the gc_options, for setOptions filters obsolete options
dOptions = helpers.mapToObject(gc_options.getOptions());
postMessage(createResponse("init", dOptions, oInfo, true));
}
catch (e) {
console.error(e);
postMessage(createResponse("init", createErrorResult(e, "init failed"), oInfo, true, true));
}
}
|
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
function getListOfTokens (sText, oInfo={}) {
// lexicographer
try {
sText = sText.replace(//g, "").normalize("NFC");
for (let sParagraph of text.getParagraph(sText)) {
if (sParagraph.trim() !== "") {
postMessage(createResponse("getListOfTokens", oLxg.getListOfTokensReduc(sParagraph, true), oInfo, false));
}
}
postMessage(createResponse("getListOfTokens", null, oInfo, true));
}
catch (e) {
console.error(e);
postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true));
|
|
|
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
function getListOfTokens (sText, oInfo={}) {
// lexicographer
try {
sText = sText.replace(//g, "").normalize("NFC");
for (let sParagraph of text.getParagraph(sText)) {
if (sParagraph.trim() !== "") {
postMessage(createResponse("getListOfTokens", lexgraph_fr.getListOfTokensReduc(sParagraph, true), oInfo, false));
}
}
postMessage(createResponse("getListOfTokens", null, oInfo, true));
}
catch (e) {
console.error(e);
postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true));
|