diff --git a/semantics/static/js/semantics_core.js b/semantics/static/js/semantics_core.js index cce542f..5b090dc 100644 --- a/semantics/static/js/semantics_core.js +++ b/semantics/static/js/semantics_core.js @@ -20,3 +20,11 @@ function normalizeFormData(data) { } } } + +function onlyUnique (value, index, self) { + return self.indexOf(value) === index; +} + +function unique(list) { + return list.filter( onlyUnique ); +} diff --git a/semantics/static/js/semantics_lexical_units.js b/semantics/static/js/semantics_lexical_units.js index cdb252b..b74a897 100644 --- a/semantics/static/js/semantics_lexical_units.js +++ b/semantics/static/js/semantics_lexical_units.js @@ -199,28 +199,24 @@ function getMeaningsSelectionForFrame(frame_id) { display += "<div>"; if (frame_content[frame_id].lemma.include) { + var rows = getPhraseologicalAlternations(frame_id); var lem = frame_content[frame_id].lemma.csv_class; var j; - for (j = 0; j < connected[lem].length; j++) { + for (j = 0; j < rows.length; j++) { var options = []; - var sch = connected[lem][j].split("pos")[0]; - var pos = connected[lem][j].split("arg")[0]; + sid_alt = rows[j].split('_'); + var sch = "schema_" + sid_alt[0] + "_"; var k; for (k = 0; k < schemas_content[sch].display.arguments[0].length; k++) { - if (schemas_content[sch].display.arguments[0][k].csv_class == pos) { - var l; - for (l = 0; l < schemas_content[sch].display.arguments[0][k].lex.length; l++) { - options.push(schemas_content[sch].display.arguments[0][k].lex[l]); - } + var proper = schemas_content[sch].display.arguments[0][k].csv_id + "alt_" + sid_alt[1] + "_"; + if (connected[lem].indexOf(proper) != -1) { + options.push(schemas_content[sch].display.arguments[0][k].lex); } } - var temp; // TODO: temporal solution for multiple schemata if (hasRefl(sch)) { - temp = [['się'], options] - } else { - temp = [options]; + options.push(['się']); } - lexicalisation.push(temp); + lexicalisation.push(options); } } @@ -241,26 +237,37 @@ function getFormForLexicalisation(lexicalisation) { return result; } -function permutations(llist) { - return llist; -/* if (list.length == 0) { - return [[]]; +function permutations(lllist) { + //return lllist; + if (lllist.length == 0) { + return []; + } else { + var shortlllist = lllist.slice(); + shortlllist.splice(0, 1); + return permute(lllist[0]).concat([[]].concat(permutations(shortlllist))) } +} + +function permute(list) { var i; - var result = []; - for (i = 0; i < list.length; i++) { - var shortlist = list.slice(); - shortlist.splice(i, 1); - var perms = permutations(shortlist); - var j; - for (j = 0; j < perms.length; j++) { - var tmp = perms[j]; - tmp.push(list[i]); - result.push(tmp); - } + if (list.length == 0) { + return [[]]; + } else { + var result = []; + for (i = 0; i < list.length; i++) { + var shortlist = list.slice(); + shortlist.splice(i, 1); + var perms = permute(shortlist); + var j; + for (j = 0; j < perms.length; j++) { + var tmp = perms[j]; + tmp.push(list[i]); + result.push(tmp); + } + } + return result; } - return result; -*/ + } function cartesian(llist) { @@ -279,7 +286,6 @@ function cartesian(llist) { for (j = 0; j < heads.length; j++) { var tmp = heads[j].slice(); tmp.push(tail); - //alert(tmp); result.push(tmp); } } @@ -290,14 +296,18 @@ function lexicalisationForm(tokenised) { var display = ""; var i; for (i = 0; i < tokenised.length; i++) { - var j; - for (j = 0; j < lexical_units.length; j++) { - if (base + " " + tokenised[i].join(" ") == lexical_units[j].base) { - return ""; - } + if (tokenised[i].length == 0) { + display += "<br\>"; + } else { + var j; + for (j = 0; j < lexical_units.length; j++) { + if (base + " " + tokenised[i].join(" ") == lexical_units[j].base) { + return ""; + } + } + display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + base + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?) + display += base + " " + tokenised[i].join(" ") + "<br\>"; } - display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + base + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?) - display += base + " " + tokenised[i].join(" ") + "<br\>"; } return display; } @@ -331,3 +341,17 @@ function addPhraseologicalUnits(frame_id, old_units, mwes, glossa, relation, to) changeUnits(frame_id, old_units.concat(units)); } + +function getPhraseologicalAlternations(frame_id) { + var result = []; + if (frame_content[frame_id].lemma.include) { + var lem = frame_content[frame_id].lemma.csv_class; + var i; + for (i = 0; i < connected[lem].length; i++) { + var ids = connected[lem][i].split('_'); + result.push(ids[1] + "_" + ids[7]) + } + } + return unique(result); +} +