Index: gc_lang/fr/webext/panel/lex_editor.css ================================================================== --- gc_lang/fr/webext/panel/lex_editor.css +++ gc_lang/fr/webext/panel/lex_editor.css @@ -214,18 +214,34 @@ #no_elem_line { display: none; } -#save_button { +.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%); Index: gc_lang/fr/webext/panel/lex_editor.html ================================================================== --- gc_lang/fr/webext/panel/lex_editor.html +++ gc_lang/fr/webext/panel/lex_editor.html @@ -265,16 +265,34 @@
-
- Enregistrer -
+

Votre lexique

+ +
+
+ Enregistrer +
+

Lexique

+

Nombre d’entrées ajoutées : 0.

+

Nombre d’entrées supprimées : 0.

+

Nombre d’entrées : 0.

+

Dictionnaire enregistré

+

Dernière sauvegarde : néant.

+

Nombre d’entrées : 0.

+

+
+
+ Exporter +
+

Export

+

Export de votre dictionnaire personnel au format JSON.

+
+
-

Aucun élément.

@@ -282,11 +300,13 @@ + + Index: gc_lang/fr/webext/panel/lex_editor.js ================================================================== --- gc_lang/fr/webext/panel/lex_editor.js +++ gc_lang/fr/webext/panel/lex_editor.js @@ -32,10 +32,11 @@ 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); @@ -513,29 +514,37 @@ oWidgets.displayTable(this.lFlexion); }, save: function () { oWidgets.hideElement("save_button"); - let lResult = []; + let lEntry = []; for (let e of this.lFlexion) { if (e !== null) { - lResult.push(e); + lEntry.push(e); } } - browser.storage.local.set({ "lexicon_list": lResult }); - this.lFlexion = lResult; + browser.storage.local.set({ "lexicon_list": lEntry }); + this.lFlexion = lEntry; oWidgets.displayTable(this.lFlexion); + this.build(); }, build: function () { - return null; + 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(); Index: graphspell-js/dawg.js ================================================================== --- graphspell-js/dawg.js +++ graphspell-js/dawg.js @@ -27,11 +27,12 @@ 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 =====") + 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; @@ -40,13 +41,13 @@ 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 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); @@ -58,11 +59,11 @@ nChar += 1; } dCharOccur.set(c, dCharOccur.gl_get(c, 0) + 1); } // affixes to find stem from flexion - sAff = funcStemmingGen(sFlex, sStem) + sAff = funcStemmingGen(sFlex, sStem); if (!dAff.get(sAff)) { dAff.set(sAff, nAff); lAff.push(sAff); nAff += 1; } Index: graphspell-js/str_transform.js ================================================================== --- graphspell-js/str_transform.js +++ graphspell-js/str_transform.js @@ -89,10 +89,35 @@ }, 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;