174
175
176
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
|
//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");
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));
}
}
|
|
|
|
|
|
|
173
174
175
176
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
|
//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);
}
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
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
|
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));
}
}
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));
|
|
|
|
|
|
|
|
|
|
|
245
246
247
248
249
250
251
252
253
254
255
256
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
|
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));
}
}
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) {
|