Grammalecte  Check-in [9fd78a9ee5]

Overview
Comment:[tb][js] update gce_worker
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tb | gcerw
Files: files | file ages | folders
SHA3-256: 9fd78a9ee541acc671ae8624285be0ff65d357b4ec5f68a5cc7c63e9cc6d76af
User & Date: olr on 2020-04-06 20:43:04
Other Links: branch diff | manifest | tags
Context
2020-04-08
14:07
merge trunk check-in: 5c14b1c9e0 user: olr tags: gcerw
2020-04-06
20:43
[tb][js] update gce_worker check-in: 9fd78a9ee5 user: olr tags: gcerw, tb
20:01
[core][js] gc engine: code rewriting check-in: 42fa8f123a user: olr tags: core, gcerw
Changes

Modified gc_lang/fr/mailext/worker/gce_worker.js from [abd0c9c4ba] to [420e3521e3].

    41     41   
    42     42   // end of copy/paste
    43     43   
    44     44   
    45     45   // no console here, use “dump”
    46     46   
    47     47   let gce = null; // module: grammar checker engine
           48  +let gco = null;
    48     49   let text = null;
    49     50   let tkz = null; // module: tokenizer
    50     51   let lxg = null; // module: lexicographer
    51     52   let helpers = null;
    52     53   
    53     54   let oTokenizer = null;
    54     55   let oSpellChecker = null;
    55     56   let oLxg = null;
    56     57   
    57     58   function loadGrammarChecker (sGCOptions="", sContext="JavaScript") {
    58     59       if (gce === null) {
    59     60           try {
           61  +            gco = require("resource://grammalecte/fr/gc_options.js");
    60     62               gce = require("resource://grammalecte/fr/gc_engine.js");
    61     63               helpers = require("resource://grammalecte/graphspell/helpers.js");
    62     64               text = require("resource://grammalecte/text.js");
    63     65               tkz = require("resource://grammalecte/graphspell/tokenizer.js");
    64     66               //lxg = require("resource://grammalecte/fr/lexicographe.js");
    65     67               oTokenizer = new tkz.Tokenizer("fr");
    66     68               gce.load(sContext, "sCSS");
    67     69               oSpellChecker = gce.getSpellChecker();
    68     70               if (sGCOptions !== "") {
    69         -                gce.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
           71  +                gco.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    70     72               }
    71     73               // we always retrieve options from the gce, for setOptions filters obsolete options
    72         -            return gce.getOptions().gl_toString();
           74  +            return gco.getOptions().gl_toString();
    73     75           }
    74     76           catch (e) {
    75     77               console.log("# Error: " + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
    76     78           }
    77     79       }
    78     80   }
    79     81   
................................................................................
   115    117       for (let aSugg of oSpellChecker.suggest(sWord, nSuggLimit)) {
   116    118           lSugg.push(...aSugg);
   117    119       }
   118    120       return lSugg.join("|");
   119    121   }
   120    122   
   121    123   function getOptions () {
   122         -    return gce.getOptions().gl_toString();
          124  +    return gco.getOptions().gl_toString();
   123    125   }
   124    126   
   125    127   function getDefaultOptions () {
   126         -    return gce.getDefaultOptions().gl_toString();
          128  +    return gco.getDefaultOptions().gl_toString();
   127    129   }
   128    130   
   129    131   function setOptions (sGCOptions) {
   130         -    gce.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
   131         -    return gce.getOptions().gl_toString();
          132  +    gco.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
          133  +    return gco.getOptions().gl_toString();
   132    134   }
   133    135   
   134    136   function setOption (sOptName, bValue) {
   135         -    gce.setOptions(new Map([ [sOptName, bValue] ]));
   136         -    return gce.getOptions().gl_toString();
          137  +    gco.setOptions(new Map([ [sOptName, bValue] ]));
          138  +    return gco.getOptions().gl_toString();
   137    139   }
   138    140   
   139    141   function resetOptions () {
   140         -    gce.resetOptions();
   141         -    return gce.getOptions().gl_toString();
          142  +    gco.resetOptions();
          143  +    return gco.getOptions().gl_toString();
   142    144   }
   143    145   
   144    146   function fullTests (sGCOptions="") {
   145         -    if (!gce || !oSpellChecker) {
          147  +    if (!gce || !oSpellChecker || !gco) {
   146    148           return "# Error: grammar checker or dictionary not loaded."
   147    149       }
   148         -    let dMemoOptions = gce.getOptions();
          150  +    let dMemoOptions = gco.getOptions();
   149    151       if (sGCOptions) {
   150         -        gce.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
          152  +        gco.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
   151    153       }
   152    154       let tests = require("resource://grammalecte/tests.js");
   153    155       let oTest = new tests.TestGrammarChecking(gce);
   154    156       let sAllRes = "";
   155    157       for (let sRes of oTest.testParse()) {
   156    158           console.log(sRes+"\n");
   157    159           sAllRes += sRes+"\n";
   158    160       }
   159         -    gce.setOptions(dMemoOptions);
          161  +    gco.setOptions(dMemoOptions);
   160    162       return sAllRes;
   161    163   }