Grammalecte  Check-in [af2ff73c99]

Overview
Comment:[core][fx] fix calls to gc_options
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | fx | gcerw
Files: files | file ages | folders
SHA3-256: af2ff73c994e8f398b50f1e492b8a6890080ad920b5809d3aba4865a49712b37
User & Date: olr on 2020-04-17 19:02:30
Other Links: branch diff | manifest | tags
Context
2020-04-17
19:10
[graphspell][js] ad hoc suggestions as private dictionary -> access via the module object check-in: dfc20f24e1 user: olr tags: gcerw, graphspell
19:02
[core][fx] fix calls to gc_options check-in: af2ff73c99 user: olr tags: core, fx, gcerw
18:37
merge trunk (empty): conflict solved before check-in: f69a4ea6d7 user: olr tags: gcerw
Changes

Modified gc_core/js/tests.js from [147f1c4e7b] to [6174473e22].

    12     12   } else if (typeof(require) !== 'undefined') {
    13     13       var helpers = require("resource://grammalecte/graphspell/helpers.js");
    14     14   }
    15     15   
    16     16   
    17     17   class TestGrammarChecking {
    18     18   
    19         -    constructor (gce, spfTests="") {
    20         -        this.gce = gce;
           19  +    constructor (gc_engine, gc_options, spfTests="") {
           20  +        this.gc_engine = gc_engine;
           21  +        this.gc_options = gc_options;
    21     22           this.spfTests = spfTests;
    22     23           this._aRuleTested = new Set();
    23     24       }
    24     25   
    25     26       * testParse (bDebug=false) {
    26     27           const t0 = Date.now();
    27     28           let sURL;
    28     29           if(typeof(process) !== 'undefined') {
    29         -            sURL = (this.spfTests !== "") ? this.spfTests : "./"+this.gce.lang+"/tests_data.json";
           30  +            sURL = (this.spfTests !== "") ? this.spfTests : "./"+this.gc_engine.lang+"/tests_data.json";
    30     31           } else {
    31         -            sURL = (this.spfTests !== "") ? this.spfTests : "resource://grammalecte/"+this.gce.lang+"/tests_data.json";
           32  +            sURL = (this.spfTests !== "") ? this.spfTests : "resource://grammalecte/"+this.gc_engine.lang+"/tests_data.json";
    32     33           }
    33     34           const aData = JSON.parse(helpers.loadFile(sURL)).aData;
    34     35           let nInvalid = 0;
    35     36           let nTotal = 0;
    36     37           let sErrorText;
    37     38           let sSugg;
    38     39           let sExpectedErrors;
................................................................................
    42     43           let sLineNum;
    43     44           let i = 1;
    44     45           let sUntestedRules = "";
    45     46           let bShowUntested = false;
    46     47           let zOption = /^__([a-zA-Z0-9]+)__ /;
    47     48           let sOption;
    48     49           let m;
    49         -        yield "Tests [" + this.gce.lang + "]: " + aData.length.toString();
           50  +        yield "Tests [" + this.gc_engine.lang + "]: " + aData.length.toString();
    50     51           try {
    51     52               for (let sLine of aData) {
    52     53                   sLineNum = sLine.slice(0,10).trim();
    53     54                   sLine = sLine.slice(10).trim();
    54     55                   if (sLine.length > 0 && !sLine.startsWith("#")) {
    55     56                       sOption = false;
    56     57                       m = zOption.exec(sLine);
................................................................................
    88     89           }
    89     90           catch (e) {
    90     91               console.error(e);
    91     92           }
    92     93   
    93     94           if (bShowUntested) {
    94     95               i = 0;
    95         -            for (let [sOpt, sLineId, sRuleId] of this.gce.listRules()) {
           96  +            for (let [sOpt, sLineId, sRuleId] of this.gc_engine.listRules()) {
    96     97                   if (sOpt !== "@@@@" && !this._aRuleTested.has(sLineId) && !/^[0-9]+[sp]$|^[pd]_/.test(sRuleId)) {
    97     98                       sUntestedRules += sLineId + "/" + sRuleId + ", ";
    98     99                       i += 1;
    99    100                   }
   100    101               }
   101    102               if (i > 0) {
   102    103                   yield sUntestedRules + "\n[" + i.toString() + " untested rules]";
................................................................................
   134    135           return " ".repeat(sLine.length);
   135    136       }
   136    137   
   137    138       _getFoundErrors (sLine, bDebug, sOption) {
   138    139           try {
   139    140               let aErrs = [];
   140    141               if (sOption) {
   141         -                this.gce.setOption(sOption, true);
   142         -                aErrs = this.gce.parse(sLine, "FR", bDebug);
   143         -                this.gce.setOption(sOption, false);
          142  +                this.gc_options.setOption(sOption, true);
          143  +                aErrs = this.gc_engine.parse(sLine, "FR", bDebug);
          144  +                this.gc_options.setOption(sOption, false);
   144    145               } else {
   145         -                aErrs = this.gce.parse(sLine, "FR", bDebug);
          146  +                aErrs = this.gc_engine.parse(sLine, "FR", bDebug);
   146    147               }
   147    148               let sRes = " ".repeat(sLine.length);
   148    149               let sListErr = "";
   149    150               for (let dErr of aErrs) {
   150    151                   sRes = sRes.slice(0, dErr["nStart"]) + "~".repeat(dErr["nEnd"] - dErr["nStart"]) + sRes.slice(dErr["nEnd"]);
   151    152                   sListErr += "    * {" + dErr['sLineId'] + " / " + dErr['sRuleId'] + "}  at  " + dErr['nStart'] + ":" + dErr['nEnd'] + "\n";
   152    153                   this._aRuleTested.add(dErr["sLineId"]);

Modified gc_lang/fr/webext/gce_worker.js from [e414bb30c0] to [4717319dce].

    45     45   importScripts("grammalecte/fr/phonet.js");
    46     46   importScripts("grammalecte/fr/cregex.js");
    47     47   importScripts("grammalecte/fr/gc_options.js");
    48     48   importScripts("grammalecte/fr/gc_rules.js");
    49     49   importScripts("grammalecte/fr/gc_rules_graph.js");
    50     50   importScripts("grammalecte/fr/gc_engine_func.js");
    51     51   importScripts("grammalecte/fr/gc_engine.js");
    52         -importScripts("grammalecte/fr/lexicographe.js");
    53     52   importScripts("grammalecte/tests.js");
    54     53   /*
    55     54       Warning.
    56     55       Initialization can’t be completed at startup of the worker,
    57     56       for we need the path of the extension to load data stored in JSON files.
    58     57       This path is retrieved in background.js and passed with the event “init”.
    59     58   */
................................................................................
   174    173               //console.log("[Worker] Loading… Extension path: " + sExtensionPath);
   175    174               conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json"));
   176    175               phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json"));
   177    176               mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json"));
   178    177               //console.log("[Worker] Modules have been initialized…");
   179    178               gc_engine.load(sContext, "aHSL", sExtensionPath+"grammalecte/graphspell/_dictionaries");
   180    179               oSpellChecker = gc_engine.getSpellChecker();
   181         -            oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
          180  +            oTest = new TestGrammarChecking(gc_engine, gc_options, sExtensionPath+"/grammalecte/fr/tests_data.json");
   182    181               oTokenizer = new Tokenizer("fr");
   183    182               oLocution =  helpers.loadFile(sExtensionPath + "/grammalecte/fr/locutions_data.json");
   184    183               lexgraph_fr.load(oSpellChecker, oTokenizer, oLocution);
   185    184               if (dOptions !== null) {
   186    185                   if (!(dOptions instanceof Map)) {
   187    186                       dOptions = helpers.objectToMap(dOptions);
   188    187                   }
................................................................................
   258    257       catch (e) {
   259    258           console.error(e);
   260    259           postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true));
   261    260       }
   262    261   }
   263    262   
   264    263   function getOptions (oInfo={}) {
   265         -    let dOptions = helpers.mapToObject(gc_engine.getOptions());
          264  +    let dOptions = helpers.mapToObject(gc_options.getOptions());
   266    265       postMessage(createResponse("getOptions", dOptions, oInfo, true));
   267    266   }
   268    267   
   269    268   function getDefaultOptions (oInfo={}) {
   270         -    let dOptions = helpers.mapToObject(gc_engine.getDefaultOptions());
          269  +    let dOptions = helpers.mapToObject(gc_options.getDefaultOptions());
   271    270       postMessage(createResponse("getDefaultOptions", dOptions, oInfo, true));
   272    271   }
   273    272   
   274    273   function setOptions (dOptions, oInfo={}) {
   275    274       if (!(dOptions instanceof Map)) {
   276    275           dOptions = helpers.objectToMap(dOptions);
   277    276       }
   278         -    gc_engine.setOptions(dOptions);
   279         -    dOptions = helpers.mapToObject(gc_engine.getOptions());
          277  +    gc_options.setOptions(dOptions);
          278  +    dOptions = helpers.mapToObject(gc_options.getOptions());
   280    279       postMessage(createResponse("setOptions", dOptions, oInfo, true));
   281    280   }
   282    281   
   283    282   function setOption (sOptName, bValue, oInfo={}) {
   284    283       console.log(sOptName+": "+bValue);
   285    284       if (sOptName) {
   286         -        gc_engine.setOption(sOptName, bValue);
   287         -        let dOptions = helpers.mapToObject(gc_engine.getOptions());
          285  +        gc_options.setOption(sOptName, bValue);
          286  +        let dOptions = helpers.mapToObject(gc_options.getOptions());
   288    287           postMessage(createResponse("setOption", dOptions, oInfo, true));
   289    288       }
   290    289   }
   291    290   
   292    291   function resetOptions (oInfo={}) {
   293         -    gc_engine.resetOptions();
   294         -    let dOptions = helpers.mapToObject(gc_engine.getOptions());
          292  +    gc_options.resetOptions();
          293  +    let dOptions = helpers.mapToObject(gc_options.getOptions());
   295    294       postMessage(createResponse("resetOptions", dOptions, oInfo, true));
   296    295   }
   297    296   
   298    297   function tests () {
   299    298       console.log(conj.getConj("devenir", ":E", ":2s"));
   300    299       console.log(mfsp.getMasForm("emmerdeuse", true));
   301    300       console.log(mfsp.getMasForm("pointilleuse", false));
................................................................................
   324    323   }
   325    324   
   326    325   function fullTests (oInfo={}) {
   327    326       if (!gc_engine) {
   328    327           postMessage(createResponse("fullTests", "# Grammar checker not loaded.", oInfo, true));
   329    328           return;
   330    329       }
   331         -    let dMemoOptions = gc_engine.getOptions();
   332         -    let dTestOptions = gc_engine.getDefaultOptions();
          330  +    let dMemoOptions = gc_options.getOptions();
          331  +    let dTestOptions = gc_options.getDefaultOptions();
   333    332       dTestOptions.set("nbsp", true);
   334    333       dTestOptions.set("esp", true);
   335    334       dTestOptions.set("unit", true);
   336    335       dTestOptions.set("num", true);
   337         -    gc_engine.setOptions(dTestOptions);
          336  +    gc_options.setOptions(dTestOptions);
   338    337       let sMsg = "";
   339    338       for (let sRes of oTest.testParse()) {
   340    339           sMsg += sRes + "\n";
   341    340           console.log(sRes);
   342    341       }
   343         -    gc_engine.setOptions(dMemoOptions);
          342  +    gc_options.setOptions(dMemoOptions);
   344    343       postMessage(createResponse("fullTests", sMsg, oInfo, true));
   345    344   }
   346    345   
   347    346   
   348    347   // SpellChecker
   349    348   
   350    349   function setDictionary (sDictionary, oDict, oInfo) {