Commit b82f1028bb6afc4d54ad4cde8c6a0210b9424af2

Authored by Tomasz Bartosiak
1 parent 1eab39ef

Wieloczłonowe frazeologizmy

semantics/static/js/semantics_core.js
@@ -20,3 +20,11 @@ function normalizeFormData(data) { @@ -20,3 +20,11 @@ function normalizeFormData(data) {
20 } 20 }
21 } 21 }
22 } 22 }
  23 +
  24 +function onlyUnique (value, index, self) {
  25 + return self.indexOf(value) === index;
  26 +}
  27 +
  28 +function unique(list) {
  29 + return list.filter( onlyUnique );
  30 +}
semantics/static/js/semantics_lexical_units.js
@@ -199,28 +199,24 @@ function getMeaningsSelectionForFrame(frame_id) { @@ -199,28 +199,24 @@ function getMeaningsSelectionForFrame(frame_id) {
199 display += "<div>"; 199 display += "<div>";
200 200
201 if (frame_content[frame_id].lemma.include) { 201 if (frame_content[frame_id].lemma.include) {
  202 + var rows = getPhraseologicalAlternations(frame_id);
202 var lem = frame_content[frame_id].lemma.csv_class; 203 var lem = frame_content[frame_id].lemma.csv_class;
203 var j; 204 var j;
204 - for (j = 0; j < connected[lem].length; j++) { 205 + for (j = 0; j < rows.length; j++) {
205 var options = []; 206 var options = [];
206 - var sch = connected[lem][j].split("pos")[0];  
207 - var pos = connected[lem][j].split("arg")[0]; 207 + sid_alt = rows[j].split('_');
  208 + var sch = "schema_" + sid_alt[0] + "_";
208 var k; 209 var k;
209 for (k = 0; k < schemas_content[sch].display.arguments[0].length; k++) { 210 for (k = 0; k < schemas_content[sch].display.arguments[0].length; k++) {
210 - if (schemas_content[sch].display.arguments[0][k].csv_class == pos) {  
211 - var l;  
212 - for (l = 0; l < schemas_content[sch].display.arguments[0][k].lex.length; l++) {  
213 - options.push(schemas_content[sch].display.arguments[0][k].lex[l]);  
214 - } 211 + var proper = schemas_content[sch].display.arguments[0][k].csv_id + "alt_" + sid_alt[1] + "_";
  212 + if (connected[lem].indexOf(proper) != -1) {
  213 + options.push(schemas_content[sch].display.arguments[0][k].lex);
215 } 214 }
216 } 215 }
217 - var temp; // TODO: temporal solution for multiple schemata  
218 if (hasRefl(sch)) { 216 if (hasRefl(sch)) {
219 - temp = [['się'], options]  
220 - } else {  
221 - temp = [options]; 217 + options.push(['się']);
222 } 218 }
223 - lexicalisation.push(temp); 219 + lexicalisation.push(options);
224 } 220 }
225 } 221 }
226 222
@@ -241,26 +237,37 @@ function getFormForLexicalisation(lexicalisation) { @@ -241,26 +237,37 @@ function getFormForLexicalisation(lexicalisation) {
241 return result; 237 return result;
242 } 238 }
243 239
244 -function permutations(llist) {  
245 - return llist;  
246 -/* if (list.length == 0) {  
247 - return [[]]; 240 +function permutations(lllist) {
  241 + //return lllist;
  242 + if (lllist.length == 0) {
  243 + return [];
  244 + } else {
  245 + var shortlllist = lllist.slice();
  246 + shortlllist.splice(0, 1);
  247 + return permute(lllist[0]).concat([[]].concat(permutations(shortlllist)))
248 } 248 }
  249 +}
  250 +
  251 +function permute(list) {
249 var i; 252 var i;
250 - var result = [];  
251 - for (i = 0; i < list.length; i++) {  
252 - var shortlist = list.slice();  
253 - shortlist.splice(i, 1);  
254 - var perms = permutations(shortlist);  
255 - var j;  
256 - for (j = 0; j < perms.length; j++) {  
257 - var tmp = perms[j];  
258 - tmp.push(list[i]);  
259 - result.push(tmp);  
260 - } 253 + if (list.length == 0) {
  254 + return [[]];
  255 + } else {
  256 + var result = [];
  257 + for (i = 0; i < list.length; i++) {
  258 + var shortlist = list.slice();
  259 + shortlist.splice(i, 1);
  260 + var perms = permute(shortlist);
  261 + var j;
  262 + for (j = 0; j < perms.length; j++) {
  263 + var tmp = perms[j];
  264 + tmp.push(list[i]);
  265 + result.push(tmp);
  266 + }
  267 + }
  268 + return result;
261 } 269 }
262 - return result;  
263 -*/ 270 +
264 } 271 }
265 272
266 function cartesian(llist) { 273 function cartesian(llist) {
@@ -279,7 +286,6 @@ function cartesian(llist) { @@ -279,7 +286,6 @@ function cartesian(llist) {
279 for (j = 0; j < heads.length; j++) { 286 for (j = 0; j < heads.length; j++) {
280 var tmp = heads[j].slice(); 287 var tmp = heads[j].slice();
281 tmp.push(tail); 288 tmp.push(tail);
282 - //alert(tmp);  
283 result.push(tmp); 289 result.push(tmp);
284 } 290 }
285 } 291 }
@@ -290,14 +296,18 @@ function lexicalisationForm(tokenised) { @@ -290,14 +296,18 @@ function lexicalisationForm(tokenised) {
290 var display = ""; 296 var display = "";
291 var i; 297 var i;
292 for (i = 0; i < tokenised.length; i++) { 298 for (i = 0; i < tokenised.length; i++) {
293 - var j;  
294 - for (j = 0; j < lexical_units.length; j++) {  
295 - if (base + " " + tokenised[i].join(" ") == lexical_units[j].base) {  
296 - return "";  
297 - } 299 + if (tokenised[i].length == 0) {
  300 + display += "<br\>";
  301 + } else {
  302 + var j;
  303 + for (j = 0; j < lexical_units.length; j++) {
  304 + if (base + " " + tokenised[i].join(" ") == lexical_units[j].base) {
  305 + return "";
  306 + }
  307 + }
  308 + display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + base + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?)
  309 + display += base + " " + tokenised[i].join(" ") + "<br\>";
298 } 310 }
299 - display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + base + " " + tokenised[i].join(" ") + "\">"; // TODO: unikalne wartości, wartość => dodanie odpowiedniej jednostki (nazwa jednostki w wartości?)  
300 - display += base + " " + tokenised[i].join(" ") + "<br\>";  
301 } 311 }
302 return display; 312 return display;
303 } 313 }
@@ -331,3 +341,17 @@ function addPhraseologicalUnits(frame_id, old_units, mwes, glossa, relation, to) @@ -331,3 +341,17 @@ function addPhraseologicalUnits(frame_id, old_units, mwes, glossa, relation, to)
331 changeUnits(frame_id, old_units.concat(units)); 341 changeUnits(frame_id, old_units.concat(units));
332 } 342 }
333 343
  344 +
  345 +function getPhraseologicalAlternations(frame_id) {
  346 + var result = [];
  347 + if (frame_content[frame_id].lemma.include) {
  348 + var lem = frame_content[frame_id].lemma.csv_class;
  349 + var i;
  350 + for (i = 0; i < connected[lem].length; i++) {
  351 + var ids = connected[lem][i].split('_');
  352 + result.push(ids[1] + "_" + ids[7])
  353 + }
  354 + }
  355 + return unique(result);
  356 +}
  357 +