Grammalecte  Check-in [ec5393a4f1]

Overview
Comment:[graphspell][js] ibdawg: getJSON() function + [fx] update: lexicon editor
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx | graphspell
Files: files | file ages | folders
SHA3-256: ec5393a4f1a6a2805ae76c069089d0563432711f87fae41fdac06d0051e16446
User & Date: olr on 2018-02-12 12:29:40
Original Comment: [graphspell][js] ibdawg: getJSON() function
Other Links: manifest | tags
Context
2018-02-12
12:55
[graphspell] fix date generation check-in: 5dd255e81e user: olr tags: trunk, graphspell
12:29
[graphspell][js] ibdawg: getJSON() function + [fx] update: lexicon editor check-in: ec5393a4f1 user: olr tags: trunk, fx, graphspell
09:04
[graphspell][py] convert hexadecimal string to binary string check-in: b6937acb8c user: olr tags: trunk, graphspell
Changes

Modified gc_lang/fr/webext/panel/lex_editor.js from [83999992e4] to [2251620d6f].

558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590


591
592
593
594
595
596

597
598
599
600
601
602
603
604
605




606
607
608
609
610
611


612
613
614
615
616
617
618
619

620
621
622
623
624
625
558
559
560
561
562
563
564

565
566
567
568
569
570

571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586


587
588
589
590
591
592
593

594
595
596
597
598
599
600
601


602
603
604
605
606
607
608
609


610
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625







-






-
















-
-
+
+





-
+







-
-
+
+
+
+




-
-
+
+







-
+






    save: function () {
        oWidgets.hideElement("save_button");
        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);
            return;
        }
        let xPromise = browser.storage.local.get("oDictionary");
        xPromise.then(this._load.bind(this), showError);
    },

    _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();

Modified graphspell-js/dawg.js from [4f989404b7] to [0b803fa3ec].

326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340







-
+







                    }
                }
            }
        }
    }

    // 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();
            this._calcNodesAddress1();
        } else {
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405







-
+







            "nCompressionMethod": nCompressionMethod,
            "nBytesArc": this.nBytesArc,
            "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");
        let sHours = (oDate.getHours()).toString().padStart(2, "0");
        let sMinutes = (oDate.getMinutes()).toString().padStart(2, "0");

Modified graphspell-js/ibdawg.js from [61152510c9] to [529ef5e9b4].

178
179
180
181
182
183
184



























185
186
187
188
189
190
191
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    getInfo () {
        return  `  Language: ${this.sLangName}   Lang code: ${this.sLangCode}   Dictionary name: ${this.sDicName}\n` +
                `  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;
        }
        if (sToken.includes("-")) {