Grammalecte  Check-in [778321169e]

Overview
Comment:[fx] update: lexicon editor
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 778321169ea3d288c6c5093423fe4cf058a2833b23e2809b623828cbd087c567
User & Date: olr on 2018-02-10 07:53:34
Other Links: manifest | tags
Context
2018-02-10
13:19
[fx] lexicon editor: fix loading check-in: 708091ec61 user: olr tags: trunk, fx
07:53
[fx] update: lexicon editor check-in: 778321169e user: olr tags: trunk, fx
2018-02-09
15:30
[graphspell][js] dawg: fix bug in select() check-in: dd59a31d13 user: olr tags: trunk, graphspell
Changes

Modified gc_lang/fr/webext/panel/lex_editor.css from [37248071c7] to [307d727b83].

233
234
235
236
237
238
239



240
241
242
243
244





245
246
247
248
249
250
251
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259







+
+
+





+
+
+
+
+







}
#export_button, #import_button {
    display: block;
    margin-left: 5px;
    background-color: hsl(210, 50%, 50%);
    color: hsl(210, 0%, 100%);
}
#import_button {
    display: none;
}

#build_progress {
    display: none;
    width: 100%;
}

#display_progress {
    display: none;
    width: 100%;
}

th {
    padding: 5px 10px;
    border-left: 1px solid hsl(210, 10%, 90%);
    text-align: left;
}
td {

Modified gc_lang/fr/webext/panel/lex_editor.html from [07c19d863f] to [78fc49cfbe].

288
289
290
291
292
293
294

295
296
297
298
299
300
301
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302







+







                    <h3>Dictionnaire enregistré</h3>
                    <p>Dernière sauvegarde : <span id="save_date">néant</span>.</p>
                    <p>Nombre d’entrées : <span id="num_entries_saved">0</span>.</p>
                </div>
                

                <p id="no_elem_line">Aucun élément.</p>
                <p><progress id="display_progress" value="0"></p>

                <table id="table">
                    
                </table>
            </div>
        </div>

Modified gc_lang/fr/webext/panel/lex_editor.js from [3661f4f0a2] to [636758bca9].

195
196
197
198
199
200
201


202
203


204
205
206
207
208

209


210
211
212
213
214
215
216
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223







+
+


+
+





+

+
+







        xRowNode.appendChild(createNode("td", { textContent: sTags }));
        return xRowNode;
    },

    displayTable: function (lFlex) {
        this.clearTable();
        if (lFlex.length > 0) {
            this.showElement("display_progress");
            let xDisplayProgress = document.getElementById("display_progress");
            let xTable = document.getElementById("table");
            let n = 0;
            xDisplayProgress.max = lFlex.length;
            xDisplayProgress.value = 1;
            this.hideElement("no_elem_line");
            xTable.appendChild(this.createTableHeader());
            for (let [sFlexion, sLemma, sTags] of lFlex) {
                xTable.appendChild(this.createRowNode(n, sFlexion, sLemma, sTags));
                n += 1;
                xDisplayProgress.value += 1;
            }
            xDisplayProgress.value = xDisplayProgress.max;
            this.hideElement("display_progress");
        } else {
            this.showElement("no_elem_line");
        }
        this.updateData();
    },

    clearTable: function () {
440
441
442
443
444
445
446
447


448
449
450

451
452
453
454
455
456

457
458
459
460
461
462
463
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473







-
+
+



+






+







    },

    _getConjRules: function (sVerb) {
        if (sVerb.endsWith("ir")) {
            // deuxième groupe
            return oConj["V2"];
        } else if (sVerb.endsWith("er")) {
            // premier groupe
            // premier groupe, conjugaison en fonction de la terminaison du lemme
            // 5 lettres
            if (sVerb.slice(-5) in oConj["V1"]) {
                return oConj["V1"][sVerb.slice(-5)];
            }
            // 4 lettres
            if (sVerb.slice(-4) in oConj["V1"]) {
                if (sVerb.endsWith("eler") || sVerb.endsWith("eter")) {
                    return oConj["V1"][sVerb.slice(-4)]["1"];
                }
                return oConj["V1"][sVerb.slice(-4)];
            }
            // 3 lettres
            if (sVerb.slice(-3) in oConj["V1"]) {
                return oConj["V1"][sVerb.slice(-3)];
            }
            return oConj["V1"]["er"];
        } else {
            // troisième groupe
            return [ [0, "", ":Y/*", false] ];
508
509
510
511
512
513
514
515

516
517
518
519
520
521
522
523
524
525
526
527
528



529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
518
519
520
521
522
523
524

525













526
527
528

529
530
531
532
533
534
535






536
537
538
539
540
541
542







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-







-
-
-
-
-
-







const oLexicon = {

    lFlexion: [],
    nEntries: 0,
    nDeletedEntries: 0,
    nAddedEntries: 0,

    load: function () {
    set: function (lFlexion) {
        if (bChrome) {
            browser.storage.local.get("oLexicon", this._load);
            return;
        }
        let xPromise = browser.storage.local.get("oLexicon");
        xPromise.then(this._load.bind(this), showError);
    },

    _load: function (oResult) {
        if (oResult.hasOwnProperty("oLexicon")) {
            this.lFlexion = oResult.oLexicon.lEntry;
            oWidgets.setDictData(this.lFlexion.length, oResult.oLexicon.sDate);
            oWidgets.displayTable(this.lFlexion);
        this.lFlexion = lFlexion;
        this.resetModif();
        oWidgets.displayTable(this.lFlexion);
        }
        if (this.lFlexion.length > 0) {
            oWidgets.showElement("export_button");
        } else {
            oWidgets.hideElement("export_button");
        }
    },

    set: function (lFlexion) {
        this.lFlexion = lFlexion; // clear the array
        this.resetModif();
        oWidgets.displayTable(this.lFlexion);
    },

    addFlexions: function (lFlex) {
        let n = lFlex.length;
        for (let aFlex of lFlex) {
            this.lFlexion.push(aFlex);
        }
        this.nAddedEntries += n;
        this.nEntries += n;
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
553
554
555
556
557
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







-
-
-
-
-
-
-
-
-
-
+
+



-
+
















+












-
-
-

+

+
+
-
+
+










-
-
-
-
-
-
-
-
-







        this.nEntries = this.lFlexion.length;
        this.nAddedEntries = 0;
        this.nDeletedEntries = 0;
    },

    save: function () {
        oWidgets.hideElement("save_button");
        let lEntry = [];
        for (let e of this.lFlexion) {
            if (e !== null) {
                lEntry.push(e);
            }
        }
        let sDate = this._getDate();
        browser.storage.local.set({ "oLexicon": {"lEntry": lEntry, "sDate": sDate} });
        this.lFlexion = lEntry;
        oBinaryDict.build(lEntry);
        this.lFlexion = this.lFlexion.filter((e) => e !== null);
        oBinaryDict.build(this.lFlexion);
        this.resetModif();
        oWidgets.displayTable(this.lFlexion);
        oWidgets.updateData();
        oWidgets.setDictData(lEntry.length, sDate);
        oWidgets.setDictData(this.lFlexion.length, this._getDate());
    },

    _getDate: function () {
        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");
        return `${oDate.getFullYear()}-${sMonth}-${sDay}, ${sHours}:${sMinutes}`;
    }
}


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")) {
            this.oJSON = oResult.oDictionary;
            oWidgets.showElement("export_button");
        } else {
            oWidgets.hideElement("export_button");
            return;
        }
        this.oJSON = oResult.oDictionary;
        this.oIBDAWG = new IBDAWG(this.oJSON);
        //oLexicon.set();
        oLexicon.set([oIBDAWG.select()]);
        oWidgets.showElement("export_button");
    },

    build: function (lEntry) {
        oWidgets.showElement("build_progress");
        let xProgressNode = document.getElementById("build_progress");
        let oDAWG = new DAWG(lEntry, "Français - dictionnaire personnel", "S", xProgressNode);
        this.oJSON = oDAWG.createBinary(1);
        this.save();
        oWidgets.hideElement("build_progress");
        oWidgets.showElement("export_button");
        // debug
        for (let e of oDAWG.select()) {
            console.log(e);
        }
        console.log("=======");
        let oIBDAWG = new IBDAWG(this.oJSON);
        for (let e of oIBDAWG.select()) {
            console.log(e);
        }
    },

    save: function () {
        browser.storage.local.set({ "oDictionary": this.oJSON });
    },

    import: function () {