45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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.
This path is retrieved in background.js and passed with the event “init”.
*/
|
<
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
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/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.
This path is retrieved in background.js and passed with the event “init”.
*/
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
//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"));
//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);
}
|
|
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
//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"));
//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, gc_options, 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);
}
|
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
catch (e) {
console.error(e);
postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true));
}
}
function getOptions (oInfo={}) {
let dOptions = helpers.mapToObject(gc_engine.getOptions());
postMessage(createResponse("getOptions", dOptions, oInfo, true));
}
function getDefaultOptions (oInfo={}) {
let dOptions = helpers.mapToObject(gc_engine.getDefaultOptions());
postMessage(createResponse("getDefaultOptions", dOptions, oInfo, true));
}
function setOptions (dOptions, oInfo={}) {
if (!(dOptions instanceof Map)) {
dOptions = helpers.objectToMap(dOptions);
}
gc_engine.setOptions(dOptions);
dOptions = helpers.mapToObject(gc_engine.getOptions());
postMessage(createResponse("setOptions", dOptions, oInfo, true));
}
function setOption (sOptName, bValue, oInfo={}) {
console.log(sOptName+": "+bValue);
if (sOptName) {
gc_engine.setOption(sOptName, bValue);
let dOptions = helpers.mapToObject(gc_engine.getOptions());
postMessage(createResponse("setOption", dOptions, oInfo, true));
}
}
function resetOptions (oInfo={}) {
gc_engine.resetOptions();
let dOptions = helpers.mapToObject(gc_engine.getOptions());
postMessage(createResponse("resetOptions", dOptions, oInfo, true));
}
function tests () {
console.log(conj.getConj("devenir", ":E", ":2s"));
console.log(mfsp.getMasForm("emmerdeuse", true));
console.log(mfsp.getMasForm("pointilleuse", false));
|
|
|
|
|
|
|
|
|
|
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
catch (e) {
console.error(e);
postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true));
}
}
function getOptions (oInfo={}) {
let dOptions = helpers.mapToObject(gc_options.getOptions());
postMessage(createResponse("getOptions", dOptions, oInfo, true));
}
function getDefaultOptions (oInfo={}) {
let dOptions = helpers.mapToObject(gc_options.getDefaultOptions());
postMessage(createResponse("getDefaultOptions", dOptions, oInfo, true));
}
function setOptions (dOptions, oInfo={}) {
if (!(dOptions instanceof Map)) {
dOptions = helpers.objectToMap(dOptions);
}
gc_options.setOptions(dOptions);
dOptions = helpers.mapToObject(gc_options.getOptions());
postMessage(createResponse("setOptions", dOptions, oInfo, true));
}
function setOption (sOptName, bValue, oInfo={}) {
console.log(sOptName+": "+bValue);
if (sOptName) {
gc_options.setOption(sOptName, bValue);
let dOptions = helpers.mapToObject(gc_options.getOptions());
postMessage(createResponse("setOption", dOptions, oInfo, true));
}
}
function resetOptions (oInfo={}) {
gc_options.resetOptions();
let dOptions = helpers.mapToObject(gc_options.getOptions());
postMessage(createResponse("resetOptions", dOptions, oInfo, true));
}
function tests () {
console.log(conj.getConj("devenir", ":E", ":2s"));
console.log(mfsp.getMasForm("emmerdeuse", true));
console.log(mfsp.getMasForm("pointilleuse", false));
|
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
349
350
|
}
function fullTests (oInfo={}) {
if (!gc_engine) {
postMessage(createResponse("fullTests", "# Grammar checker not loaded.", oInfo, true));
return;
}
let dMemoOptions = gc_engine.getOptions();
let dTestOptions = gc_engine.getDefaultOptions();
dTestOptions.set("nbsp", true);
dTestOptions.set("esp", true);
dTestOptions.set("unit", true);
dTestOptions.set("num", true);
gc_engine.setOptions(dTestOptions);
let sMsg = "";
for (let sRes of oTest.testParse()) {
sMsg += sRes + "\n";
console.log(sRes);
}
gc_engine.setOptions(dMemoOptions);
postMessage(createResponse("fullTests", sMsg, oInfo, true));
}
// SpellChecker
function setDictionary (sDictionary, oDict, oInfo) {
|
|
|
|
|
|
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
349
|
}
function fullTests (oInfo={}) {
if (!gc_engine) {
postMessage(createResponse("fullTests", "# Grammar checker not loaded.", oInfo, true));
return;
}
let dMemoOptions = gc_options.getOptions();
let dTestOptions = gc_options.getDefaultOptions();
dTestOptions.set("nbsp", true);
dTestOptions.set("esp", true);
dTestOptions.set("unit", true);
dTestOptions.set("num", true);
gc_options.setOptions(dTestOptions);
let sMsg = "";
for (let sRes of oTest.testParse()) {
sMsg += sRes + "\n";
console.log(sRes);
}
gc_options.setOptions(dMemoOptions);
postMessage(createResponse("fullTests", sMsg, oInfo, true));
}
// SpellChecker
function setDictionary (sDictionary, oDict, oInfo) {
|