Grammalecte  Diff

Differences From Artifact [b986ace5c1]:

To Artifact [07c481136a]:


1
2
3
4







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


43
44
45
46

47
48

49
50
51
52
53
54
55
// JavaScript

"use strict";









function createNode  (sType, oAttr, oDataset=null) {
    try {
        let xNode = document.createElement(sType);
        Object.assign(xNode, oAttr);
        if (oDataset) {
            Object.assign(xNode.dataset, oDataset);
        }
        return xNode;
    }
    catch (e) {
        showError(e);
    }
}

function showError (e) {
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}


document.getElementById("lexicon_button").addEventListener("click", () => { oPage.showPage("lex"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oPage.showPage("word"); }, false);
document.getElementById("editor").addEventListener("click", (xEvent) => { oPage.onSelectionClick(xEvent); }, false);
document.getElementById("word").addEventListener("keyup", () => { oPage.onWrite(); }, false);
document.getElementById("word2").addEventListener("keyup", () => { oPage.onWrite2(); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("add_to_lexicon").addEventListener("click", () => { oFlex.addToLexicon(); }, false);



/*
    ACTIONS
*/

const oPage = {

    showPage: function (sPage) {


        if (document.getElementById("lexicon_page").style.display == "block") {
            document.getElementById("lexicon_page").style.display = "none";
            document.getElementById("add_word_page").style.display = "block";
        } else {

            document.getElementById("add_word_page").style.display = "none";
            document.getElementById("lexicon_page").style.display = "block";

        }
    },

    showEditor: function () {
        document.getElementById("editor").style.display = "block";
    },





>
>
>
>
>
>
>




















|

















>
>
|
|
|

>
|
|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// JavaScript

"use strict";

// Chrome don’t follow the W3C specification:
// https://browserext.github.io/browserext/
let bChrome = false;
if (typeof(browser) !== "object") {
    var browser = chrome;
    bChrome = true;
}

function createNode  (sType, oAttr, oDataset=null) {
    try {
        let xNode = document.createElement(sType);
        Object.assign(xNode, oAttr);
        if (oDataset) {
            Object.assign(xNode.dataset, oDataset);
        }
        return xNode;
    }
    catch (e) {
        showError(e);
    }
}

function showError (e) {
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}


document.getElementById("lexicon_button").addEventListener("click", () => { oPage.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oPage.showPage("word"); }, false);
document.getElementById("editor").addEventListener("click", (xEvent) => { oPage.onSelectionClick(xEvent); }, false);
document.getElementById("word").addEventListener("keyup", () => { oPage.onWrite(); }, false);
document.getElementById("word2").addEventListener("keyup", () => { oPage.onWrite2(); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("add_to_lexicon").addEventListener("click", () => { oFlex.addToLexicon(); }, false);



/*
    ACTIONS
*/

const oPage = {

    showPage: function (sPage) {
        if (sPage == "lexicon") {
            document.getElementById("add_word_page").style.display = "none";
            document.getElementById("lexicon_page").style.display = "block";
            document.getElementById("lexicon_button").style.backgroundColor = "hsl(210, 80%, 90%)";
            document.getElementById("add_word_button").style.backgroundColor = "hsl(210, 10%, 95%)";
        } else {
            document.getElementById("lexicon_page").style.display = "none";
            document.getElementById("add_word_page").style.display = "block";
            document.getElementById("lexicon_button").style.backgroundColor = "hsl(210, 10%, 95%)";
            document.getElementById("add_word_button").style.backgroundColor = "hsl(210, 80%, 90%)";
        }
    },

    showEditor: function () {
        document.getElementById("editor").style.display = "block";
    },

71
72
73
74
75
76
77


78
79
80
81
82
83
84
        if (document.getElementById(sName)) {
            document.getElementById(sName).style.display = "block";
        }
    },

    clear: function () {
        try {


            // nom, adjectif, noms propres
            for (let xElem of document.getElementsByName("POS")) {
                xElem.checked = false;
            }
            for (let xElem of document.getElementsByName("POS2")) {
                xElem.checked = false;
            }







>
>







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        if (document.getElementById(sName)) {
            document.getElementById(sName).style.display = "block";
        }
    },

    clear: function () {
        try {
            document.getElementById("word2").value = "";
            this.hideWord2();
            // nom, adjectif, noms propres
            for (let xElem of document.getElementsByName("POS")) {
                xElem.checked = false;
            }
            for (let xElem of document.getElementsByName("POS2")) {
                xElem.checked = false;
            }
129
130
131
132
133
134
135

136
137
138
139
140
141
142
        }
    },

    onWrite: function () {
        if (document.getElementById("word").value.trim() !== "") {
            this.showEditor();
        } else {

            this.hideEditor();
            this.hideActions();
        }
    },

    onWrite2: function () {
        if (document.getElementById("word2").value.trim() !== "") {







>







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
        }
    },

    onWrite: function () {
        if (document.getElementById("word").value.trim() !== "") {
            this.showEditor();
        } else {
            this.showSection("section_vide");
            this.hideEditor();
            this.hideActions();
        }
    },

    onWrite2: function () {
        if (document.getElementById("word2").value.trim() !== "") {
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241





242
243

244

245
246
247
248
249
250
251
        try {
            this.clear();
            let sGenderTag = "";
            let sWord = document.getElementById("word").value.trim();
            if (sWord.length > 0) {
                switch (this.cMainTag) {
                    case "N":



                        let sTag = this.getRadioValue("POS") + this.getRadioValue("genre");
                        switch (this.getRadioValue("pluriel")) {
                            case "s":
                                this.addFlexion(sWord, sWord, sTag+":s");
                                this.addFlexion(sWord+"s", sWord, sTag+":p");
                                break;
                            case "x":
                                this.addFlexion(sWord, sWord, sTag+":s");
                                this.addFlexion(sWord+"x", sWord, sTag+":p");
                                break;
                            case "i":
                                this.addFlexion(sWord, sWord, sTag+":i");
                                break;
                        }
                        let sWord2 = document.getElementById("word2").value.trim();
                        if (sWord2.length > 0) {
                            let sTag2 = this.getRadioValue("POS2") + this.getRadioValue("genre2");
                            switch (this.getRadioValue("pluriel2")) {
                                case "s":
                                    this.addFlexion(sWord2, sWord, sTag2+":s");
                                    this.addFlexion(sWord2+"s", sWord, sTag2+":p");
                                    break;
                                case "x":
                                    this.addFlexion(sWord2, sWord, sTag2+":s");
                                    this.addFlexion(sWord2+"x", sWord, sTag2+":p");
                                    break;
                                case "i":
                                    this.addFlexion(sWord2, sWord, sTag2+":i");
                                    break;
                            }
                        }
                        break;
                    case "V":
                        if (!sWord.endsWith("er") && !sWord.endsWith("ir")) {
                            break;
                        }
                        sWord = sWord.toLowerCase();
                        let c_g = (sWord.endsWith("er")) ? "1" : "2";
                        let c_i = (document.getElementById("up_v_i").checked) ? "i" : "_";
                        let c_t = (document.getElementById("up_v_t").checked) ? "t" : "_";
                        let c_n = (document.getElementById("up_v_n").checked) ? "n" : "_";
                        let c_p = (document.getElementById("up_v_p").checked) ? "p" : "_";
                        let c_m = (document.getElementById("up_v_m").checked) ? "m" : "_";
                        let c_ae = (document.getElementById("up_v_ae").checked) ? "e" : "_";
                        let c_aa = (document.getElementById("up_v_aa").checked) ? "a" : "_";
                        let sVerbTag = c_i + c_t + c_n + c_p + c_m + c_ae + c_aa;
                        if (!sVerbTag.endsWith("__") && !sVerbTag.startsWith("____")) {





                            this.addFlexion(sWord, sWord, ":V" + c_g + "_" + sVerbTag);
                        }

                        break;

                    case "W":
                        sWord = sWord.toLowerCase();
                        this.addFlexion(sWord, sWord, ":W");
                        break;
                    case "M1":
                        sWord = sWord.slice(0,1).toUpperCase() + sWord.slice(1);
                        sGenderTag = this.getRadioValue("genre_m1");







>
>
>















|
















|














>
>
>
>
>
|
|
>

>







202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
        try {
            this.clear();
            let sGenderTag = "";
            let sWord = document.getElementById("word").value.trim();
            if (sWord.length > 0) {
                switch (this.cMainTag) {
                    case "N":
                        if (!this.getRadioValue("POS") || !this.getRadioValue("genre")) {
                            break;
                        }
                        let sTag = this.getRadioValue("POS") + this.getRadioValue("genre");
                        switch (this.getRadioValue("pluriel")) {
                            case "s":
                                this.addFlexion(sWord, sWord, sTag+":s");
                                this.addFlexion(sWord+"s", sWord, sTag+":p");
                                break;
                            case "x":
                                this.addFlexion(sWord, sWord, sTag+":s");
                                this.addFlexion(sWord+"x", sWord, sTag+":p");
                                break;
                            case "i":
                                this.addFlexion(sWord, sWord, sTag+":i");
                                break;
                        }
                        let sWord2 = document.getElementById("word2").value.trim();
                        if (sWord2.length > 0  &&  this.getRadioValue("POS2")  &&  this.getRadioValue("genre2")) {
                            let sTag2 = this.getRadioValue("POS2") + this.getRadioValue("genre2");
                            switch (this.getRadioValue("pluriel2")) {
                                case "s":
                                    this.addFlexion(sWord2, sWord, sTag2+":s");
                                    this.addFlexion(sWord2+"s", sWord, sTag2+":p");
                                    break;
                                case "x":
                                    this.addFlexion(sWord2, sWord, sTag2+":s");
                                    this.addFlexion(sWord2+"x", sWord, sTag2+":p");
                                    break;
                                case "i":
                                    this.addFlexion(sWord2, sWord, sTag2+":i");
                                    break;
                            }
                        }
                        break;
                    case "V": {
                        if (!sWord.endsWith("er") && !sWord.endsWith("ir")) {
                            break;
                        }
                        sWord = sWord.toLowerCase();
                        let c_g = (sWord.endsWith("er")) ? "1" : "2";
                        let c_i = (document.getElementById("up_v_i").checked) ? "i" : "_";
                        let c_t = (document.getElementById("up_v_t").checked) ? "t" : "_";
                        let c_n = (document.getElementById("up_v_n").checked) ? "n" : "_";
                        let c_p = (document.getElementById("up_v_p").checked) ? "p" : "_";
                        let c_m = (document.getElementById("up_v_m").checked) ? "m" : "_";
                        let c_ae = (document.getElementById("up_v_ae").checked) ? "e" : "_";
                        let c_aa = (document.getElementById("up_v_aa").checked) ? "a" : "_";
                        let sVerbTag = c_i + c_t + c_n + c_p + c_m + c_ae + c_aa;
                        if (!sVerbTag.endsWith("__") && !sVerbTag.startsWith("____")) {
                            if (sWord.endsWith("ir")) {
                                for (let [nCut, sAdd, sFlexTags] of oConj["V2"]) {
                                    this.addFlexion(sWord.slice(0,-nCut)+sAdd, sWord, ":V" + c_g + "_" + sVerbTag+sFlexTags);
                                }
                            } else {
                                this.addFlexion(sWord, sWord, ":V" + c_g + "_" + sVerbTag+":Y");
                            }
                        }
                        break;
                    }
                    case "W":
                        sWord = sWord.toLowerCase();
                        this.addFlexion(sWord, sWord, ":W");
                        break;
                    case "M1":
                        sWord = sWord.slice(0,1).toUpperCase() + sWord.slice(1);
                        sGenderTag = this.getRadioValue("genre_m1");
302
303
304
305
306
307
308






309
310
311
312
313
314
315
        }
    },

    addToLexicon: function () {
        try {
            oLexicon.addFlexions(this.lFlexion);
            oLexicon.save();






        }
        catch (e) {
            showError(e);
        }
    }
}








>
>
>
>
>
>







326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
        }
    },

    addToLexicon: function () {
        try {
            oLexicon.addFlexions(this.lFlexion);
            oLexicon.save();
            document.getElementById("word").value = "";
            oPage.showSection("section_vide");
            oPage.hideEditor();
            oPage.hideActions();
            oPage.clear();
            this.clear();
        }
        catch (e) {
            showError(e);
        }
    }
}

332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347


348
349
350
351



352









353
354
355
356
357
358
359
            return;
        }
        let xPromise = browser.storage.local.get("lexicon_list");
        xPromise.then(this._setList, showError);
    },

    _setList: function (dResult) {
        console.log("LOAD");
        if (dResult.hasOwnProperty("lexicon_list")) {
            this.lFlexion = dResult.lexicon_list;
        }
    },

    display: function () {

        let xTable = document.getElementById("table");
        let n = 0;


        for (let [sFlexion, sLemma, sTags] of this.lFlexion) {
            xTable.appendChild(this._createRowNode(n, sFlexion, sLemma, sTags));
            n += 1;
        }



    },










    _createRowNode: function (n, sFlexion, sLemma, sTags) {
        let xRowNode = createNode("tr", { id: "row_"+n });
        xRowNode.appendChild(createNode("td", { textContent: n }));
        xRowNode.appendChild(createNode("td", { textContent: sFlexion }));
        xRowNode.appendChild(createNode("td", { textContent: sLemma }));
        xRowNode.appendChild(createNode("td", { textContent: sTags }));







<






>


>
>
|
|
|
|
>
>
>

>
>
>
>
>
>
>
>
>







362
363
364
365
366
367
368

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
            return;
        }
        let xPromise = browser.storage.local.get("lexicon_list");
        xPromise.then(this._setList, showError);
    },

    _setList: function (dResult) {

        if (dResult.hasOwnProperty("lexicon_list")) {
            this.lFlexion = dResult.lexicon_list;
        }
    },

    display: function () {
        this.clearTable();
        let xTable = document.getElementById("table");
        let n = 0;
        if (this.lFlexion.length > 0) {
            xTable.appendChild(this._createTableHeader());
            for (let [sFlexion, sLemma, sTags] of this.lFlexion) {
                xTable.appendChild(this._createRowNode(n, sFlexion, sLemma, sTags));
                n += 1;
            }
        } else {
            xTable.appendChild(createNode("tr", { textContent: "Aucun élément." }));
        }
    },

    _createTableHeader: function () {
        let xRowNode = createNode("tr");
        xRowNode.appendChild(createNode("th", { textContent: "#" }));
        xRowNode.appendChild(createNode("th", { textContent: "Forme fléchie" }));
        xRowNode.appendChild(createNode("th", { textContent: "Lemme" }));
        xRowNode.appendChild(createNode("th", { textContent: "Étiquettes" }));
        return xRowNode;
    },

    _createRowNode: function (n, sFlexion, sLemma, sTags) {
        let xRowNode = createNode("tr", { id: "row_"+n });
        xRowNode.appendChild(createNode("td", { textContent: n }));
        xRowNode.appendChild(createNode("td", { textContent: sFlexion }));
        xRowNode.appendChild(createNode("td", { textContent: sLemma }));
        xRowNode.appendChild(createNode("td", { textContent: sTags }));
372
373
374
375
376
377
378
379
380
381
382
383




























































    },

    build: function () {
        return null;
    },

    export: function () {
        let xBlob = new Blob(['{ "app": "grammalecte", "data": ["énum", "test"] }'], {type: 'application/json'}); 
        let sURL = URL.createObjectURL(xBlob);
        browser.downloads.download({ filename: "grammalecte_personal_dictionary.json", url: sURL, saveAs: true });
    }
}



































































|

|


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
    },

    build: function () {
        return null;
    },

    export: function () {
        let xBlob = new Blob(['{ "app": "grammalecte", "data": ' + JSON.stringify(this.lFlexion) + ' }'], {type: 'application/json'}); 
        let sURL = URL.createObjectURL(xBlob);
        browser.downloads.download({ filename: "grammalecte_dictionnaire_personnel.json", url: sURL, saveAs: true });
    }
}


oLexicon.load();
oLexicon.display();


/*
    DATA
*/

const oConj = {
    // deuxième groupe (le seul groupe régulier)
    "V2": [
        [2,     "ir",           ":Y/*"],
        [2,     "issant",       ":P/*"],
        [2,     "is",           ":Ip:Is:1s:2s/*"],
        [2,     "it",           ":Ip:Is:3s/*"],
        [2,     "issons",       ":Ip:1p/*"],
        [2,     "issez",        ":Ip:2p/*"],
        [2,     "issent",       ":Ip:Sp:Sq:3p/*"],
        [2,     "issais",       ":Iq:1s:2s/*"],
        [2,     "issait",       ":Iq:3s/*"],
        [2,     "issions",      ":Iq:Sp:Sq:1p/*"],
        [2,     "issiez",       ":Iq:Sp:Sq:2p/*"],
        [2,     "issaient",     ":Iq:3p/*"],
        [2,     "îmes",         ":Is:1p/*"],
        [2,     "îtes",         ":Is:2p/*"],
        [2,     "irent",        ":Is:3p!/*"],
        [2,     "irai",         ":If:1s/*"],
        [2,     "iras",         ":If:2s/*"],
        [2,     "ira",          ":If:3s/*"],
        [2,     "irons",        ":If:1p/*"],
        [2,     "irez",         ":If:2p/*"],
        [2,     "iront",        ":If:3p!/*"],
        [2,     "irais",        ":K:1s:2s/*"],
        [2,     "irait",        ":K:3s/*"],
        [2,     "irions",       ":K:1p/*"],
        [2,     "iriez",        ":K:2p/*"],
        [2,     "iraient",      ":K:3p/*"],
        [2,     "isse",         ":Sp:Sq:1s/*"],
        [2,     "isses",        ":Sp:Sq:2s/*"],
        [2,     "isse",         ":Sp:3s/*"],
        [2,     "ît",           ":Sq:3s/*"],
        [2,     "is",           ":E:2s/*"],
        [2,     "issons",       ":E:1p/*"],
        [2,     "issez",        ":E:2p/*"],
    ],
    


    // premier groupe
    "V1": {

    },
    "V1ger": {

    }
};