Grammalecte  Diff

Differences From Artifact [65b854aa07]:

To Artifact [4723ccb4db]:


26
27
28
29
30
31
32
33

34
35
36
37



38
39
40
41
42
43
44
26
27
28
29
30
31
32

33
34



35
36
37
38
39
40
41
42
43
44







-
+

-
-
-
+
+
+








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("add_word_button").addEventListener("click", () => { oPage.showPage("lemma"); }, 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("lemma").addEventListener("keyup", () => { oPage.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oPage.onWrite2(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("add_to_lexicon").addEventListener("click", () => { oFlex.addToLexicon(); }, false);



/*
    ACTIONS
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96







-
+







        if (document.getElementById(sName)) {
            document.getElementById(sName).style.display = "block";
        }
    },

    clear: function () {
        try {
            document.getElementById("word2").value = "";
            document.getElementById("lemma2").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;
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126







-
+







            document.getElementById("up_v_t").checked = false;
            document.getElementById("up_v_n").checked = false;
            document.getElementById("up_v_p").checked = false;
            document.getElementById("up_v_m").checked = false;
            document.getElementById("up_v_ae").checked = false;
            document.getElementById("up_v_aa").checked = false;
            // autre
            document.getElementById("lemma").value = "";
            document.getElementById("flexion").value = "";
            document.getElementById("tags").value = "";
        }
        catch (e) {
            showError(e);
        }
    },

139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163







-
+









-
+







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

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

    onWrite2: function () {
        if (document.getElementById("word2").value.trim() !== "") {
        if (document.getElementById("lemma2").value.trim() !== "") {
            this.showWord2();
        } else {
            this.hideWord2();
        }
    },

    showWord2: function () {
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
252
253
254
255
256
257
258



259
260

















261
262
263
264
265
266
267


268
269
270

271
272
273

274
275
276
277

278
279
280

281
282
283
284
285
286

287
288
289
290

291
292
293


294
295
296
297
298
299
300
301
302
303
304
305
306

307
308


309
310
311
312
313
314
315
316
317
318
319
320
321



322
323
324
325
326
327
328
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
252
253
254
255
256
257
258
259
260
261


262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283


284
285
286
287

288
289
290

291
292
293
294

295
296
297

298
299
300
301
302
303

304
305
306
307

308
309


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351







-
-
+
+








-
-
+
+


-
-
+
+


-
+


-
-
+
+



-
-
+
+


-
-
+
+


-
+





-
+


-
-
+
+









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





-
-
+
+


-
+


-
+



-
+


-
+





-
+



-
+

-
-
+
+













+

-
+
+













+
+
+







        this.lFlexion.push( [sFlexion, sLemma, sTag] );
    },

    update: function () {
        try {
            this.clear();
            let sGenderTag = "";
            let sWord = document.getElementById("word").value.trim();
            if (sWord.length > 0) {
            let sLemma = document.getElementById("lemma").value.trim();
            if (sLemma.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");
                                this.addFlexion(sLemma, sLemma, sTag+":s");
                                this.addFlexion(sLemma+"s", sLemma, sTag+":p");
                                break;
                            case "x":
                                this.addFlexion(sWord, sWord, sTag+":s");
                                this.addFlexion(sWord+"x", sWord, sTag+":p");
                                this.addFlexion(sLemma, sLemma, sTag+":s");
                                this.addFlexion(sLemma+"x", sLemma, sTag+":p");
                                break;
                            case "i":
                                this.addFlexion(sWord, sWord, sTag+":i");
                                this.addFlexion(sLemma, sLemma, sTag+":i");
                                break;
                        }
                        let sWord2 = document.getElementById("word2").value.trim();
                        if (sWord2.length > 0  &&  this.getRadioValue("POS2")  &&  this.getRadioValue("genre2")) {
                        let sLemma2 = document.getElementById("lemma2").value.trim();
                        if (sLemma2.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");
                                    this.addFlexion(sLemma2, sLemma, sTag2+":s");
                                    this.addFlexion(sLemma2+"s", sLemma, sTag2+":p");
                                    break;
                                case "x":
                                    this.addFlexion(sWord2, sWord, sTag2+":s");
                                    this.addFlexion(sWord2+"x", sWord, sTag2+":p");
                                    this.addFlexion(sLemma2, sLemma, sTag2+":s");
                                    this.addFlexion(sLemma2+"x", sLemma, sTag2+":p");
                                    break;
                                case "i":
                                    this.addFlexion(sWord2, sWord, sTag2+":i");
                                    this.addFlexion(sLemma2, sLemma, sTag2+":i");
                                    break;
                            }
                        }
                        break;
                    case "V": {
                        if (!sWord.endsWith("er") && !sWord.endsWith("ir")) {
                        if (!sLemma.endsWith("er") && !sLemma.endsWith("ir")) {
                            break;
                        }
                        sWord = sWord.toLowerCase();
                        let c_g = (sWord.endsWith("er")) ? "1" : "2";
                        sLemma = sLemma.toLowerCase();
                        let c_g = (sLemma.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("____")) {
                            let sVerbPattern = document.getElementById("conj_rules_like").value.trim();
                            if (sVerbPattern.length == 0) {
                                // tables de conjugaison du 1er et du 2e groupe
                            for (let [nCut, sAdd, sFlexTags] of this._getConjRule(sWord)) {
                                this.addFlexion(sWord.slice(0,-nCut)+sAdd, sWord, ":V" + c_g + "_" + sVerbTag+sFlexTags);
                                for (let [nCut, sAdd, sFlexTags, sPattern] of this._getConjRule(sLemma)) {
                                    if (!sPattern || RegExp(sPattern).test(sLemma)) {
                                        this.addFlexion(sLemma.slice(0,-nCut)+sAdd, sLemma, ":V" + c_g + "_" + sVerbTag + sFlexTags);
                                    }
                                }
                            } else {
                                // utilisation du conjugueur
                                let oVerb = new Verb(sLemma, sVerbPattern);
                                for (let [sTag1, dFlex] of oVerb.dConj.entries()) {
                                    if (sTag1 !== ":Q") {
                                        for (let [sTag2, sConj] of dFlex.entries()) {
                                            if (sTag2.startsWith(":") && sConj !== "") {
                                                this.addFlexion(sConj, sLemma, ":V" + c_g + "_" + sVerbTag + sTag1 + sTag2);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                    case "W":
                        sWord = sWord.toLowerCase();
                        this.addFlexion(sWord, sWord, ":W");
                        sLemma = sLemma.toLowerCase();
                        this.addFlexion(sLemma, sLemma, ":W");
                        break;
                    case "M1":
                        sWord = sWord.slice(0,1).toUpperCase() + sWord.slice(1);
                        sLemma = sLemma.slice(0,1).toUpperCase() + sLemma.slice(1);
                        sGenderTag = this.getRadioValue("genre_m1");
                        if (sGenderTag) {
                            this.addFlexion(sWord, sWord, ":M1"+sGenderTag+":i");
                            this.addFlexion(sLemma, sLemma, ":M1"+sGenderTag+":i");
                        }
                        break;
                    case "M2":
                        sWord = sWord.slice(0,1).toUpperCase() + sWord.slice(1);
                        sLemma = sLemma.slice(0,1).toUpperCase() + sLemma.slice(1);
                        sGenderTag = this.getRadioValue("genre_m2");
                        if (sGenderTag) {
                            this.addFlexion(sWord, sWord, ":M2"+sGenderTag+":i");
                            this.addFlexion(sLemma, sLemma, ":M2"+sGenderTag+":i");
                        }
                        break;
                    case "MP":
                        sGenderTag = this.getRadioValue("genre_mp");
                        if (sGenderTag) {
                            this.addFlexion(sWord, sWord, ":MP"+sGenderTag+":i");
                            this.addFlexion(sLemma, sLemma, ":MP"+sGenderTag+":i");
                        }
                        break;
                    case "X":
                        let sLemma = document.getElementById("lemma").value.trim();
                        let sFlexion = document.getElementById("flexion").value.trim();
                        let sTags = document.getElementById("tags").value.trim();
                        if (sLemma.length > 0 && sTags.startsWith(":")) {
                            this.addFlexion(sWord, sLemma, sTags);
                        if (sFlexion.length > 0 && sTags.startsWith(":")) {
                            this.addFlexion(sFlexion, sLemma, sTags);
                        }
                        break;
                }
            }
            this.show();
        }
        catch (e) {
            showError(e);
        }
    },

    _getConjRule: function (sVerb) {
        if (sVerb.endsWith("ir")) {
            // deuxième groupe
            return oConj["V2"];
        } else {
        } else if (sVerb.endsWith("er")) {
            // premier groupe
            if (sVerb.slice(-5) in oConj["V1"]) {
                return oConj["V1"][sVerb.slice(-5)];
            }
            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)];
            }
            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] ];
        }
    },

    getRadioValue: function (sName) {
        if (document.querySelector('input[name="' + sName + '"]:checked')) {
            return document.querySelector('input[name="' + sName + '"]:checked').value;
        }
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







-
+







        }
    },

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