︙ | | | ︙ | |
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
s += "\n";
}
return s;
}
parse (sText, sCountry="${country_default}", bDebug=false, dOptions=null, bContext=false) {
// analyses the paragraph sText and returns list of errors
let dOpt = dOptions || gc_engine.dOptions;
// parse paragraph
try {
this.parseText(this.sText, this.sText0, true, 0, sCountry, dOpt, bDebug, bContext);
}
catch (e) {
console.error(e);
}
|
|
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
s += "\n";
}
return s;
}
parse (sText, sCountry="${country_default}", bDebug=false, dOptions=null, bContext=false) {
// analyses the paragraph sText and returns list of errors
let dOpt = dOptions || _dOptions;
// parse paragraph
try {
this.parseText(this.sText, this.sText0, true, 0, sCountry, dOpt, bDebug, bContext);
}
catch (e) {
console.error(e);
}
|
︙ | | | ︙ | |
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
}
return Array.from(this.dError.values());
}
parseText (sText, sText0, bParagraph, nOffset, sCountry, dOptions, bDebug, bContext) {
let bChange = false;
let bIdRule = option('idrule');
for (let [sOption, lRuleGroup] of gc_engine.getRules(bParagraph)) {
if (sOption == "@@@@") {
// graph rules
if (!bParagraph && bChange) {
this.update(sText, bDebug);
bChange = false;
|
>
|
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
}
return Array.from(this.dError.values());
}
parseText (sText, sText0, bParagraph, nOffset, sCountry, dOptions, bDebug, bContext) {
let bChange = false;
let bIdRule = option('idrule');
let m;
for (let [sOption, lRuleGroup] of gc_engine.getRules(bParagraph)) {
if (sOption == "@@@@") {
// graph rules
if (!bParagraph && bChange) {
this.update(sText, bDebug);
bChange = false;
|
︙ | | | ︙ | |
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
|
}
}
}
else if (!sOption || option(sOption)) {
for (let [zRegex, bUppercase, sLineId, sRuleId, nPriority, lActions, lGroups, lNegLookBefore] of lRuleGroup) {
if (!_aIgnoredRules.has(sRuleId)) {
while ((m = zRegex.gl_exec2(sText, lGroups, lNegLookBefore)) !== null) {
bCondMemo = null;
for (let [sFuncCond, cActionType, sWhat, ...eAct] of lActions) {
// action in lActions: [ condition, action type, replacement/suggestion/action[, iGroup[, message, URL]] ]
try {
bCondMemo = (!sFuncCond || oEvalFunc[sFuncCond](sText, sText0, m, dDA, sCountry, bCondMemo));
if (bCondMemo) {
switch (cActionType) {
case "-":
// grammar error
//console.log("-> error detected in " + sLineId + "\nzRegex: " + zRegex.source);
nErrorStart = nOffset + m.start[eAct[0]];
if (!this.dError.has(nErrorStart) || nPriority > this.dErrorPriority.get(nErrorStart)) {
this.dError.set(nErrorStart, this._createErrorFromRegex(sText, sText0, sWhat, nOffset, m, eAct[0], sLineId, sRuleId, bUppercase, eAct[1], eAct[2], bIdRule, sOption, bContext));
this.dErrorPriority.set(nErrorStart, nPriority);
}
break;
case "~":
// text processor
|
|
|
|
|
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
|
}
}
}
else if (!sOption || option(sOption)) {
for (let [zRegex, bUppercase, sLineId, sRuleId, nPriority, lActions, lGroups, lNegLookBefore] of lRuleGroup) {
if (!_aIgnoredRules.has(sRuleId)) {
while ((m = zRegex.gl_exec2(sText, lGroups, lNegLookBefore)) !== null) {
let bCondMemo = null;
for (let [sFuncCond, cActionType, sWhat, ...eAct] of lActions) {
// action in lActions: [ condition, action type, replacement/suggestion/action[, iGroup[, message, URL]] ]
try {
bCondMemo = (!sFuncCond || oEvalFunc[sFuncCond](sText, sText0, m, this.dTokenPos, sCountry, bCondMemo));
if (bCondMemo) {
switch (cActionType) {
case "-":
// grammar error
//console.log("-> error detected in " + sLineId + "\nzRegex: " + zRegex.source);
let nErrorStart = nOffset + m.start[eAct[0]];
if (!this.dError.has(nErrorStart) || nPriority > this.dErrorPriority.get(nErrorStart)) {
this.dError.set(nErrorStart, this._createErrorFromRegex(sText, sText0, sWhat, nOffset, m, eAct[0], sLineId, sRuleId, bUppercase, eAct[1], eAct[2], bIdRule, sOption, bContext));
this.dErrorPriority.set(nErrorStart, nPriority);
}
break;
case "~":
// text processor
|
︙ | | | ︙ | |
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
} else {
if (cActionType == ">") {
break;
}
}
}
catch (e) {
console.log(s);
console.log("# line id: " + sLineId + "\n# rule id: " + sRuleId);
console.error(e);
}
}
}
}
}
|
|
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
} else {
if (cActionType == ">") {
break;
}
}
}
catch (e) {
console.log(sText);
console.log("# line id: " + sLineId + "\n# rule id: " + sRuleId);
console.error(e);
}
}
}
}
}
|
︙ | | | ︙ | |
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
}
update (sSentence, bDebug=false) {
// update <sSentence> and retokenize
this.sSentence = sSentence;
let lNewToken = Array.from(_oTokenizer.genTokens(sSentence, true));
for (let dToken of lNewToken) {
if (this.dTokenPos.gl_get(dToken["nStart"], {}).has("lMorph")) {
dToken["lMorph"] = this.dTokenPos.gl_get(dToken["nStart"], {}).get("lMorph");
}
if (this.dTokenPos.gl_get(dToken["nStart"], {}).has("tags")) {
dToken["tags"] = this.dTokenPos.gl_get(dToken["nStart"], {}).get("tags");
}
}
this.lToken = lNewToken;
this.dTokenPos.clear();
for (let dToken of this.lToken) {
if (dToken["sType"] != "INFO") {
this.dTokenPos.set(dToken["nStart"], dToken);
|
|
|
|
|
|
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
}
update (sSentence, bDebug=false) {
// update <sSentence> and retokenize
this.sSentence = sSentence;
let lNewToken = Array.from(_oTokenizer.genTokens(sSentence, true));
for (let dToken of lNewToken) {
if (this.dTokenPos.gl_get(dToken["nStart"], {}).hasOwnProperty("lMorph")) {
dToken["lMorph"] = this.dTokenPos.get(dToken["nStart"])["lMorph"];
}
if (this.dTokenPos.gl_get(dToken["nStart"], {}).hasOwnProperty("tags")) {
dToken["tags"] = this.dTokenPos.get(dToken["nStart"])["tags"];
}
}
this.lToken = lNewToken;
this.dTokenPos.clear();
for (let dToken of this.lToken) {
if (dToken["sType"] != "INFO") {
this.dTokenPos.set(dToken["nStart"], dToken);
|
︙ | | | ︙ | |
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
|
}
}
}
return bChange;
}
_createErrorFromRegex (sText, sText0, sSugg, nOffset, m, iGroup, sLineId, sRuleId, bUppercase, sMsg, sURL, bShowRuleId, sOption, bContext) {
let nStart = nOffset + m.start(iGroup);
let nEnd = nOffset + m.end(iGroup);
// suggestions
let lSugg = [];
if (sSugg.startsWith("=")) {
sSugg = oEvalFunc[sSugg.slice(1)](sText, m);
lSugg = (sSugg) ? sSugg.split("|") : [];
} else if (sSugg == "_") {
lSugg = [];
|
|
|
|
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
|
}
}
}
return bChange;
}
_createErrorFromRegex (sText, sText0, sSugg, nOffset, m, iGroup, sLineId, sRuleId, bUppercase, sMsg, sURL, bShowRuleId, sOption, bContext) {
let nStart = nOffset + m.start[iGroup];
let nEnd = nOffset + m.end[iGroup];
// suggestions
let lSugg = [];
if (sSugg.startsWith("=")) {
sSugg = oEvalFunc[sSugg.slice(1)](sText, m);
lSugg = (sSugg) ? sSugg.split("|") : [];
} else if (sSugg == "_") {
lSugg = [];
|
︙ | | | ︙ | |
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
|
sMessage += " ## " + sLineId + " # " + sRuleId;
}
//
return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext);
}
_createError (nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) {
oErr = {
"nStart": nStart,
"nEnd": nEnd,
"sLineId": sLineId,
"sRuleId": sRuleId,
"sType": sOption || "notype",
"sMessage": sMessage,
"aSuggestions": lSugg,
|
|
|
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
|
sMessage += " ## " + sLineId + " # " + sRuleId;
}
//
return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext);
}
_createError (nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) {
let oErr = {
"nStart": nStart,
"nEnd": nEnd,
"sLineId": sLineId,
"sRuleId": sRuleId,
"sType": sOption || "notype",
"sMessage": sMessage,
"aSuggestions": lSugg,
|
︙ | | | ︙ | |