Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -33,10 +33,11 @@ //console.log(self); importScripts("grammalecte/graphspell/helpers.js"); importScripts("grammalecte/graphspell/str_transform.js"); importScripts("grammalecte/graphspell/char_player.js"); +importScripts("grammalecte/graphspell/suggest.js"); importScripts("grammalecte/graphspell/ibdawg.js"); importScripts("grammalecte/graphspell/spellchecker.js"); importScripts("grammalecte/text.js"); importScripts("grammalecte/graphspell/tokenizer.js"); importScripts("grammalecte/fr/conj.js"); Index: graphspell-js/spellchecker.js ================================================================== --- graphspell-js/spellchecker.js +++ graphspell-js/spellchecker.js @@ -14,13 +14,15 @@ "use strict"; if(typeof(process) !== 'undefined') { var ibdawg = require("./ibdawg.js"); var tokenizer = require("./tokenizer.js"); + var suggest = require("./suggest.js"); } else if (typeof(require) !== 'undefined') { var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js"); var tokenizer = require("resource://grammalecte/graphspell/tokenizer.js"); + var suggest = require("resource://grammalecte/graphspell/suggest.js"); } ${map} @@ -42,10 +44,13 @@ this.oCommunityDic = this._loadDictionary(communityDic, sPath); 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.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 } @@ -122,10 +127,21 @@ deactivatePersonalDictionary () { this.bPersonalDic = false; } + + // 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]; + } + } + // Storage activateStorage () { this.bStorage = true; @@ -231,11 +247,22 @@ 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 - yield this.oMainDic.suggest(sWord, nSuggLimit, true); + if (this.oDefaultSugg) { + if (this.oDefaultSugg.hasOwnProperty(sWord)) { + yield this.oDefaultSugg[sWord].split("|"); + } else if (sWord.gl_isTitle() && this.oDefaultSugg.hasOwnProperty(sWord.lower())) { + let lRes = this.oDefaultSugg[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 { + yield this.oMainDic.suggest(sWord, nSuggLimit, true); + } if (this.bCommunityDic) { yield this.oCommunityDic.suggest(sWord, Math.floor(nSuggLimit/2)+1); } if (this.bPersonalDic) { yield this.oPersonalDic.suggest(sWord, Math.floor(nSuggLimit/2)+1); ADDED graphspell-js/suggest.js Index: graphspell-js/suggest.js ================================================================== --- graphspell-js/suggest.js +++ graphspell-js/suggest.js @@ -0,0 +1,48 @@ +// 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" + } +} Index: graphspell/fr.py ================================================================== --- graphspell/fr.py +++ graphspell/fr.py @@ -8,10 +8,11 @@ "cad": "c’est-à-dire", "cb": "combien|CB", "cdlt": "cordialement", "construirent": "construire|construisirent|construisent|construiront", "càd": "c’est-à-dire", + "done": "donc|donne", "dc": "de|donc", "email": "courriel|e-mail|émail", "emails": "courriels|e-mails", "Etes-vous": "Êtes-vous", "Etiez-vous": "Étiez-vous",