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: fr, trunk
17:21
[fx] update: lexicon editor check-in: 3017914303 user: olr tags: fx, trunk
10:36
[fr] faux positif: x fois par mois check-in: 7a50bf6290 user: olr tags: fr, trunk
Changes

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

   212    212       
   213    213   }
   214    214   
   215    215   #no_elem_line {
   216    216       display: none;
   217    217   }
   218    218   
   219         -#save_button {
          219  +.button_block {
          220  +    margin: 5px 0px;
          221  +    background-color: hsl(210, 10%, 90%);
          222  +    border-radius: 5px;
          223  +    padding: 15px;
          224  +}
          225  +#save_button, #export_button {
   220    226       display: none;
   221    227       float: right;
   222    228       padding: 2px 20px;
   223    229       background-color: hsl(150, 50%, 50%);
   224    230       color: hsl(150, 0%, 100%);
   225    231       border-radius: 3px;
   226    232       cursor: pointer;
          233  +}
          234  +#export_button {
          235  +    display: block;
          236  +    background-color: hsl(210, 50%, 50%);
          237  +    color: hsl(210, 0%, 100%);
          238  +}
          239  +
          240  +#build_progress {
          241  +    display: none;
          242  +    width: 100%;
   227    243   }
   228    244   
   229    245   th {
   230    246       padding: 5px 20px;
   231    247       border-left: 1px solid hsl(210, 10%, 90%);
   232    248       text-align: left;
   233    249   }

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

   263    263                       <div id="buttonline">
   264    264                           <div id="add_to_lexicon">Ajouter au dictionnaire</div>
   265    265                       </div>
   266    266                   </div>
   267    267               </div>
   268    268   
   269    269               <div id="lexicon_page">
   270         -                <div id="save_button">
   271         -                    Enregistrer
   272         -                </div>
          270  +                
   273    271                   <h2>Votre lexique</h2>
          272  +
          273  +                <div class="button_block">
          274  +                    <div id="save_button" class="fright">
          275  +                        Enregistrer
          276  +                    </div>
          277  +                    <h3>Lexique</h3>
          278  +                    <p>Nombre d’entrées ajoutées : <i id="num_added_entries">0</i>.</p>
          279  +                    <p>Nombre d’entrées supprimées : <i id="num_deleted_entries">0</i>.</p>
          280  +                    <p>Nombre d’entrées : <i id="num_entries">0</i>.</p>
          281  +                    <h3>Dictionnaire enregistré</h3>
          282  +                    <p>Dernière sauvegarde : <i id="save_date">néant</i>.</p>
          283  +                    <p>Nombre d’entrées : <i id="num_entries_saved">0</i>.</p>
          284  +                    <p><progress id="build_progress" value="0"></p>
          285  +                    <div id="export_div">
          286  +                        <div id="export_button" class="fright">
          287  +                            Exporter
          288  +                        </div>
          289  +                        <h3>Export</h3>
          290  +                        <p>Export de votre dictionnaire personnel au format JSON.</p>
          291  +                    </div>
          292  +                </div>
   274    293                   
   275         -                <div class="clearer"></div>
   276    294   
   277    295                   <p id="no_elem_line">Aucun élément.</p>
   278    296   
   279    297                   <table id="table">
   280    298                       
   281    299                   </table>
   282    300               </div>
   283    301           </div>
   284    302   
   285    303   
   286    304           <script src="../grammalecte/graphspell/helpers.js"></script>
          305  +        <script src="../grammalecte/graphspell/str_transform.js"></script>
          306  +        <script src="../grammalecte/graphspell/dawg.js"></script>
   287    307           <script src="../grammalecte/fr/conj.js"></script>
   288    308           <script src="lex_conj_data.js"></script>
   289    309           <script src="lex_editor.js"></script>
   290    310       </body>
   291    311       
   292    312   </html>

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

    30     30   
    31     31   
    32     32   document.getElementById("lexicon_button").addEventListener("click", () => { oWidgets.showPage("lexicon"); }, false);
    33     33   document.getElementById("add_word_button").addEventListener("click", () => { oWidgets.showPage("lemma"); }, false);
    34     34   
    35     35   document.getElementById("table").addEventListener("click", (xEvent) => { oWidgets.onTableClick(xEvent); }, false);
    36     36   document.getElementById("save_button").addEventListener("click", () => { oLexicon.save(); }, false);
           37  +document.getElementById("export_button").addEventListener("click", () => { oLexicon.export(); }, false);
    37     38   
    38     39   document.getElementById("editor").addEventListener("click", (xEvent) => { oWidgets.onSelectionClick(xEvent); }, false);
    39     40   document.getElementById("lemma").addEventListener("keyup", () => { oWidgets.onWrite(); }, false);
    40     41   document.getElementById("lemma2").addEventListener("keyup", () => { oWidgets.onWrite2(); }, false);
    41     42   document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlexGen.update(); }, false);
    42     43   document.getElementById("flexion").addEventListener("keyup", () => { oFlexGen.update(); }, false);
    43     44   document.getElementById("tags").addEventListener("keyup", () => { oFlexGen.update(); }, false);
................................................................................
   511    512               this.lFlexion = dResult.lexicon_list;
   512    513           }
   513    514           oWidgets.displayTable(this.lFlexion);
   514    515       },
   515    516   
   516    517       save: function () {
   517    518           oWidgets.hideElement("save_button");
   518         -        let lResult = [];
          519  +        let lEntry = [];
   519    520           for (let e of this.lFlexion) {
   520    521               if (e !== null) {
   521         -                lResult.push(e);
          522  +                lEntry.push(e);
   522    523               }
   523    524           }
   524         -        browser.storage.local.set({ "lexicon_list": lResult });
   525         -        this.lFlexion = lResult;
          525  +        browser.storage.local.set({ "lexicon_list": lEntry });
          526  +        this.lFlexion = lEntry;
   526    527           oWidgets.displayTable(this.lFlexion);
          528  +        this.build();
   527    529       },
   528    530   
   529    531       build: function () {
   530         -        return null;
          532  +        oWidgets.showElement("build_progress");
          533  +        let xProgressNode = document.getElementById("build_progress");
          534  +        let oDAWG = new DAWG(this.lFlexion, "Français - dictionnaire personnel", "S", xProgressNode);
          535  +        let lMorph = oDAWG.morph("finis");
          536  +        console.log(lMorph);
   531    537       },
   532    538   
   533    539       export: function () {
   534    540           let xBlob = new Blob(['{ "app": "grammalecte", "data": ' + JSON.stringify(this.lFlexion) + ' }'], {type: 'application/json'}); 
   535    541           let sURL = URL.createObjectURL(xBlob);
   536    542           browser.downloads.download({ filename: "grammalecte_dictionnaire_personnel.json", url: sURL, saveAs: true });
          543  +    },
          544  +
          545  +    import: function () {
          546  +        // TO DO
   537    547       }
   538    548   }
   539         -
   540    549   
   541    550   oLexicon.load();

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

    25     25           We store suffix/affix codes and tags within the graph after the “real” word.
    26     26           A word is a list of numbers [ c1, c2, c3 . . . cN, iAffix, iTags]
    27     27           Each arc is an index in this.lArcVal, where are stored characters, suffix/affix codes for stemming and tags.
    28     28           Important: As usual, the last node (after ‘iTags’) is tagged final, AND the node after ‘cN’ is ALSO tagged final.
    29     29       */
    30     30   
    31     31       constructor (lEntrySrc, sLangName, cStemming, xProgressBarNode=null) {
    32         -        console.log("===== Direct Acyclic Word Graph - Minimal Acyclic Finite State Automaton =====")
           32  +        console.log("===== Direct Acyclic Word Graph - Minimal Acyclic Finite State Automaton =====");
           33  +        let funcStemmingGen = null;
    33     34           switch (cStemming.toUpperCase()) {
    34     35               case "A":
    35     36                   funcStemmingGen = str_transform.defineAffixCode; break;
    36     37               case "S":
    37     38                   funcStemmingGen = str_transform.defineSuffixCode; break;
    38     39               case "N":
    39     40                   funcStemmingGen = str_transform.noStemming; break;
    40     41               default:
    41     42                   throw "Error. Unknown stemming code: " + cStemming;
    42     43           }
    43     44           
    44     45           let lEntry = [];
    45         -        let lChar = [''],  Char = new Map(),  nChar = 1,  dCharOccur = new Map();
    46         -        let lAff  = [],    Aff  = new Map(),  nAff  = 0,  dAffOccur = new Map();
    47         -        let lTag  = [],    Tag  = new Map(),  nTag  = 0,  dTagOccur = new Map();
           46  +        let lChar = [''],  dChar = new Map(),  nChar = 1,  dCharOccur = new Map();
           47  +        let lAff  = [],    dAff  = new Map(),  nAff  = 0,  dAffOccur = new Map();
           48  +        let lTag  = [],    dTag  = new Map(),  nTag  = 0,  dTagOccur = new Map();
    48     49           let nErr = 0;
    49     50           
    50     51           // read lexicon
    51     52           for (let [sFlex, sStem, sTag] of lEntrySrc) {
    52     53               addWordToCharDict(sFlex);
    53     54               // chars
    54     55               for (let c of sFlex) {
................................................................................
    56     57                       dChar.set(c, nChar);
    57     58                       lChar.push(c);
    58     59                       nChar += 1;
    59     60                   }
    60     61                   dCharOccur.set(c, dCharOccur.gl_get(c, 0) + 1);
    61     62               }
    62     63               // affixes to find stem from flexion
    63         -            sAff = funcStemmingGen(sFlex, sStem)
           64  +            sAff = funcStemmingGen(sFlex, sStem);
    64     65               if (!dAff.get(sAff)) {
    65     66                   dAff.set(sAff, nAff);
    66     67                   lAff.push(sAff);
    67     68                   nAff += 1;
    68     69               }
    69     70               dAffOccur.set(sAff, dCharOccur.gl_get(sAff, 0) + 1);
    70     71               // tags

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

    87     87               helpers.logerror(e);
    88     88           }
    89     89       },
    90     90   
    91     91       showDistance (s1, s2) {
    92     92           console.log(`Distance: ${s1} / ${s2} = ${this.distanceDamerauLevenshtein(s1, s2)})`);
    93     93       },
           94  +
           95  +    // Suffix only
           96  +    defineSuffixCode: function (sFlex, sStem) {
           97  +        /*
           98  +            Returns a string defining how to get stem from flexion
           99  +                "n(sfx)"
          100  +            with n: a char with numeric meaning, "0" = 0, "1" = 1, ... ":" = 10, etc. (See ASCII table.) Says how many letters to strip from flexion.
          101  +                 sfx [optional]: string to add on flexion
          102  +            Examples:
          103  +                "0": strips nothing, adds nothing
          104  +                "1er": strips 1 letter, adds "er"
          105  +                "2": strips 2 letters, adds nothing
          106  +        */
          107  +        if (sFlex == sStem) {
          108  +            return "0";
          109  +        }
          110  +        let jSfx = 0;
          111  +        for (let i = 0;  i < Math.min(sFlex.length, sStem.length);  i++) {
          112  +            if (sFlex[i] !== sStem[i]) {
          113  +                break;
          114  +            }
          115  +            jSfx += 1;
          116  +        }
          117  +        return String.fromCharCode(sFlex.length-jSfx+48) + sStem.slice(jSfx);
          118  +    },
    94    119   
    95    120       getStemFromSuffixCode: function (sFlex, sSfxCode) {
    96    121           // Suffix only
    97    122           if (sSfxCode == "0") {
    98    123               return sFlex;
    99    124           }
   100    125           return sSfxCode[0] == '0' ? sFlex + sSfxCode.slice(1) : sFlex.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1);