39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
+
|
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/thesaurus.js");
importScripts("grammalecte/fr/cregex.js");
importScripts("grammalecte/fr/gc_options.js");
importScripts("grammalecte/fr/gc_functions.js");
importScripts("grammalecte/fr/gc_rules.js");
importScripts("grammalecte/fr/gc_rules_graph.js");
importScripts("grammalecte/fr/gc_engine.js");
importScripts("grammalecte/tests.js");
|
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
+
+
+
-
+
+
|
break;
case "getSpellSuggestions":
getSpellSuggestions(oParam.sWord, oInfo);
break;
case "getVerb":
getVerb(oParam.sVerb, oParam.bPro, oParam.bNeg, oParam.bTpsCo, oParam.bInt, oParam.bFem, oInfo);
break;
case "getSyns":
getSyns(oParam.sWord, oInfo);
break;
default:
console.log("[Worker] Unknown command: " + sCommand);
showData(e.data);
}
}
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
This worker doesn’t work as a PromiseWorker (which returns a promise), so when we send request
to this worker, we can’t wait the return of the answer just after the request made.
The answer is received by the background in another function (onmessage).
That’s why the full text to analyze is send in one block, but analyse is returned paragraph
by paragraph.
*/
function init (sExtensionPath, dOptions=null, sContext="JavaScript", oInfo={}) {
try {
if (!bInitDone) {
//console.log("[Worker] Loading… Extension path: " + sExtensionPath);
conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json"));
phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json"));
mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json"));
thesaurus.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/thesaurus_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");
if (dOptions !== null) {
if (!(dOptions instanceof Map)) {
|
427
428
429
430
431
432
433
|
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
postMessage(createResponse("getVerb", { oVerb: oVerb, oConjTable: oConjTable }, oInfo, true));
}
catch (e) {
console.error(e);
postMessage(createResponse("getVerb", createErrorResult(e, "no verb"), oInfo, true, true));
}
}
// Thesaurus
function getSyns (sWord, oInfo) {
try {
let lSyns = thesaurus.getSyns(sWord)
postMessage(createResponse("getSyns", { sWord: sWord, lSyns: lSyns }, oInfo, true));
}
catch (e) {
console.error(e);
postMessage(createResponse("getSyns", createErrorResult(e, "no synonyms"), oInfo, true, true));
}
}
|