Index: gc_lang/fr/build_data.py ================================================================== --- gc_lang/fr/build_data.py +++ gc_lang/fr/build_data.py @@ -56,33 +56,21 @@ except: traceback.print_exc() def makeDictionaries (sp, sVersion): + print("> Exécution du script dans gc_lang/fr/dictionnaire:") + print(" genfrdic.py -s -gl -v "+sVersion) with cd(sp+"/dictionnaire"): if platform.system() == "Windows": os.system("python genfrdic.py -s -gl -v "+sVersion) else: os.system("python3 ./genfrdic.py -s -gl -v "+sVersion) - -def makeThesaurusFiles (sp, bJS=False): - dThesaurus = {} - sContent = open(sp+'/data/thes_fr.json', "r", encoding="utf-8").read() - dThesaurus = json.loads(sContent) - ## write file for Python - sCode = "# generated data (do not edit)\n\n" + \ - "dThesaurus = " + str(dThesaurus) + "\n" - open(sp+"/modules/thesaurus_data.py", "w", encoding="utf-8", newline="\n").write(sCode) - if bJS: - ## write file for JavaScript - shutil.copy2(sp+'/data/thes_fr.json', sp+"/modules-js/thesaurus_data.json") - def makeConj (sp, bJS=False): - print("> Conjugaisons ", end="") - print("(Python et JavaScript)" if bJS else "(Python seulement)") + print("> Fichier des conjugaisons pour Grammalecte") dVerb = {} lVinfo = []; dVinfo = {}; nVinfo = 0 lTags = []; dTags = {}; nTags = 0 dVerbNames = {} @@ -208,12 +196,11 @@ hDst.write(' "dVerbNames": ' + json.dumps(dVerbNames, ensure_ascii=False) + "\n") hDst.write("}\n") def makeMfsp (sp, bJS=False): - print("> Pluriel/singulier/masculin/féminin ", end="") - print("(Python et JavaScript)" if bJS else "(Python seulement)") + print("> Fichier des pluriels/singuliers/masculins/féminins pour Grammalecte") aPlurS = set() # pluriels en -s dTag = {} lTagFemForm = [] lTagMiscPlur = [] # pluriels spéciaux dMiscPlur = {} @@ -297,12 +284,11 @@ ' "dMasForm": ' + json.dumps(dMasForm, ensure_ascii=False) + "\n}" open(sp+"/modules-js/mfsp_data.json", "w", encoding="utf-8", newline="\n").write(sCode) def makePhonetTable (sp, bJS=False): - print("> Correspondances phonétiques ", end="") - print("(Python et JavaScript)" if bJS else "(Python seulement)") + print("> Fichier des correspondances phonétiques pour Grammalecte") loadDictionary() conj = importlib.import_module("gc_lang.fr.modules.conj") @@ -356,17 +342,40 @@ ' "dWord": ' + json.dumps(dWord, ensure_ascii=False) + ",\n" + \ ' "lSet": ' + json.dumps(lSet, ensure_ascii=False) + ",\n" + \ ' "dMorph": ' + json.dumps(dMorph, ensure_ascii=False) + "\n}" open(sp+"/modules-js/phonet_data.json", "w", encoding="utf-8", newline="\n").write(sCode) + +def makeThesaurusFiles (sp, bJS=False): + print("> Fichiers du Thésaurus pour Grammalecte") + dThesaurus = {} + sContent = open(sp+'/data/thes_fr.json', "r", encoding="utf-8").read() + dThesaurus = json.loads(sContent) + ## write file for Python + sCode = "# generated data (do not edit)\n\n" + \ + "dThesaurus = " + str(dThesaurus) + "\n" + open(sp+"/modules/thesaurus_data.py", "w", encoding="utf-8", newline="\n").write(sCode) + if bJS: + ## write file for JavaScript + #shutil.copy2(sp+'/data/thes_fr.json', sp+"/modules-js/thesaurus_data.json") + + # thes_fr.json is too big, we have to split it. + # Addons.mozilla.org doesn’t a file that big. 5 Mo maximum. + nHalfSize = len(dThesaurus) // 2 + dThes1 = { k: v for i, (k, v) in enumerate(dThesaurus.items()) if i < nHalfSize } + dThes2 = { k: v for i, (k, v) in enumerate(dThesaurus.items()) if i >= nHalfSize } + open(sp+"/modules-js/thesaurus1_data.json", "w", encoding="utf-8").write(json.dumps(dThes1, ensure_ascii=False)) + open(sp+"/modules-js/thesaurus2_data.json", "w", encoding="utf-8").write(json.dumps(dThes2, ensure_ascii=False)) + def before (spLaunch, dVars, bJS=False): - print("========== Build Hunspell dictionaries / Thesaurus ==========") + print("========== Construction des dictionnaires Hunspell et du Thesaurus ==========") makeDictionaries(spLaunch, dVars['oxt_version']) - makeThesaurusFiles(spLaunch, bJS) + def after (spLaunch, dVars, bJS=False): - print("========== Build French data ==========") + print("========== Création des fichiers de données pour Grammalecte ==========") + print("(Python et JavaScript)" if bJS else "(Python seulement)") makeMfsp(spLaunch, bJS) makeConj(spLaunch, bJS) makePhonetTable(spLaunch, bJS) - + makeThesaurusFiles(spLaunch, bJS) Index: gc_lang/fr/modules-js/conj_data.json ================================================================== --- gc_lang/fr/modules-js/conj_data.json +++ gc_lang/fr/modules-js/conj_data.json cannot compute difference between binary files Index: gc_lang/fr/modules-js/phonet_data.json ================================================================== --- gc_lang/fr/modules-js/phonet_data.json +++ gc_lang/fr/modules-js/phonet_data.json cannot compute difference between binary files Index: gc_lang/fr/modules-js/thesaurus.js ================================================================== --- gc_lang/fr/modules-js/thesaurus.js +++ gc_lang/fr/modules-js/thesaurus.js @@ -16,13 +16,18 @@ var thesaurus = { _dWord: new Map(), bInit: false, - init: function (sJSONData) { + init: function (sJSONData1, sJSONData2) { try { - let _oData = JSON.parse(sJSONData); + // As addons.mozilla.org doesn’t accept file bigger than 5 Mb, + // we had to split the thesaurus in two parts. And now we merge them. + let _oData1 = JSON.parse(sJSONData1); + let _oData2 = JSON.parse(sJSONData2); + let _oData = { ..._oData1, ..._oData2 }; + // convert to Map this._dWord = helpers.objectToMap(_oData); this.bInit = true; //console.log(this._dWord); } catch (e) { @@ -51,17 +56,17 @@ // Initialization if (!thesaurus.bInit && typeof(process) !== 'undefined') { // NodeJS - thesaurus.init(helpers.loadFile(__dirname+"/thesaurus_data.json")); + thesaurus.init(helpers.loadFile(__dirname+"/thesaurus1_data.json"), helpers.loadFile(__dirname+"/thesaurus2_data.json")); } else if (!thesaurus.bInit && typeof(browser) !== 'undefined') { // WebExtension Standard (but not in Worker) - thesaurus.init(helpers.loadFile(browser.runtime.getURL("grammalecte/fr/thesaurus_data.json"))); + thesaurus.init(helpers.loadFile(browser.runtime.getURL("grammalecte/fr/thesaurus1_data.json")), helpers.loadFile(browser.runtime.getURL("grammalecte/fr/thesaurus2_data.json"))); } else if (!thesaurus.bInit && typeof(chrome) !== 'undefined') { // WebExtension Chrome (but not in Worker) - thesaurus.init(helpers.loadFile(chrome.runtime.getURL("grammalecte/fr/thesaurus_data.json"))); + thesaurus.init(helpers.loadFile(chrome.runtime.getURL("grammalecte/fr/thesaurus1_data.json")), helpers.loadFile(chrome.runtime.getURL("grammalecte/fr/thesaurus2_data.json"))); } else if (thesaurus.bInit){ console.log("Module thesaurus déjà initialisé"); } else { //console.log("Module thesaurus non initialisé"); } ADDED gc_lang/fr/modules-js/thesaurus1_data.json Index: gc_lang/fr/modules-js/thesaurus1_data.json ================================================================== --- /dev/null +++ gc_lang/fr/modules-js/thesaurus1_data.json cannot compute difference between binary files ADDED gc_lang/fr/modules-js/thesaurus2_data.json Index: gc_lang/fr/modules-js/thesaurus2_data.json ================================================================== --- /dev/null +++ gc_lang/fr/modules-js/thesaurus2_data.json cannot compute difference between binary files DELETED gc_lang/fr/modules-js/thesaurus_data.json Index: gc_lang/fr/modules-js/thesaurus_data.json ================================================================== --- gc_lang/fr/modules-js/thesaurus_data.json +++ /dev/null cannot compute difference between binary files Index: gc_lang/fr/modules/conj_data.py ================================================================== --- gc_lang/fr/modules/conj_data.py +++ gc_lang/fr/modules/conj_data.py cannot compute difference between binary files Index: gc_lang/fr/modules/phonet_data.py ================================================================== --- gc_lang/fr/modules/phonet_data.py +++ gc_lang/fr/modules/phonet_data.py cannot compute difference between binary files Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -176,11 +176,11 @@ if (!bInitDone) { //console.log("[Worker] Loading… Extension path: " + sExtensionPath); conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json")); phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json")); mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json")); - thesaurus.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/thesaurus_data.json")); + thesaurus.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/thesaurus1_data.json"), helpers.loadFile(sExtensionPath + "/grammalecte/fr/thesaurus2_data.json")); //console.log("[Worker] Modules have been initialized…"); gc_engine.load(sContext, "aHSL", sExtensionPath+"grammalecte/graphspell/_dictionaries"); oSpellChecker = gc_engine.getSpellChecker(); oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json"); oTokenizer = new Tokenizer("fr"); Index: make.py ================================================================== --- make.py +++ make.py @@ -176,11 +176,11 @@ hZip.write(spLangPack+"/"+sf, sAddPath+spLangPack+"/"+sf) def create (sLang, xConfig, bInstallOXT, bJavaScript, bUseCache): "make Grammalecte for project " - print(f">>>> MAKE GC ENGINE: {sLang} <<<<") + print(f"========== MAKE GC ENGINE: {sLang} ==========") #### READ CONFIGURATION print("> read configuration...") spLang = "gc_lang/" + sLang @@ -281,11 +281,11 @@ return dVars['version'] def copyGraphspellCore (bJavaScript=False): "copy Graphspell package in Grammalecte package" - print("> Copy Graphspell package in Grammalecte package") + print("===== Copy Graphspell package in Grammalecte package =====") helpers.createCleanFolder("grammalecte/graphspell") os.makedirs("grammalecte/graphspell/_dictionaries", exist_ok=True) for sf in os.listdir("graphspell"): if not os.path.isdir("graphspell/"+sf): shutil.copy2("graphspell/"+sf, "grammalecte/graphspell") @@ -301,11 +301,11 @@ helpers.copyAndFileTemplate("graphspell-js/"+sf, "grammalecte-js/graphspell/"+sf, dVars) def copyGraphspellDictionaries (dVars, bJavaScript=False, bCommunityDict=False, bPersonalDict=False): "copy requested Graphspell dictionaries in Grammalecte package" - print("> Copy requested Graphspell dictionaries in Grammalecte package") + print("===== Copy requested Graphspell dictionaries in Grammalecte package =====") dVars["dic_main_filename_py"] = "" dVars["dic_main_filename_js"] = "" dVars["dic_community_filename_py"] = "" dVars["dic_community_filename_js"] = "" dVars["dic_personal_filename_py"] = "" @@ -413,11 +413,11 @@ xParser.add_argument("-tbb", "--thunderbird_beta", help="Launch Thunderbird Beta", action="store_true") xParser.add_argument("-i", "--install", help="install the extension in Writer (path of unopkg must be set in config.ini)", action="store_true") xArgs = xParser.parse_args() oNow = datetime.datetime.now() - print("============== MAKE GRAMMALECTE at {0.hour:>2} h {0.minute:>2} min {0.second:>2} s ==============".format(oNow)) + print("#################### MAKE GRAMMALECTE at {0.hour:>2} h {0.minute:>2} min {0.second:>2} s ####################".format(oNow)) if xArgs.build_data: xArgs.build_data_before = True xArgs.build_data_after = True