Grammalecte  Check-in [3017914303]

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: 301791430305d4c6b01e747bad212ff5a344afb444aac399ef15f28e0d448313
User & Date: olr on 2018-02-03 17:21:37
Other Links: manifest | tags
Context
2018-02-03
20:02
[fr] faux positif: avoir été +Vinf check-in: 526eb32d7c user: olr tags: trunk, fr
17:21
[fx] update: lexicon editor check-in: 3017914303 user: olr tags: trunk, fx
10:36
[fr] faux positif: x fois par mois check-in: 7a50bf6290 user: olr tags: trunk, fr
Changes

Modified gc_lang/fr/webext/panel/lex_editor.css from [4856554058] to [d5d2b73a16].

212
213
214
215
216
217
218






219
220
221
222
223
224
225
226










227
228
229
230
231
232
233
    
}

#no_elem_line {
    display: none;
}







#save_button {
    display: none;
    float: right;
    padding: 2px 20px;
    background-color: hsl(150, 50%, 50%);
    color: hsl(150, 0%, 100%);
    border-radius: 3px;
    cursor: pointer;










}

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







>
>
>
>
>
>
|







>
>
>
>
>
>
>
>
>
>







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
    
}

#no_elem_line {
    display: none;
}

.button_block {
    margin: 5px 0px;
    background-color: hsl(210, 10%, 90%);
    border-radius: 5px;
    padding: 15px;
}
#save_button, #export_button {
    display: none;
    float: right;
    padding: 2px 20px;
    background-color: hsl(150, 50%, 50%);
    color: hsl(150, 0%, 100%);
    border-radius: 3px;
    cursor: pointer;
}
#export_button {
    display: block;
    background-color: hsl(210, 50%, 50%);
    color: hsl(210, 0%, 100%);
}

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

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

Modified gc_lang/fr/webext/panel/lex_editor.html from [37748d26f5] to [13b3afd3c6].

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
                    <div id="buttonline">
                        <div id="add_to_lexicon">Ajouter au dictionnaire</div>
                    </div>
                </div>
            </div>

            <div id="lexicon_page">




                <div id="save_button">
                    Enregistrer
                </div>
                <h2>Votre lexique</h2>















                
                <div class="clearer"></div>

                <p id="no_elem_line">Aucun élément.</p>

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


        <script src="../grammalecte/graphspell/helpers.js"></script>


        <script src="../grammalecte/fr/conj.js"></script>
        <script src="lex_conj_data.js"></script>
        <script src="lex_editor.js"></script>
    </body>
    
</html>







>
>
>
>
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<











>
>






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
                    <div id="buttonline">
                        <div id="add_to_lexicon">Ajouter au dictionnaire</div>
                    </div>
                </div>
            </div>

            <div id="lexicon_page">
                
                <h2>Votre lexique</h2>

                <div class="button_block">
                    <div id="save_button" class="fright">
                        Enregistrer
                    </div>
                    <h3>Lexique</h3>
                    <p>Nombre d’entrées ajoutées : <i id="num_added_entries">0</i>.</p>
                    <p>Nombre d’entrées supprimées : <i id="num_deleted_entries">0</i>.</p>
                    <p>Nombre d’entrées : <i id="num_entries">0</i>.</p>
                    <h3>Dictionnaire enregistré</h3>
                    <p>Dernière sauvegarde : <i id="save_date">néant</i>.</p>
                    <p>Nombre d’entrées : <i id="num_entries_saved">0</i>.</p>
                    <p><progress id="build_progress" value="0"></p>
                    <div id="export_div">
                        <div id="export_button" class="fright">
                            Exporter
                        </div>
                        <h3>Export</h3>
                        <p>Export de votre dictionnaire personnel au format JSON.</p>
                    </div>
                </div>
                


                <p id="no_elem_line">Aucun élément.</p>

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


        <script src="../grammalecte/graphspell/helpers.js"></script>
        <script src="../grammalecte/graphspell/str_transform.js"></script>
        <script src="../grammalecte/graphspell/dawg.js"></script>
        <script src="../grammalecte/fr/conj.js"></script>
        <script src="lex_conj_data.js"></script>
        <script src="lex_editor.js"></script>
    </body>
    
</html>

Modified gc_lang/fr/webext/panel/lex_editor.js from [a0448c9bfb] to [6855918a57].

30
31
32
33
34
35
36

37
38
39
40
41
42
43


document.getElementById("lexicon_button").addEventListener("click", () => { oWidgets.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oWidgets.showPage("lemma"); }, false);

document.getElementById("table").addEventListener("click", (xEvent) => { oWidgets.onTableClick(xEvent); }, false);
document.getElementById("save_button").addEventListener("click", () => { oLexicon.save(); }, false);


document.getElementById("editor").addEventListener("click", (xEvent) => { oWidgets.onSelectionClick(xEvent); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oWidgets.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oWidgets.onWrite2(); }, false);
document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlexGen.update(); }, false);







>







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


document.getElementById("lexicon_button").addEventListener("click", () => { oWidgets.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oWidgets.showPage("lemma"); }, false);

document.getElementById("table").addEventListener("click", (xEvent) => { oWidgets.onTableClick(xEvent); }, false);
document.getElementById("save_button").addEventListener("click", () => { oLexicon.save(); }, false);
document.getElementById("export_button").addEventListener("click", () => { oLexicon.export(); }, false);

document.getElementById("editor").addEventListener("click", (xEvent) => { oWidgets.onSelectionClick(xEvent); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oWidgets.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oWidgets.onWrite2(); }, false);
document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlexGen.update(); }, false);
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
            this.lFlexion = dResult.lexicon_list;
        }
        oWidgets.displayTable(this.lFlexion);
    },

    save: function () {
        oWidgets.hideElement("save_button");
        let lResult = [];
        for (let e of this.lFlexion) {
            if (e !== null) {
                lResult.push(e);
            }
        }
        browser.storage.local.set({ "lexicon_list": lResult });
        this.lFlexion = lResult;
        oWidgets.displayTable(this.lFlexion);

    },

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







|


|


|
|

>



|
>
>
>
>






>
|
>
>
|
|


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
550
            this.lFlexion = dResult.lexicon_list;
        }
        oWidgets.displayTable(this.lFlexion);
    },

    save: function () {
        oWidgets.hideElement("save_button");
        let lEntry = [];
        for (let e of this.lFlexion) {
            if (e !== null) {
                lEntry.push(e);
            }
        }
        browser.storage.local.set({ "lexicon_list": lEntry });
        this.lFlexion = lEntry;
        oWidgets.displayTable(this.lFlexion);
        this.build();
    },

    build: function () {
        oWidgets.showElement("build_progress");
        let xProgressNode = document.getElementById("build_progress");
        let oDAWG = new DAWG(this.lFlexion, "Français - dictionnaire personnel", "S", xProgressNode);
        let lMorph = oDAWG.morph("finis");
        console.log(lMorph);
    },

    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 });
    },

    import: function () {
        // TO DO
    }
}

oLexicon.load();

Modified graphspell-js/dawg.js from [cd7995de2e] to [b32ed20eaa].

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
67
68
69
70
        We store suffix/affix codes and tags within the graph after the “real” word.
        A word is a list of numbers [ c1, c2, c3 . . . cN, iAffix, iTags]
        Each arc is an index in this.lArcVal, where are stored characters, suffix/affix codes for stemming and tags.
        Important: As usual, the last node (after ‘iTags’) is tagged final, AND the node after ‘cN’ is ALSO tagged final.
    */

    constructor (lEntrySrc, sLangName, cStemming, xProgressBarNode=null) {
        console.log("===== Direct Acyclic Word Graph - Minimal Acyclic Finite State Automaton =====")

        switch (cStemming.toUpperCase()) {
            case "A":
                funcStemmingGen = str_transform.defineAffixCode; break;
            case "S":
                funcStemmingGen = str_transform.defineSuffixCode; break;
            case "N":
                funcStemmingGen = str_transform.noStemming; break;
            default:
                throw "Error. Unknown stemming code: " + cStemming;
        }
        
        let lEntry = [];
        let lChar = [''],  Char = new Map(),  nChar = 1,  dCharOccur = new Map();
        let lAff  = [],    Aff  = new Map(),  nAff  = 0,  dAffOccur = new Map();
        let lTag  = [],    Tag  = new Map(),  nTag  = 0,  dTagOccur = new Map();
        let nErr = 0;
        
        // read lexicon
        for (let [sFlex, sStem, sTag] of lEntrySrc) {
            addWordToCharDict(sFlex);
            // chars
            for (let c of sFlex) {
                if (!dChar.get(c)) {
                    dChar.set(c, nChar);
                    lChar.push(c);
                    nChar += 1;
                }
                dCharOccur.set(c, dCharOccur.gl_get(c, 0) + 1);
            }
            // affixes to find stem from flexion
            sAff = funcStemmingGen(sFlex, sStem)
            if (!dAff.get(sAff)) {
                dAff.set(sAff, nAff);
                lAff.push(sAff);
                nAff += 1;
            }
            dAffOccur.set(sAff, dCharOccur.gl_get(sAff, 0) + 1);
            // tags







|
>












|
|
|















|







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
67
68
69
70
71
        We store suffix/affix codes and tags within the graph after the “real” word.
        A word is a list of numbers [ c1, c2, c3 . . . cN, iAffix, iTags]
        Each arc is an index in this.lArcVal, where are stored characters, suffix/affix codes for stemming and tags.
        Important: As usual, the last node (after ‘iTags’) is tagged final, AND the node after ‘cN’ is ALSO tagged final.
    */

    constructor (lEntrySrc, sLangName, cStemming, xProgressBarNode=null) {
        console.log("===== Direct Acyclic Word Graph - Minimal Acyclic Finite State Automaton =====");
        let funcStemmingGen = null;
        switch (cStemming.toUpperCase()) {
            case "A":
                funcStemmingGen = str_transform.defineAffixCode; break;
            case "S":
                funcStemmingGen = str_transform.defineSuffixCode; break;
            case "N":
                funcStemmingGen = str_transform.noStemming; break;
            default:
                throw "Error. Unknown stemming code: " + cStemming;
        }
        
        let lEntry = [];
        let lChar = [''],  dChar = new Map(),  nChar = 1,  dCharOccur = new Map();
        let lAff  = [],    dAff  = new Map(),  nAff  = 0,  dAffOccur = new Map();
        let lTag  = [],    dTag  = new Map(),  nTag  = 0,  dTagOccur = new Map();
        let nErr = 0;
        
        // read lexicon
        for (let [sFlex, sStem, sTag] of lEntrySrc) {
            addWordToCharDict(sFlex);
            // chars
            for (let c of sFlex) {
                if (!dChar.get(c)) {
                    dChar.set(c, nChar);
                    lChar.push(c);
                    nChar += 1;
                }
                dCharOccur.set(c, dCharOccur.gl_get(c, 0) + 1);
            }
            // affixes to find stem from flexion
            sAff = funcStemmingGen(sFlex, sStem);
            if (!dAff.get(sAff)) {
                dAff.set(sAff, nAff);
                lAff.push(sAff);
                nAff += 1;
            }
            dAffOccur.set(sAff, dCharOccur.gl_get(sAff, 0) + 1);
            // tags

Modified graphspell-js/str_transform.js from [aaa0b82c6b] to [e440be0f51].

87
88
89
90
91
92
93

























94
95
96
97
98
99
100
            helpers.logerror(e);
        }
    },

    showDistance (s1, s2) {
        console.log(`Distance: ${s1} / ${s2} = ${this.distanceDamerauLevenshtein(s1, s2)})`);
    },


























    getStemFromSuffixCode: function (sFlex, sSfxCode) {
        // Suffix only
        if (sSfxCode == "0") {
            return sFlex;
        }
        return sSfxCode[0] == '0' ? sFlex + sSfxCode.slice(1) : sFlex.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
            helpers.logerror(e);
        }
    },

    showDistance (s1, s2) {
        console.log(`Distance: ${s1} / ${s2} = ${this.distanceDamerauLevenshtein(s1, s2)})`);
    },

    // Suffix only
    defineSuffixCode: function (sFlex, sStem) {
        /*
            Returns a string defining how to get stem from flexion
                "n(sfx)"
            with n: a char with numeric meaning, "0" = 0, "1" = 1, ... ":" = 10, etc. (See ASCII table.) Says how many letters to strip from flexion.
                 sfx [optional]: string to add on flexion
            Examples:
                "0": strips nothing, adds nothing
                "1er": strips 1 letter, adds "er"
                "2": strips 2 letters, adds nothing
        */
        if (sFlex == sStem) {
            return "0";
        }
        let jSfx = 0;
        for (let i = 0;  i < Math.min(sFlex.length, sStem.length);  i++) {
            if (sFlex[i] !== sStem[i]) {
                break;
            }
            jSfx += 1;
        }
        return String.fromCharCode(sFlex.length-jSfx+48) + sStem.slice(jSfx);
    },

    getStemFromSuffixCode: function (sFlex, sSfxCode) {
        // Suffix only
        if (sSfxCode == "0") {
            return sFlex;
        }
        return sSfxCode[0] == '0' ? sFlex + sSfxCode.slice(1) : sFlex.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1);