Index: gc_lang/fr/webext/panel/lex_editor.js ================================================================== --- gc_lang/fr/webext/panel/lex_editor.js +++ gc_lang/fr/webext/panel/lex_editor.js @@ -560,18 +560,16 @@ this.lFlexion = this.lFlexion.filter((e) => e !== null); oBinaryDict.build(this.lFlexion); this.resetModif(); oWidgets.displayTable(this.lFlexion); oWidgets.updateData(); - oWidgets.setDictData(this.lFlexion.length, this._getDate()); } } const oBinaryDict = { - oJSON: null, oIBDAWG: null, load: function () { if (bChrome) { browser.storage.local.get("oDictionary", this._load); @@ -584,42 +582,44 @@ _load: function (oResult) { if (!oResult.hasOwnProperty("oDictionary")) { oWidgets.hideElement("export_button"); return; } - this.oJSON = oResult.oDictionary; - this.oIBDAWG = new IBDAWG(this.oJSON); + let oJSON = oResult.oDictionary; + this.oIBDAWG = new IBDAWG(oJSON); let lEntry = []; for (let s of this.oIBDAWG.select()) { lEntry.push(s.split("\t")); } oLexicon.set(lEntry); - oWidgets.setDictData(lEntry.length, oJSON.sDate); + oWidgets.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate); oWidgets.showElement("export_button"); }, build: function (lEntry) { oWidgets.showElement("build_progress"); let xProgressNode = document.getElementById("build_progress"); let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel", xProgressNode); - this.oJSON = oDAWG.createBinary(1); - this.save(); + let oJSON = oDAWG.createBinaryJSON(1); + this.save(oJSON); + this.oIBDAWG = new IBDAWG(oJSON); + oWidgets.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate); oWidgets.hideElement("build_progress"); oWidgets.showElement("export_button"); }, - save: function () { - browser.storage.local.set({ "oDictionary": this.oJSON }); + save: function (oJSON) { + browser.storage.local.set({ "oDictionary": oJSON }); }, import: function () { // TO DO }, export: function () { - let xBlob = new Blob([ JSON.stringify(this.oJSON) ], {type: 'application/json'}); + let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'}); let sURL = URL.createObjectURL(xBlob); browser.downloads.download({ filename: "grammalecte_dictionnaire_personnel.json", url: sURL, saveAs: true }); } } oBinaryDict.load(); Index: graphspell-js/dawg.js ================================================================== --- graphspell-js/dawg.js +++ graphspell-js/dawg.js @@ -328,11 +328,11 @@ } } } // BINARY CONVERSION - createBinary (nCompressionMethod) { + createBinaryJSON (nCompressionMethod) { console.log("Write DAWG as an indexable binary dictionary [method: "+nCompressionMethod+"]"); if (nCompressionMethod == 1) { this.nBytesArc = Math.floor( (this.nArcVal.toString(2).length + 2) / 8 ) + 1; // We add 2 bits. See DawgNode.convToBytes1() this.nBytesOffset = 0; this._calcNumBytesNodeAddress(); @@ -393,11 +393,11 @@ "nBytesNodeAddress": this.nBytesNodeAddress, "nBytesOffset": this.nBytesOffset, "sByDic": sByDic // binary word graph }; return oJSON; - }, + } _getDate () { let oDate = new Date(); let sMonth = (oDate.getMonth() + 1).toString().padStart(2, "0"); // Month+1: Because JS always sucks somehow. let sDay = (oDate.getDay()).toString().padStart(2, "0"); Index: graphspell-js/ibdawg.js ================================================================== --- graphspell-js/ibdawg.js +++ graphspell-js/ibdawg.js @@ -180,10 +180,37 @@ ` Compression method: ${this.nCompressionMethod} Date: ${this.sDate} Stemming: ${this.cStemming}FX\n` + ` Arcs values: ${this.nArcVal} = ${this.nChar} characters, ${this.nAff} affixes, ${this.nTag} tags\n` + ` Dictionary: ${this.nEntry} entries, ${this.nNode} nodes, ${this.nArc} arcs\n` + ` Address size: ${this.nBytesNodeAddress} bytes, Arc size: ${this.nBytesArc} bytes\n`; } + + getJSON () { + let oJSON = { + "sHeader": "/pyfsa/", + "sLangCode": this.sLangCode, + "sLangName": this.sLangName, + "sDicName": this.sDicName, + "sFileName": this.sFileName, + "sDate": this.sDate, + "nEntry": this.nEntry, + "nChar": this.nChar, + "nAff": this.nAff, + "nTag": this.nTag, + "cStemming": this.cStemming, + "dChar": helpers.mapToObject(this.dChar), + "nNode": this.nNode, + "nArc": this.nArc, + "lArcVal": this.lArcVal, + "nArcVal": this.nArcVal, + "nCompressionMethod": nCompressionMethod, + "nBytesArc": this.nBytesArc, + "nBytesNodeAddress": this.nBytesNodeAddress, + "nBytesOffset": this.nBytesOffset, + "sByDic": this.sByDic // binary word graph + }; + return oJSON; + } isValidToken (sToken) { // checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked) if (this.isValid(sToken)) { return true;