Overview
Comment: | [core][js] gc engine: code rewriting |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | core | gcerw |
Files: | files | file ages | folders |
SHA3-256: |
42fa8f123aa4ff485705e781fee01e5d |
User & Date: | olr on 2020-04-06 20:01:22 |
Other Links: | branch diff | manifest | tags |
Context
2020-04-06
| ||
20:43 | [tb][js] update gce_worker check-in: 9fd78a9ee5 user: olr tags: tb, gcerw | |
20:01 | [core][js] gc engine: code rewriting check-in: 42fa8f123a user: olr tags: core, gcerw | |
19:12 | [core][py] add echo to gc_engine_func.py check-in: e9d7f69946 user: olr tags: core, gcerw | |
Changes
Modified gc_core/js/lang_core/gc_engine.js from [224c579d52] to [6a386c1d36].
1 2 3 4 5 6 7 8 9 10 11 12 13 | // Grammar checker engine /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global require, exports, console */ "use strict"; ${string} ${regex} ${map} | | > > | > < < < < < < < < < < < < < < < > > > > > > > > | | > | | > | | < < | | | > > | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | // Grammar checker engine /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global require, exports, console */ "use strict"; ${string} ${regex} ${map} if (typeof(process) !== 'undefined') { var gc_engine_func = require("./gc_engine_func.js"); var gc_options = require("./gc_options.js"); var gc_rules = require("./gc_rules.js"); var gc_rules_graph = require("./gc_rules_graph.js"); var cregex = require("./cregex.js"); var text = require("../text.js"); } else if (typeof(require) !== 'undefined') { var gc_engine_func = require("resource://grammalecte/${lang}/gc_engine_func.js"); var gc_options = require("resource://grammalecte/${lang}/gc_options.js"); var gc_rules = require("resource://grammalecte/${lang}/gc_rules.js"); var gc_rules_graph = require("resource://grammalecte/${lang}/gc_rules_graph.js"); var cregex = require("resource://grammalecte/${lang}/cregex.js"); var text = require("resource://grammalecte/text.js"); } function capitalizeArray (aArray) { // can’t map on user defined function?? let aNew = []; for (let i = 0; i < aArray.length; i = i + 1) { aNew[i] = aArray[i].slice(0,1).toUpperCase() + aArray[i].slice(1); } return aNew; } var gc_engine = { //// Informations lang: "${lang}", locales: ${loc}, pkg: "${implname}", name: "${name}", version: "${version}", author: "${author}", //// Tools oSpellChecker: null, oTokenizer: null, //// Data aIgnoredRules: new Set(), oOptionsColors: null, //// Initialization load: function (sContext="JavaScript", sColorType="aRGB", sPath="") { try { if (typeof(process) !== 'undefined') { var spellchecker = require("../graphspell/spellchecker.js"); this.oSpellChecker = new spellchecker.SpellChecker("${lang}", "", "${dic_main_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}"); } else if (typeof(require) !== 'undefined') { var spellchecker = require("resource://grammalecte/graphspell/spellchecker.js"); this.oSpellChecker = new spellchecker.SpellChecker("${lang}", "", "${dic_main_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}"); } else { this.oSpellChecker = new SpellChecker("${lang}", sPath, "${dic_main_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}"); } this.oOptionsColors = gc_options.getOptionsColors(sContext, sColorType); this.oTokenizer = this.oSpellChecker.getTokenizer(); this.oSpellChecker.activateStorage(); gc_engine_func.load(sContext, this.oSpellChecker) gc_options.load(sContext) } catch (e) { console.error(e); } }, getSpellChecker: function () { return this.oSpellChecker; }, //// Rules getRules: function (bParagraph) { if (!bParagraph) { return gc_rules.lSentenceRules; } return gc_rules.lParagraphRules; }, ignoreRule: function (sRuleId) { this.aIgnoredRules.add(sRuleId); }, resetIgnoreRules: function () { this.aIgnoredRules.clear(); }, reactivateRule: function (sRuleId) { this.aIgnoredRules.delete(sRuleId); }, listRules: function* (sFilter=null) { // generator: returns tuple (sOption, sLineId, sRuleId) try { for (let [sOption, lRuleGroup] of this.getRules(true)) { for (let [,, sLineId, sRuleId,,] of lRuleGroup) { |
︙ | ︙ | |||
130 131 132 133 134 135 136 | } } catch (e) { console.error(e); } }, | < < < < < < < < < < < < < < < < < < < < < < < < | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | } } catch (e) { console.error(e); } }, //// Parsing parse: function (sText, sCountry="${country_default}", bDebug=false, dOptions=null, bContext=false, bFullInfo=false) { // init point to analyse <sText> and returns an iterable of errors or (with option <bFullInfo>) a list of sentences with tokens and errors let oText = new TextParser(sText); return oText.parse(sCountry, bDebug, dOptions, bContext, bFullInfo); } |
︙ | ︙ | |||
199 200 201 202 203 204 205 | s += "\n"; } return s; } parse (sCountry="${country_default}", bDebug=false, dOptions=null, bContext=false, bFullInfo=false) { // analyses <sText> and returns an iterable of errors or (with option <bFullInfo>) a list of sentences with tokens and errors | | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | s += "\n"; } return s; } parse (sCountry="${country_default}", bDebug=false, dOptions=null, bContext=false, bFullInfo=false) { // analyses <sText> and returns an iterable of errors or (with option <bFullInfo>) a list of sentences with tokens and errors let dOpt = dOptions || gc_options.dOptions; let bShowRuleId = gc_options.dOptions.gl_get('idrule', false); // parse paragraph try { this.parseText(this.sText, this.sText0, true, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext); } catch (e) { console.error(e); } |
︙ | ︙ | |||
222 223 224 225 226 227 228 | let lSentences = []; let oSentence = null; for (let [iStart, iEnd] of text.getSentenceBoundaries(sText)) { try { this.sSentence = sText.slice(iStart, iEnd); this.sSentence0 = this.sText0.slice(iStart, iEnd); this.nOffsetWithinParagraph = iStart; | | | | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | let lSentences = []; let oSentence = null; for (let [iStart, iEnd] of text.getSentenceBoundaries(sText)) { try { this.sSentence = sText.slice(iStart, iEnd); this.sSentence0 = this.sText0.slice(iStart, iEnd); this.nOffsetWithinParagraph = iStart; this.lToken = Array.from(gc_engine.oTokenizer.genTokens(this.sSentence, true)); this.dTokenPos.clear(); for (let dToken of this.lToken) { if (dToken["sType"] != "INFO") { this.dTokenPos.set(dToken["nStart"], dToken); } } if (bFullInfo) { oSentence = { "nStart": iStart, "nEnd": iEnd, "sSentence": this.sSentence, "lToken": Array.from(this.lToken) }; for (let oToken of oSentence["lToken"]) { if (oToken["sType"] == "WORD") { oToken["bValidToken"] = gc_engine.oSpellChecker.isValidToken(oToken["sValue"]); } } // the list of tokens is duplicated, to keep all tokens from being deleted when analysis } this.parseText(this.sSentence, this.sSentence0, false, iStart, sCountry, dOpt, bShowRuleId, bDebug, bContext); if (bFullInfo) { oSentence["lGrammarErrors"] = Array.from(this.dSentenceError.values()); |
︙ | ︙ | |||
298 299 300 301 302 303 304 | if (bDebug) { console.log(">>>> GRAPH: " + sGraphName + " " + sLineId); } sText = this.parseGraph(gc_rules_graph.dAllGraph[sGraphName], sCountry, dOptions, bShowRuleId, bDebug, bContext); } } } | | | | | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | if (bDebug) { console.log(">>>> GRAPH: " + sGraphName + " " + sLineId); } sText = this.parseGraph(gc_rules_graph.dAllGraph[sGraphName], sCountry, dOptions, bShowRuleId, bDebug, bContext); } } } else if (!sOption || gc_options.dOptions.gl_get(sOption, false)) { for (let [zRegex, bUppercase, sLineId, sRuleId, nPriority, lActions, lGroups, lNegLookBefore] of lRuleGroup) { if (!gc_engine.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 || gc_engine_func[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)) { |
︙ | ︙ | |||
331 332 333 334 335 336 337 | if (bDebug) { console.log("~ " + sText + " -- " + m[eAct[0]] + " # " + sLineId); } break; case "=": // disambiguation //console.log("-> disambiguation by " + sLineId + "\nzRegex: " + zRegex.source); | | | 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | if (bDebug) { console.log("~ " + sText + " -- " + m[eAct[0]] + " # " + sLineId); } break; case "=": // disambiguation //console.log("-> disambiguation by " + sLineId + "\nzRegex: " + zRegex.source); gc_engine_func[sWhat](sText, m, this.dTokenPos); if (bDebug) { console.log("= " + m[0] + " # " + sLineId, "\nDA:", this.dTokenPos); } break; case ">": // we do nothing, this test is just a condition to apply all following actions break; |
︙ | ︙ | |||
371 372 373 374 375 376 377 | } } } update (sSentence, bDebug=false) { // update <sSentence> and retokenize this.sSentence = sSentence; | | | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | } } } update (sSentence, bDebug=false) { // update <sSentence> and retokenize this.sSentence = sSentence; let lNewToken = Array.from(gc_engine.oTokenizer.genTokens(sSentence, true)); for (let oToken of lNewToken) { if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("lMorph")) { oToken["lMorph"] = this.dTokenPos.get(oToken["nStart"])["lMorph"]; } if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("aTags")) { oToken["aTags"] = this.dTokenPos.get(oToken["nStart"])["aTags"]; } |
︙ | ︙ | |||
469 470 471 472 473 474 475 | } } } // analysable tokens if (oToken["sType"].slice(0,4) == "WORD") { // token lemmas if (oNode.hasOwnProperty("<lemmas>")) { | | | | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | } } } // analysable tokens if (oToken["sType"].slice(0,4) == "WORD") { // token lemmas if (oNode.hasOwnProperty("<lemmas>")) { for (let sLemma of gc_engine.oSpellChecker.getLemma(oToken["sValue"])) { if (oNode["<lemmas>"].hasOwnProperty(sLemma)) { if (bDebug) { console.log(" MATCH: >" + sLemma); } yield { "iToken1": iToken1, "iNode": oNode["<lemmas>"][sLemma] }; bTokenFound = true; } } } // morph arcs if (oNode.hasOwnProperty("<morph>")) { let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]); if (lMorph.length > 0) { for (let sSearch in oNode["<morph>"]) { if (!sSearch.includes("¬")) { // no anti-pattern if (lMorph.some(sMorph => (sMorph.includes(sSearch)))) { if (bDebug) { console.log(" MATCH: $" + sSearch); |
︙ | ︙ | |||
525 526 527 528 529 530 531 | } } } } } // regex morph arcs if (oNode.hasOwnProperty("<re_morph>")) { | | | 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | } } } } } // regex morph arcs if (oNode.hasOwnProperty("<re_morph>")) { let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]); if (lMorph.length > 0) { for (let sRegex in oNode["<re_morph>"]) { if (!sRegex.includes("¬")) { // no anti-pattern if (lMorph.some(sMorph => (sMorph.search(sRegex) !== -1))) { if (bDebug) { console.log(" MATCH: @" + sRegex); |
︙ | ︙ | |||
674 675 676 677 678 679 680 | // Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, sURL ] // TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] // Disambiguator [ option, condition, "=", replacement/suggestion/action ] // Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] // Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] // Test [ option, condition, ">", "" ] if (!sOption || dOptions.gl_get(sOption, false)) { | | | 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | // Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, sURL ] // TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] // Disambiguator [ option, condition, "=", replacement/suggestion/action ] // Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] // Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] // Test [ option, condition, ">", "" ] if (!sOption || dOptions.gl_get(sOption, false)) { bCondMemo = !sFuncCond || gc_engine_func[sFuncCond](this.lToken, nTokenOffset, nLastToken, sCountry, bCondMemo, this.dTags, this.sSentence, this.sSentence0); if (bCondMemo) { if (cActionType == "-") { // grammar error let [iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, sURL] = eAct; let nTokenErrorStart = (iTokenStart > 0) ? nTokenOffset + iTokenStart : nLastToken + iTokenStart; if (!this.lToken[nTokenErrorStart].hasOwnProperty("bImmune")) { let nTokenErrorEnd = (iTokenEnd > 0) ? nTokenOffset + iTokenEnd : nLastToken + iTokenEnd; |
︙ | ︙ | |||
706 707 708 709 710 711 712 | bChange = true; if (bDebug) { console.log(` TEXT_PROCESSOR: [${this.lToken[nTokenStart]["sValue"]}:${this.lToken[nTokenEnd]["sValue"]}] > ${sWhat}`); } } else if (cActionType == "=") { // disambiguation | | | 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | bChange = true; if (bDebug) { console.log(` TEXT_PROCESSOR: [${this.lToken[nTokenStart]["sValue"]}:${this.lToken[nTokenEnd]["sValue"]}] > ${sWhat}`); } } else if (cActionType == "=") { // disambiguation gc_engine_func[sWhat](this.lToken, nTokenOffset, nLastToken); if (bDebug) { console.log(` DISAMBIGUATOR: (${sWhat}) [${this.lToken[nTokenOffset+1]["sValue"]}:${this.lToken[nLastToken]["sValue"]}]`); } } else if (cActionType == ">") { // we do nothing, this test is just a condition to apply all following actions if (bDebug) { |
︙ | ︙ | |||
786 787 788 789 790 791 792 | _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("=")) { | | | | | | | 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | _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 = gc_engine_func[sSugg.slice(1)](sText, m); lSugg = (sSugg) ? sSugg.split("|") : []; } else if (sSugg == "_") { lSugg = []; } else { lSugg = sSugg.gl_expand(m).split("|"); } if (bUppercase && lSugg.length > 0 && m[iGroup].slice(0,1).gl_isUpperCase()) { lSugg = capitalizeArray(lSugg); } // Message let sMessage = (sMsg.startsWith("=")) ? gc_engine_func[sMsg.slice(1)](sText, m) : sMsg.gl_expand(m); if (bShowRuleId) { sMessage += " #" + sLineId + " / " + sRuleId; } // return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext); } _createErrorFromTokens (sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext) { // suggestions let lSugg = []; if (sSugg.startsWith("=")) { sSugg = gc_engine_func[sSugg.slice(1)](this.lToken, nTokenOffset, nLastToken); lSugg = (sSugg) ? sSugg.split("|") : []; } else if (sSugg == "_") { lSugg = []; } else { lSugg = this._expand(sSugg, nTokenOffset, nLastToken).split("|"); } if (bCaseSvty && lSugg.length > 0 && this.lToken[iFirstToken]["sValue"].slice(0,1).gl_isUpperCase()) { lSugg = capitalizeArray(lSugg); } // Message let sMessage = (sMsg.startsWith("=")) ? gc_engine_func[sMsg.slice(1)](this.lToken, nTokenOffset, nLastToken) : this._expand(sMsg, nTokenOffset, nLastToken); if (bShowRuleId) { 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", "aColor": gc_engine.oOptionsColors[sOption], "sMessage": sMessage, "aSuggestions": lSugg, "URL": sURL } if (bContext) { oErr['sUnderlined'] = this.sText0.slice(nStart, nEnd); oErr['sBefore'] = this.sText0.slice(Math.max(0,nStart-80), nStart); |
︙ | ︙ | |||
874 875 876 877 878 879 880 | else if (sRepl === "_") { sNew = "_".repeat(ln); } else if (sRepl === "@") { sNew = "@".repeat(ln); } else if (sRepl.slice(0,1) === "=") { | | | 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 | else if (sRepl === "_") { sNew = "_".repeat(ln); } else if (sRepl === "@") { sNew = "@".repeat(ln); } else if (sRepl.slice(0,1) === "=") { sNew = gc_engine_func[sRepl.slice(1)](sText, m); sNew = sNew + " ".repeat(ln-sNew.length); if (bUppercase && m[iGroup].slice(0,1).gl_isUpperCase()) { sNew = sNew.gl_toCapitalize(); } } else { sNew = sRepl.gl_expand(m); sNew = sNew + " ".repeat(ln-sNew.length); |
︙ | ︙ | |||
915 916 917 918 919 920 921 | for (let i = nTokenRewriteStart; i <= nTokenRewriteEnd; i++) { this.lToken[i]["sNewValue"] = "_"; } } } else { if (sWhat.startsWith("=")) { | | | 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | for (let i = nTokenRewriteStart; i <= nTokenRewriteEnd; i++) { this.lToken[i]["sNewValue"] = "_"; } } } else { if (sWhat.startsWith("=")) { sWhat = gc_engine_func[sWhat.slice(1)](this.lToken, nTokenOffset, nLastToken); } else { sWhat = this._expand(sWhat, nTokenOffset, nLastToken); } let bUppercase = bCaseSvty && this.lToken[nTokenRewriteStart]["sValue"].slice(0,1).gl_isUpperCase(); if (nTokenRewriteEnd - nTokenRewriteStart == 0) { // one token if (bUppercase) { |
︙ | ︙ | |||
1023 1024 1025 1026 1027 1028 1029 | console.log(" TEXT REWRITED: " + this.sSentence); } this.lToken.length = 0; this.lToken = lNewToken; } }; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > < < < < < < | 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | console.log(" TEXT REWRITED: " + this.sSentence); } this.lToken.length = 0; this.lToken = lNewToken; } }; if (typeof(exports) !== 'undefined') { exports.lang = gc_engine.lang; exports.locales = gc_engine.locales; exports.pkg = gc_engine.pkg; exports.name = gc_engine.name; exports.version = gc_engine.version; exports.author = gc_engine.author; // objects exports.oSpellChecker = gc_engine.oSpellChecker; exports.oTokenizer = gc_engine.oTokenizer; exports.aIgnoredRules = gc_engine.aIgnoredRules; exports.oOptionsColors = gc_engine.oOptionsColors; // init exports.load = gc_engine.load; exports.parse = gc_engine.parse; exports.getSpellChecker = gc_engine.getSpellChecker; // rules exports.ignoreRule = gc_engine.ignoreRule; exports.resetIgnoreRules = gc_engine.resetIgnoreRules; exports.reactivateRule = gc_engine.reactivateRule; exports.listRules = gc_engine.listRules; exports.getRules = gc_engine.getRules; // other exports.TextParser = TextParser; } |
Added gc_core/js/lang_core/gc_engine_func.js version [0448168ecb].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | // JavaScript // Grammar checker engine functions ${string} ${regex} ${map} if (typeof(process) !== 'undefined') { var gc_options = require("./gc_options.js"); } else if (typeof(require) !== 'undefined') { var gc_options = require("resource://grammalecte/${lang}/gc_options.js"); } let _sAppContext = "JavaScript"; // what software is running let _oSpellChecker = null; //////// Common functions function option (sOpt) { // return true if option sOpt is active return gc_options.dOptions.gl_get(sOpt, false); } function echo (x) { console.log(x); return true; } var re = { search: function (sRegex, sText) { if (sRegex.startsWith("(?i)")) { return sText.search(new RegExp(sRegex.slice(4), "i")) !== -1; } else { return sText.search(sRegex) !== -1; } }, createRegExp: function (sRegex) { if (sRegex.startsWith("(?i)")) { return new RegExp(sRegex.slice(4), "i"); } else { return new RegExp(sRegex); } } } //////// functions to get text outside pattern scope // warning: check compile_rules.py to understand how it works function nextword (s, iStart, n) { // get the nth word of the input string or empty string let z = new RegExp("^(?: +[a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ%_-]+){" + (n-1).toString() + "} +([a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ%_-]+)", "ig"); let m = z.exec(s.slice(iStart)); if (!m) { return null; } return [iStart + z.lastIndex - m[1].length, m[1]]; } function prevword (s, iEnd, n) { // get the (-)nth word of the input string or empty string let z = new RegExp("([a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ%_-]+) +(?:[a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ%_-]+ +){" + (n-1).toString() + "}$", "i"); let m = z.exec(s.slice(0, iEnd)); if (!m) { return null; } return [m.index, m[1]]; } function nextword1 (s, iStart) { // get next word (optimization) let _zNextWord = new RegExp ("^ +([a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ_][a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ_-]*)", "ig"); let m = _zNextWord.exec(s.slice(iStart)); if (!m) { return null; } return [iStart + _zNextWord.lastIndex - m[1].length, m[1]]; } const _zPrevWord = new RegExp ("([a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ_][a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯff-stᴀ-ᶿ_-]*) +$", "i"); function prevword1 (s, iEnd) { // get previous word (optimization) let m = _zPrevWord.exec(s.slice(0, iEnd)); if (!m) { return null; } return [m.index, m[1]]; } function look (s, sPattern, sNegPattern=null) { // seek sPattern in s (before/after/fulltext), if antipattern sNegPattern not in s try { if (sNegPattern && re.search(sNegPattern, s)) { return false; } return re.search(sPattern, s); } catch (e) { console.error(e); } return false; } //////// Analyse groups for regex rules function displayInfo (dTokenPos, aWord) { // for debugging: info of word if (!aWord) { console.log("> nothing to find"); return true; } let lMorph = _oSpellChecker.getMorph(aWord[1]); if (lMorph.length === 0) { console.log("> not in dictionary"); return true; } if (dTokenPos.has(aWord[0])) { console.log("DA: " + dTokenPos.get(aWord[0])); } console.log("FSA: " + lMorph); return true; } function morph (dTokenPos, aWord, sPattern, sNegPattern, bNoWord=false) { // analyse a tuple (position, word), returns true if not sNegPattern in word morphologies and sPattern in word morphologies (disambiguation on) if (!aWord) { return bNoWord; } let lMorph = (dTokenPos.has(aWord[0]) && dTokenPos.get(aWord[0]))["lMorph"] ? dTokenPos.get(aWord[0])["lMorph"] : _oSpellChecker.getMorph(aWord[1]); if (lMorph.length === 0) { return false; } if (sNegPattern) { // check negative condition if (sNegPattern === "*") { // all morph must match sPattern return lMorph.every(sMorph => (sMorph.search(sPattern) !== -1)); } else { if (lMorph.some(sMorph => (sMorph.search(sNegPattern) !== -1))) { return false; } } } // search sPattern return lMorph.some(sMorph => (sMorph.search(sPattern) !== -1)); } function analyse (sWord, sPattern, sNegPattern) { // analyse a word, returns True if not sNegPattern in word morphologies and sPattern in word morphologies (disambiguation off) let lMorph = _oSpellChecker.getMorph(sWord); if (lMorph.length === 0) { return false; } if (sNegPattern) { // check negative condition if (sNegPattern === "*") { // all morph must match sPattern return lMorph.every(sMorph => (sMorph.search(sPattern) !== -1)); } else { if (lMorph.some(sMorph => (sMorph.search(sNegPattern) !== -1))) { return false; } } } // search sPattern return lMorph.some(sMorph => (sMorph.search(sPattern) !== -1)); } //// Analyse tokens for graph rules function g_value (oToken, sValues, nLeft=null, nRight=null) { // test if <oToken['sValue']> is in sValues (each value should be separated with |) let sValue = (nLeft === null) ? "|"+oToken["sValue"]+"|" : "|"+oToken["sValue"].slice(nLeft, nRight)+"|"; if (sValues.includes(sValue)) { return true; } if (oToken["sValue"].slice(0,2).gl_isTitle()) { // we test only 2 first chars, to make valid words such as "Laissez-les", "Passe-partout". if (sValues.includes(sValue.toLowerCase())) { return true; } } else if (oToken["sValue"].gl_isUpperCase()) { //if sValue.lower() in sValues: // return true; sValue = "|"+sValue.slice(1).gl_toCapitalize(); if (sValues.includes(sValue)) { return true; } sValue = sValue.toLowerCase(); if (sValues.includes(sValue)) { return true; } } return false; } function g_morph (oToken, sPattern, sNegPattern="", nLeft=null, nRight=null, bMemorizeMorph=true) { // analyse a token, return True if <sNegPattern> not in morphologies and <sPattern> in morphologies let lMorph; if (oToken.hasOwnProperty("lMorph")) { lMorph = oToken["lMorph"]; } else { if (nLeft !== null) { let sValue = (nRight !== null) ? oToken["sValue"].slice(nLeft, nRight) : oToken["sValue"].slice(nLeft); lMorph = _oSpellChecker.getMorph(sValue); if (bMemorizeMorph) { oToken["lMorph"] = lMorph; } } else { lMorph = _oSpellChecker.getMorph(oToken["sValue"]); } } if (lMorph.length == 0) { return false; } // check negative condition if (sNegPattern) { if (sNegPattern == "*") { // all morph must match sPattern return lMorph.every(sMorph => (sMorph.search(sPattern) !== -1)); } else { if (lMorph.some(sMorph => (sMorph.search(sNegPattern) !== -1))) { return false; } } } // search sPattern return lMorph.some(sMorph => (sMorph.search(sPattern) !== -1)); } function g_analyse (oToken, sPattern, sNegPattern="", nLeft=null, nRight=null, bMemorizeMorph=true) { // analyse a token, return True if <sNegPattern> not in morphologies and <sPattern> in morphologies let lMorph; if (nLeft !== null) { let sValue = (nRight !== null) ? oToken["sValue"].slice(nLeft, nRight) : oToken["sValue"].slice(nLeft); lMorph = _oSpellChecker.getMorph(sValue); if (bMemorizeMorph) { oToken["lMorph"] = lMorph; } } else { lMorph = _oSpellChecker.getMorph(oToken["sValue"]); } if (lMorph.length == 0) { return false; } // check negative condition if (sNegPattern) { if (sNegPattern == "*") { // all morph must match sPattern return lMorph.every(sMorph => (sMorph.search(sPattern) !== -1)); } else { if (lMorph.some(sMorph => (sMorph.search(sNegPattern) !== -1))) { return false; } } } // search sPattern return lMorph.some(sMorph => (sMorph.search(sPattern) !== -1)); } function g_merged_analyse (oToken1, oToken2, cMerger, sPattern, sNegPattern="", bSetMorph=true) { // merge two token values, return True if <sNegPattern> not in morphologies and <sPattern> in morphologies (disambiguation off) let lMorph = _oSpellChecker.getMorph(oToken1["sValue"] + cMerger + oToken2["sValue"]); if (lMorph.length == 0) { return false; } // check negative condition if (sNegPattern) { if (sNegPattern == "*") { // all morph must match sPattern let bResult = lMorph.every(sMorph => (sMorph.search(sPattern) !== -1)); if (bResult && bSetMorph) { oToken1["lMorph"] = lMorph; } return bResult; } else { if (lMorph.some(sMorph => (sMorph.search(sNegPattern) !== -1))) { return false; } } } // search sPattern let bResult = lMorph.some(sMorph => (sMorph.search(sPattern) !== -1)); if (bResult && bSetMorph) { oToken1["lMorph"] = lMorph; } return bResult; } function g_tag_before (oToken, dTags, sTag) { if (!dTags.has(sTag)) { return false; } if (oToken["i"] > dTags.get(sTag)[0]) { return true; } return false; } function g_tag_after (oToken, dTags, sTag) { if (!dTags.has(sTag)) { return false; } if (oToken["i"] < dTags.get(sTag)[1]) { return true; } return false; } function g_tag (oToken, sTag) { return oToken.hasOwnProperty("aTags") && oToken["aTags"].has(sTag); } function g_space_between_tokens (oToken1, oToken2, nMin, nMax=null) { let nSpace = oToken2["nStart"] - oToken1["nEnd"] if (nSpace < nMin) { return false; } if (nMax !== null && nSpace > nMax) { return false; } return true; } function g_token (lToken, i) { if (i < 0) { return lToken[0]; } if (i >= lToken.length) { return lToken[-1]; } return lToken[i]; } //////// Disambiguator function select (dTokenPos, nPos, sWord, sPattern, lDefault=null) { if (!sWord) { return true; } if (!dTokenPos.has(nPos)) { console.log("Error. There should be a token at this position: ", nPos); return true; } let lMorph = _oSpellChecker.getMorph(sWord); if (lMorph.length === 0 || lMorph.length === 1) { return true; } let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 ); if (lSelect.length > 0) { if (lSelect.length != lMorph.length) { dTokenPos.get(nPos)["lMorph"] = lSelect; } } else if (lDefault) { dTokenPos.get(nPos)["lMorph"] = lDefault; } return true; } function exclude (dTokenPos, nPos, sWord, sPattern, lDefault=null) { if (!sWord) { return true; } if (!dTokenPos.has(nPos)) { console.log("Error. There should be a token at this position: ", nPos); return true; } let lMorph = _oSpellChecker.getMorph(sWord); if (lMorph.length === 0 || lMorph.length === 1) { return true; } let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 ); if (lSelect.length > 0) { if (lSelect.length != lMorph.length) { dTokenPos.get(nPos)["lMorph"] = lSelect; } } else if (lDefault) { dTokenPos.get(nPos)["lMorph"] = lDefault; } return true; } function define (dTokenPos, nPos, lMorph) { dTokenPos.get(nPos)["lMorph"] = lMorph; return true; } //// Disambiguation for graph rules function g_select (oToken, sPattern, lDefault=null) { // select morphologies for <oToken> according to <sPattern>, always return true let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : _oSpellChecker.getMorph(oToken["sValue"]); if (lMorph.length === 0 || lMorph.length === 1) { if (lDefault) { oToken["lMorph"] = lDefault; } return true; } let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 ); if (lSelect.length > 0) { if (lSelect.length != lMorph.length) { oToken["lMorph"] = lSelect; } } else if (lDefault) { oToken["lMorph"] = lDefault; } return true; } function g_exclude (oToken, sPattern, lDefault=null) { // select morphologies for <oToken> according to <sPattern>, always return true let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : _oSpellChecker.getMorph(oToken["sValue"]); if (lMorph.length === 0 || lMorph.length === 1) { if (lDefault) { oToken["lMorph"] = lDefault; } return true; } let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 ); if (lSelect.length > 0) { if (lSelect.length != lMorph.length) { oToken["lMorph"] = lSelect; } } else if (lDefault) { oToken["lMorph"] = lDefault; } return true; } function g_add_morph (oToken, lNewMorph) { "Disambiguation: add a morphology to a token" let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : _oSpellChecker.getMorph(oToken["sValue"]); lMorph.push(...lNewMorph); oToken["lMorph"] = lMorph; return true; } function g_define (oToken, lMorph) { // set morphologies of <oToken>, always return true oToken["lMorph"] = lMorph; return true; } function g_define_from (oToken, nLeft=null, nRight=null) { let sValue = oToken["sValue"]; if (nLeft !== null) { sValue = (nRight !== null) ? sValue.slice(nLeft, nRight) : sValue.slice(nLeft); } oToken["lMorph"] = _oSpellChecker.getMorph(sValue); return true; } function g_change_meta (oToken, sType) { // Disambiguation: change type of token oToken["sType"] = sType; return true; } //////// GRAMMAR CHECKER PLUGINS ${pluginsJS} // generated code, do not edit var gc_engine_func = { load: function (sContext, oSpellChecker) { _sAppContext = sContext _oSpellChecker = oSpellChecker }, // callables for regex rules ${callablesJS} // callables for graph rules ${graph_callablesJS} } if (typeof(exports) !== 'undefined') { exports.load = gc_engine_func.load; } |
Modified gc_core/js/lang_core/gc_options.js from [ece26d7264] to [6f3ff68ba6].
1 2 3 4 5 6 7 8 9 10 | // Options for Grammalecte /* jshint esversion:6 */ /* jslint esversion:6 */ /* global exports */ ${map} var gc_options = { | > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > | > > > > > > > | | | | | | | | | | | | > > > > > > > | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | // Options for Grammalecte /* jshint esversion:6 */ /* jslint esversion:6 */ /* global exports */ ${map} var gc_options = { dOptions: new Map(), sAppContext: "JavaScript", load: function (sContext="JavaScript") { this.sAppContext = sContext; this.dOptions = this.getDefaultOptions(sContext); }, setOption: function (sOpt, bVal) { if (this.dOptions.has(sOpt)) { this.dOptions.set(sOpt, bVal); } }, setOptions: function (dOpt) { this.dOptions.gl_updateOnlyExistingKeys(dOpt); }, getOptions: function () { return this.dOptions.gl_shallowCopy(); }, resetOptions: function () { this.dOptions = this.getDefaultOptions(this._sAppContext); }, getDefaultOptions: function (sContext="") { if (!sContext) { sContext = this.sAppContext; } if (this.oDefaultOpt.hasOwnProperty(sContext)) { return this.oDefaultOpt[sContext].gl_shallowCopy(); } return this.oDefaultOpt["JavaScript"].gl_shallowCopy(); }, getOptionLabels: function (sLang="${sLang}") { if (this.oOptLabel.hasOwnProperty(sLang)) { return this.oOptLabel[sLang]; } return this.oOptLabel["{$sLang}"]; }, getOptionsColors: function (sTheme="Default", sColorType="aRGB") { let oOptColor = (this.oOptColor.hasOwnProperty(sTheme)) ? this.oOptColor[sTheme] : this.oOptColor["Default"]; let oColorType = (this.oColorType.hasOwnProperty(sColorType)) ? this.oColorType[sColorType] : this.oColorType["aRGB"]; let oColor = {}; try { for (let [sOpt, sColor] of Object.entries(oOptColor)) { oColor[sOpt] = oColorType[sColor]; } return oColor; } catch (e) { console.error(e); return {}; } }, lStructOpt: ${lStructOpt}, oDefaultOpt: { "JavaScript": new Map (${dOptJavaScript}), "Firefox": new Map (${dOptFirefox}), "Thunderbird": new Map (${dOptThunderbird}), }, oColorType: ${dColorType}, oOptColor: ${dOptColor}, oOptLabel: ${dOptLabel} }; if (typeof(exports) !== 'undefined') { exports.dOptions = gc_options.dOptions; exports.sAppContext = gc_options.sAppContext; exports.load = gc_options.load; exports.setOption = gc_options.setOption; exports.setOptions = gc_options.setOptions; exports.resetOptions = gc_options.resetOptions; exports.getDefaultOptions = gc_options.getDefaultOptions; exports.getOptions = gc_options.getOptions; exports.getOptionsColors = gc_options.getOptionsColors; exports.lStructOpt = gc_options.lStructOpt; exports.oDefaultOpt = gc_options.oDefaultOpt; exports.dColorType = gc_options.dColorType; exports.oOptColor = gc_options.oOptColor; exports.oOptLabel = gc_options.oOptLabel; } |
Modified gc_lang/fr/webext/gce_worker.js from [67fa9791af] to [129eee4726].
︙ | ︙ | |||
43 44 45 46 47 48 49 50 51 52 53 54 55 56 | importScripts("grammalecte/fr/conj.js"); importScripts("grammalecte/fr/mfsp.js"); 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.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. | > | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | importScripts("grammalecte/fr/conj.js"); importScripts("grammalecte/fr/mfsp.js"); 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. |
︙ | ︙ | |||
182 183 184 185 186 187 188 | 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); } | | | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | 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_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)); } } |
︙ | ︙ |