Index: graphspell-js/spellchecker.js ================================================================== --- graphspell-js/spellchecker.js +++ graphspell-js/spellchecker.js @@ -45,11 +45,11 @@ this.oPersonalDic = this._loadDictionary(personalDic, sPath); this.bCommunityDic = Boolean(this.oCommunityDic); this.bPersonalDic = Boolean(this.oPersonalDic); this.oTokenizer = null; // Default suggestions - this.oDefaultSugg = null; + this.dDefaultSugg = null; this.loadSuggestions(sLangCode) // storage this.bStorage = false; this._dMorphologies = new Map(); // key: flexion, value: list of morphologies this._dLemmas = new Map(); // key: flexion, value: list of lemmas @@ -133,12 +133,17 @@ // Default suggestions loadSuggestions (sLangCode) { // load default suggestion module for // When “import” works everywhere, do like with Python - if (suggest && suggest.hasOwnProperty(sLangCode)) { - this.oDefaultSugg = suggest[sLangCode]; + try { + if (typeof(suggest) !== 'undefined') { + this.dDefaultSugg = suggest[sLangCode]; + } + } + catch (e) { + console.error(e); } } // Storage @@ -247,15 +252,15 @@ return Array.from(new Set(this.getMorph(sWord).map((sMorph) => { return sMorph.slice(1, sMorph.indexOf("/")); }))); } * suggest (sWord, nSuggLimit=10) { // generator: returns 1, 2 or 3 lists of suggestions - if (this.oDefaultSugg) { - if (this.oDefaultSugg.hasOwnProperty(sWord)) { - yield this.oDefaultSugg[sWord].split("|"); - } else if (sWord.gl_isTitle() && this.oDefaultSugg.hasOwnProperty(sWord.toLowerCase())) { - let lRes = this.oDefaultSugg[sWord.toLowerCase()].split("|"); + if (this.dDefaultSugg) { + if (this.dDefaultSugg.has(sWord)) { + yield this.dDefaultSugg.get(sWord).split("|"); + } else if (sWord.gl_isTitle() && this.dDefaultSugg.has(sWord.toLowerCase())) { + let lRes = this.dDefaultSugg.get(sWord.toLowerCase()).split("|"); yield lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); }); } else { yield this.oMainDic.suggest(sWord, nSuggLimit, true); } } else { Index: graphspell-js/suggest.js ================================================================== --- graphspell-js/suggest.js +++ graphspell-js/suggest.js @@ -1,48 +1,53 @@ // JavaScript "use strict"; var suggest = { - "fr": { - "bcp": "beaucoup", - "ca": "ça", - "cad": "c’est-à-dire", - "cb": "combien|CB", - "cdlt": "cordialement", - "construirent": "construire|construisirent|construisent|construiront", - "càd": "c’est-à-dire", - "dc": "de|donc", - "done": "donc|donne", - "email": "courriel|e-mail|émail", - "emails": "courriels|e-mails", - "Etes-vous": "Êtes-vous", - "Etiez-vous": "Étiez-vous", - "Etions-nous": "Étions-nous", - "parce-que": "parce que", - "pcq": "parce que", - "pd": "pendant|pédé", - "pdq": "pendant que", - "pdt": "pendant", - "pdtq": "pendant que", - "pk": "pourquoi", - "pq": "pourquoi|PQ", - "prq": "presque", - "prsq": "presque", - "qcq": "quiconque", - "qq": "quelque", - "qqch": "quelque chose", - "qqn": "quelqu’un", - "qqne": "quelqu’une", - "qqs": "quelques", - "qqunes": "quelques-unes", - "qquns": "quelques-uns", - "tdq": "tandis que", - "tj": "toujours", - "tjs": "toujours", - "tq": "tant que|tandis que", - "ts": "tous", - "tt": "tant|tout", - "tte": "toute", - "ttes": "toutes" - } + fr: new Map ([ + ["bcp", "beaucoup"], + ["ca", "ça"], + ["cad", "c’est-à-dire"], + ["cb", "combien|CB"], + ["cdlt", "cordialement"], + ["construirent", "construire|construisirent|construisent|construiront"], + ["càd", "c’est-à-dire"], + ["dc", "de|donc"], + ["done", "donc|donne"], + ["email", "courriel|e-mail|émail"], + ["emails", "courriels|e-mails"], + ["Etes-vous", "Êtes-vous"], + ["Etiez-vous", "Étiez-vous"], + ["Etions-vous", "Étions-nous"], + ["parce-que", "parce que"], + ["pcq", "parce que"], + ["pd", "pendant|pédé"], + ["pdq", "pendant que"], + ["pdt", "pendant"], + ["pdtq", "pendant que"], + ["pk", "pourquoi"], + ["pq", "pourquoi|PQ"], + ["prq", "presque"], + ["prsq", "presque"], + ["qcq", "quiconque"], + ["qq", "quelque"], + ["qqch", "quelque chose"], + ["qqn", "quelqu’un"], + ["qqne", "quelqu’une"], + ["qqs", "quelques"], + ["qqunes", "quelques-unes"], + ["qquns", "quelques-uns"], + ["tdq", "tandis que"], + ["tj", "toujours"], + ["tjs", "toujours"], + ["tq", "tant que|tandis que"], + ["ts", "tous"], + ["tt", "tant|tout"], + ["tte", "toute"], + ["ttes", "toutes"] + ]) +}; + + +if (typeof(exports) !== 'undefined') { + exports.fr = suggest.fr; }