Grammalecte  Check-in [8b6694ecca]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[graphspell] JS sucks: for some strange reason, Thunderbird doesn’t like the using of hasOwnProperty with personal Object -> use Map
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | graphspell | v1.1
Files: files | file ages | folders
SHA3-256:8b6694ecca38fa9e726ae0e5c0911000df878b78a0e96abade450d8b3233e350
User & Date: olr 2019-05-15 07:55:07
Context
2019-05-15
09:15
pylint: exclusion list check-in: a31e62962a user: olr tags: trunk
07:55
[graphspell] JS sucks: for some strange reason, Thunderbird doesn’t like the using of hasOwnProperty with personal Object -> use Map check-in: 8b6694ecca user: olr tags: graphspell, trunk, v1.1
06:30
[fr] mise à jour du dictionnaire check-in: 07779d8b19 user: olr tags: fr, trunk
Changes

Changes to graphspell-js/spellchecker.js.

    43     43           this.oMainDic = this._loadDictionary(mainDic, sPath, true);
    44     44           this.oCommunityDic = this._loadDictionary(communityDic, sPath);
    45     45           this.oPersonalDic = this._loadDictionary(personalDic, sPath);
    46     46           this.bCommunityDic = Boolean(this.oCommunityDic);
    47     47           this.bPersonalDic = Boolean(this.oPersonalDic);
    48     48           this.oTokenizer = null;
    49     49           // Default suggestions
    50         -        this.oDefaultSugg = null;
           50  +        this.dDefaultSugg = null;
    51     51           this.loadSuggestions(sLangCode)
    52     52           // storage
    53     53           this.bStorage = false;
    54     54           this._dMorphologies = new Map();            // key: flexion, value: list of morphologies
    55     55           this._dLemmas = new Map();                  // key: flexion, value: list of lemmas
    56     56       }
    57     57   
................................................................................
   131    131   
   132    132   
   133    133       // Default suggestions
   134    134   
   135    135       loadSuggestions (sLangCode) {
   136    136           // load default suggestion module for <sLangCode>
   137    137           // When “import” works everywhere, do like with Python
   138         -        if (suggest && suggest.hasOwnProperty(sLangCode)) {
   139         -            this.oDefaultSugg = suggest[sLangCode];
          138  +        try {
          139  +            if (typeof(suggest) !== 'undefined') {
          140  +                this.dDefaultSugg = suggest[sLangCode];
          141  +            }
          142  +        }
          143  +        catch (e) {
          144  +            console.error(e);
   140    145           }
   141    146       }
   142    147   
   143    148   
   144    149       // Storage
   145    150   
   146    151       activateStorage () {
................................................................................
   245    250               return this._dLemmas.get(sWord);
   246    251           }
   247    252           return Array.from(new Set(this.getMorph(sWord).map((sMorph) => { return sMorph.slice(1, sMorph.indexOf("/")); })));
   248    253       }
   249    254   
   250    255       * suggest (sWord, nSuggLimit=10) {
   251    256           // generator: returns 1, 2 or 3 lists of suggestions
   252         -        if (this.oDefaultSugg) {
   253         -            if (this.oDefaultSugg.hasOwnProperty(sWord)) {
   254         -                yield this.oDefaultSugg[sWord].split("|");
   255         -            } else if (sWord.gl_isTitle() && this.oDefaultSugg.hasOwnProperty(sWord.toLowerCase())) {
   256         -                let lRes = this.oDefaultSugg[sWord.toLowerCase()].split("|");
          257  +        if (this.dDefaultSugg) {
          258  +            if (this.dDefaultSugg.has(sWord)) {
          259  +                yield this.dDefaultSugg.get(sWord).split("|");
          260  +            } else if (sWord.gl_isTitle() && this.dDefaultSugg.has(sWord.toLowerCase())) {
          261  +                let lRes = this.dDefaultSugg.get(sWord.toLowerCase()).split("|");
   257    262                   yield lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
   258    263               } else {
   259    264                   yield this.oMainDic.suggest(sWord, nSuggLimit, true);
   260    265               }
   261    266           } else {
   262    267               yield this.oMainDic.suggest(sWord, nSuggLimit, true);
   263    268           }

Changes to graphspell-js/suggest.js.

     1      1   // JavaScript
     2      2   
     3      3   "use strict";
     4      4   
     5      5   var suggest = {
     6         -    "fr": {
     7         -        "bcp": "beaucoup",
     8         -        "ca": "ça",
     9         -        "cad": "c’est-à-dire",
    10         -        "cb": "combien|CB",
    11         -        "cdlt": "cordialement",
    12         -        "construirent": "construire|construisirent|construisent|construiront",
    13         -        "càd": "c’est-à-dire",
    14         -        "dc": "de|donc",
    15         -        "done": "donc|donne",
    16         -        "email": "courriel|e-mail|émail",
    17         -        "emails": "courriels|e-mails",
    18         -        "Etes-vous": "Êtes-vous",
    19         -        "Etiez-vous": "Étiez-vous",
    20         -        "Etions-nous": "Étions-nous",
    21         -        "parce-que": "parce que",
    22         -        "pcq": "parce que",
    23         -        "pd": "pendant|pédé",
    24         -        "pdq": "pendant que",
    25         -        "pdt": "pendant",
    26         -        "pdtq": "pendant que",
    27         -        "pk": "pourquoi",
    28         -        "pq": "pourquoi|PQ",
    29         -        "prq": "presque",
    30         -        "prsq": "presque",
    31         -        "qcq": "quiconque",
    32         -        "qq": "quelque",
    33         -        "qqch": "quelque chose",
    34         -        "qqn": "quelqu’un",
    35         -        "qqne": "quelqu’une",
    36         -        "qqs": "quelques",
    37         -        "qqunes": "quelques-unes",
    38         -        "qquns": "quelques-uns",
    39         -        "tdq": "tandis que",
    40         -        "tj": "toujours",
    41         -        "tjs": "toujours",
    42         -        "tq": "tant que|tandis que",
    43         -        "ts": "tous",
    44         -        "tt": "tant|tout",
    45         -        "tte": "toute",
    46         -        "ttes": "toutes"
    47         -    }
            6  +    fr: new Map ([
            7  +        ["bcp", "beaucoup"],
            8  +        ["ca", "ça"],
            9  +        ["cad", "c’est-à-dire"],
           10  +        ["cb", "combien|CB"],
           11  +        ["cdlt", "cordialement"],
           12  +        ["construirent", "construire|construisirent|construisent|construiront"],
           13  +        ["càd", "c’est-à-dire"],
           14  +        ["dc", "de|donc"],
           15  +        ["done", "donc|donne"],
           16  +        ["email", "courriel|e-mail|émail"],
           17  +        ["emails", "courriels|e-mails"],
           18  +        ["Etes-vous", "Êtes-vous"],
           19  +        ["Etiez-vous", "Étiez-vous"],
           20  +        ["Etions-vous", "Étions-nous"],
           21  +        ["parce-que", "parce que"],
           22  +        ["pcq", "parce que"],
           23  +        ["pd", "pendant|pédé"],
           24  +        ["pdq", "pendant que"],
           25  +        ["pdt", "pendant"],
           26  +        ["pdtq", "pendant que"],
           27  +        ["pk", "pourquoi"],
           28  +        ["pq", "pourquoi|PQ"],
           29  +        ["prq", "presque"],
           30  +        ["prsq", "presque"],
           31  +        ["qcq", "quiconque"],
           32  +        ["qq", "quelque"],
           33  +        ["qqch", "quelque chose"],
           34  +        ["qqn", "quelqu’un"],
           35  +        ["qqne", "quelqu’une"],
           36  +        ["qqs", "quelques"],
           37  +        ["qqunes", "quelques-unes"],
           38  +        ["qquns", "quelques-uns"],
           39  +        ["tdq", "tandis que"],
           40  +        ["tj", "toujours"],
           41  +        ["tjs", "toujours"],
           42  +        ["tq", "tant que|tandis que"],
           43  +        ["ts", "tous"],
           44  +        ["tt", "tant|tout"],
           45  +        ["tte", "toute"],
           46  +        ["ttes", "toutes"]
           47  +    ])
           48  +};
           49  +
           50  +
           51  +if (typeof(exports) !== 'undefined') {
           52  +    exports.fr = suggest.fr;
    48     53   }