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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
let bInitDone = false;
let oDict = null;
let oTokenizer = null;
let oLxg = null;
let oTest = null;
function init (sExtensionPath, sGCOptions="", sContext="JavaScript", dInfo={}) {
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"));
console.log("[Worker] Modules have been initialized…");
gc_engine.load(sContext, sExtensionPath+"grammalecte/_dictionaries");
oDict = gc_engine.getDictionary();
oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
oLxg = new Lexicographe(oDict);
if (sGCOptions !== "") {
gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
}
oTokenizer = new Tokenizer("fr");
tests();
bInitDone = true;
} else {
console.log("[Worker] Already initialized…")
}
// we always retrieve options from the gc_engine, for setOptions filters obsolete options
postMessage(createResponse("init", gc_engine.getOptions().gl_toString(), dInfo, true));
}
catch (e) {
helpers.logerror(e);
postMessage(createResponse("init", createErrorResult(e, "init failed"), dInfo, true, true));
}
}
function parse (sText, sCountry, bDebug, bContext, dInfo={}) {
let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
postMessage({sActionDone: "parse", result: aGrammErr, dInfo: dInfo});
}
function parseAndSpellcheck (sText, sCountry, bDebug, bContext, dInfo={}) {
let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
let aSpellErr = oTokenizer.getSpellingErrors(sText, oDict);
postMessage(createResponse("parseAndSpellcheck", {aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo, true));
}
function getOptions (dInfo={}) {
postMessage(createResponse("getOptions", gc_engine.getOptions().gl_toString(), dInfo, true));
}
function getDefaultOptions (dInfo={}) {
|
>
>
>
>
>
>
>
>
>
|
>
|
|
>
>
>
>
|
|
>
>
>
|
|
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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
let bInitDone = false;
let oDict = null;
let oTokenizer = null;
let oLxg = null;
let oTest = null;
/*
Technical note:
This worker don’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, sGCOptions="", sContext="JavaScript", dInfo={}) {
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"));
console.log("[Worker] Modules have been initialized…");
gc_engine.load(sContext, sExtensionPath+"grammalecte/_dictionaries");
oDict = gc_engine.getDictionary();
oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
oLxg = new Lexicographe(oDict);
if (sGCOptions !== "") {
gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
}
oTokenizer = new Tokenizer("fr");
//tests();
bInitDone = true;
} else {
console.log("[Worker] Already initialized…")
}
// we always retrieve options from the gc_engine, for setOptions filters obsolete options
postMessage(createResponse("init", gc_engine.getOptions().gl_toString(), dInfo, true));
}
catch (e) {
helpers.logerror(e);
postMessage(createResponse("init", createErrorResult(e, "init failed"), dInfo, true, true));
}
}
function parse (sText, sCountry, bDebug, bContext, dInfo={}) {
for (let sParagraph of text.getParagraph(sText)) {
let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, bContext);
postMessage(createResponse("parse", aGrammErr, dInfo, false));
}
postMessage(createResponse("parse", null, dInfo, true));
}
function parseAndSpellcheck (sText, sCountry, bDebug, bContext, dInfo={}) {
let n = 0;
for (let sParagraph of text.getParagraph(sText)) {
let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, bContext);
let aSpellErr = oTokenizer.getSpellingErrors(sParagraph, oDict);
n += 1;
postMessage(createResponse("parseAndSpellcheck", {sParagraph: sParagraph, sParaNum: n.toString(), aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo, false));
}
postMessage(createResponse("parseAndSpellcheck", null, dInfo, true));
}
function getOptions (dInfo={}) {
postMessage(createResponse("getOptions", gc_engine.getOptions().gl_toString(), dInfo, true));
}
function getDefaultOptions (dInfo={}) {
|