Grammalecte  Check-in [7f65ce689c]

Overview
Comment:[fx] use personal dictionary + [graphspell][js] spellchecker: fix JS syntax
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | graphspell | multid
Files: files | file ages | folders
SHA3-256: 7f65ce689c94cd0192ca37db300e3377ad9e7f98f7323393a81fc432717f07a3
User & Date: olr on 2018-02-16 14:42:04
Original Comment: [graphspell][js] spellchecker: fix JS syntax
Other Links: branch diff | manifest | tags
Context
2018-02-16
15:40
[grphspell][js] ibdawg: use ... instead of concat check-in: 254e33fe66 user: olr tags: graphspell, multid
14:42
[fx] use personal dictionary + [graphspell][js] spellchecker: fix JS syntax check-in: 7f65ce689c user: olr tags: fx, graphspell, multid
2018-02-13
18:34
[graphspell] add space in comments check-in: 6a6c2f6878 user: olr tags: graphspell, multid
Changes

Modified gc_lang/fr/webext/background.js from [f7965949be] to [1d15c00f44].

    58     58                   }
    59     59                   browser.runtime.sendMessage(e.data);
    60     60                   break;
    61     61               case "setOptions":
    62     62               case "setOption":
    63     63                   storeGCOptions(result);
    64     64                   break;
           65  +            case "setDictionary":
           66  +                console.log("[background] " + sActionDone + ": " + result);
           67  +                break;
    65     68               default:
    66     69                   console.log("[background] Unknown command: " + sActionDone);
    67     70                   console.log(e.data);
    68     71           }
    69     72       }
    70     73       catch (e) {
    71     74           showError(e);
................................................................................
    85     88       let dOptions = (dSavedOptions.hasOwnProperty("gc_options")) ? dSavedOptions.gc_options : null;
    86     89       xGCEWorker.postMessage({
    87     90           sCommand: "init",
    88     91           dParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"},
    89     92           dInfo: {}
    90     93       });
    91     94   }
           95  +
           96  +function setSpellingDictionary (dSavedDictionary) {
           97  +    if (dSavedDictionary.hasOwnProperty("oExtendedDictionary")) {
           98  +        xGCEWorker.postMessage({
           99  +            sCommand: "setDictionary",
          100  +            dParam: { sType: "extended", oDict: dSavedDictionary["oExtendedDictionary"] },
          101  +            dInfo: {}
          102  +        });
          103  +    }
          104  +    else if (dSavedDictionary.hasOwnProperty("oPersonalDictionary")) {
          105  +        xGCEWorker.postMessage({
          106  +            sCommand: "setDictionary",
          107  +            dParam: { sType: "personal", oDict: dSavedDictionary["oPersonalDictionary"] },
          108  +            dInfo: {}
          109  +        });
          110  +    }
          111  +}
    92    112   
    93    113   function init () {
    94    114       if (bChrome) {
    95    115           browser.storage.local.get("gc_options", initGrammarChecker);
    96    116           browser.storage.local.get("ui_options", initUIOptions);
          117  +        browser.storage.local.get("oExtendedDictionary", setSpellingDictionary);
          118  +        browser.storage.local.get("oPersonalDictionary", setSpellingDictionary);
    97    119           return;
    98    120       }
    99    121       browser.storage.local.get("gc_options").then(initGrammarChecker, showError);
   100    122       browser.storage.local.get("ui_options").then(initUIOptions, showError);
          123  +    browser.storage.local.get("oExtendedDictionary").then(setSpellingDictionary, showError);
          124  +    browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionary, showError);
   101    125   }
   102    126   
   103    127   init();
   104    128   
   105    129   
   106    130   browser.runtime.onInstalled.addListener(function (oDetails) {
   107    131       // launched at installation or update
................................................................................
   131    155           case "getOptions":
   132    156           case "getDefaultOptions":
   133    157           case "setOptions":
   134    158           case "setOption":
   135    159           case "resetOptions":
   136    160           case "textToTest":
   137    161           case "fullTests":
          162  +        case "setDictionary":
   138    163               xGCEWorker.postMessage(oRequest);
   139    164               break;
   140    165           case "openURL":
   141    166               browser.tabs.create({url: dParam.sURL});
   142    167               break;
   143    168           default:
   144    169               console.log("[background] Unknown command: " + sCommand);

Modified gc_lang/fr/webext/gce_worker.js from [fb2b2e5711] to [c20f81d8f3].

   117    117               break;
   118    118           case "textToTest":
   119    119               textToTest(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo);
   120    120               break;
   121    121           case "fullTests":
   122    122               fullTests(dInfo);
   123    123               break;
          124  +        case "setDictionary":
          125  +            setDictionary(dParam.sType, dParam.oDict, dInfo);
          126  +            break;
   124    127           case "getSpellSuggestions":
   125    128               getSpellSuggestions(dParam.sWord, dInfo);
   126    129               break;
   127    130           case "getListOfTokens":
   128    131               getListOfTokens(dParam.sText, dInfo);
   129    132               break;
   130    133           default:
................................................................................
   285    288           console.log(sRes);
   286    289       }
   287    290       gc_engine.setOptions(dMemoOptions);
   288    291       postMessage(createResponse("fullTests", sMsg, dInfo, true));
   289    292   }
   290    293   
   291    294   
   292         -// Spellchecker
          295  +// SpellChecker
          296  +
          297  +function setDictionary (sType, oDict, dInfo) {
          298  +    if (!oSpellChecker) {
          299  +        postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true));
          300  +        return;
          301  +    }
          302  +    switch (sType) {
          303  +        case "main":
          304  +            oSpellChecker.setMainDictionary(oDict);
          305  +            postMessage(createResponse("setDictionary", true, dInfo, true));
          306  +            break;
          307  +        case "extended":
          308  +            oSpellChecker.setExtendedDictionary(oDict);
          309  +            postMessage(createResponse("setDictionary", true, dInfo, true));
          310  +            break;
          311  +        case "personal":
          312  +            oSpellChecker.setPersonalDictionary(oDict);
          313  +            postMessage(createResponse("setDictionary", true, dInfo, true));
          314  +            break;
          315  +        default:
          316  +            console.log("[worker] setDictionary: Unknown command");
          317  +    }
          318  +}
   293    319   
   294    320   function getSpellSuggestions (sWord, dInfo) {
   295    321       if (!oSpellChecker) {
   296         -        postMessage(createResponse("getSpellSuggestions", "# Error. Dictionary not loaded.", dInfo, true));
          322  +        postMessage(createResponse("getSpellSuggestions", "# Error. SpellChecker not loaded.", dInfo, true));
   297    323           return;
   298    324       }
   299    325       let i = 1;
   300    326       for (let aSugg of oSpellChecker.suggest(sWord)) {
   301    327           postMessage(createResponse("getSpellSuggestions", {sWord: sWord, aSugg: aSugg, iSugg: i}, dInfo, true));
   302    328           i += 1;
   303    329       }

Modified gc_lang/fr/webext/panel/lex_editor.js from [629a2b4b0e] to [2142dc301a].

   568    568   
   569    569   const oBinaryDict = {
   570    570       
   571    571       oIBDAWG: null,
   572    572   
   573    573       load: function () {
   574    574           if (bChrome) {
   575         -            browser.storage.local.get("oDictionary", this._load);
          575  +            browser.storage.local.get("oPersonalDictionary", this._load);
   576    576               return;
   577    577           }
   578         -        let xPromise = browser.storage.local.get("oDictionary");
          578  +        let xPromise = browser.storage.local.get("oPersonalDictionary");
   579    579           xPromise.then(this._load.bind(this), showError);
   580    580       },
   581    581   
   582    582       _load: function (oResult) {
   583         -        if (!oResult.hasOwnProperty("oDictionary")) {
          583  +        if (!oResult.hasOwnProperty("oPersonalDictionary")) {
   584    584               oWidgets.hideElement("export_button");
   585    585               return;
   586    586           }
   587         -        let oJSON = oResult.oDictionary;
          587  +        let oJSON = oResult.oPersonalDictionary;
   588    588           this.oIBDAWG = new IBDAWG(oJSON);
   589    589           let lEntry = [];
   590    590           for (let s of this.oIBDAWG.select()) {
   591    591               lEntry.push(s.split("\t"));
   592    592           }        
   593    593           oLexicon.set(lEntry);
   594    594           oWidgets.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
................................................................................
   601    601           let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel", xProgressNode);
   602    602           let oJSON = oDAWG.createBinaryJSON(1);
   603    603           this.save(oJSON);
   604    604           this.oIBDAWG = new IBDAWG(oJSON);
   605    605           oWidgets.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
   606    606           oWidgets.hideElement("build_progress");
   607    607           oWidgets.showElement("export_button");
          608  +        browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: oJSON}, dInfo: {} });
   608    609       },
   609    610   
   610    611       save: function (oJSON) {
   611         -        browser.storage.local.set({ "oDictionary": oJSON });
          612  +        browser.storage.local.set({ "oPersonalDictionary": oJSON });
   612    613       },
   613    614   
   614    615       import: function () {
   615    616           // TO DO
   616    617       },
   617    618   
   618    619       export: function () {

Modified graphspell-js/spellchecker.js from [82a4eba2bb] to [61ed7ab1e9].

    58     58               return null;
    59     59           }
    60     60       }
    61     61   
    62     62       setMainDictionary (dictionary) {
    63     63           // returns true if the dictionary is loaded
    64     64           this.oMainDic = this._loadDictionary(dictionary);
    65         -        return bool(this.oMainDic);
           65  +        return Boolean(this.oMainDic);
    66     66       }
    67     67   
    68     68       setExtendedDictionary (dictionary) {
    69     69           // returns true if the dictionary is loaded
    70     70           this.oExtendedDic = this._loadDictionary(dictionary);
    71         -        return bool(this.oExtendedDic);
           71  +        return Boolean(this.oExtendedDic);
    72     72       }
    73     73   
    74     74       setPersonalDictionary (dictionary) {
    75     75           // returns true if the dictionary is loaded
    76     76           this.oPersonalDic = this._loadDictionary(dictionary);
    77         -        return bool(this.oPersonalDic);
           77  +        return Boolean(this.oPersonalDic);
    78     78       }
    79     79   
    80     80       // IBDAWG functions
    81     81   
    82     82       isValidToken (sToken) {
    83     83           // checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked)
    84     84           if (this.oMainDic.isValidToken(sToken)) {
................................................................................
   121    121           return false;
   122    122       }
   123    123   
   124    124       getMorph (sWord) {
   125    125           // retrieves morphologies list, different casing allowed
   126    126           let lResult = this.oMainDic.getMorph(sWord);
   127    127           if (this.oExtendedDic) {
   128         -            lResult.extends(this.oExtendedDic.getMorph(sWord));
          128  +            lResult.push(...this.oExtendedDic.getMorph(sWord));
   129    129           }
   130    130           if (this.oPersonalDic) {
   131         -            lResult.extends(this.oPersonalDic.getMorph(sWord));
          131  +            lResult.push(...this.oPersonalDic.getMorph(sWord));
   132    132           }
   133    133           return lResult;
   134    134       }
   135    135   
   136    136       * suggest (sWord, nSuggLimit=10) {
   137    137           // generator: returns 1, 2 or 3 lists of suggestions
   138    138           yield this.oMainDic.suggest(sWord, nSuggLimit);