semantics_lexical_units.js
14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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
250
251
252
253
254
255
256
257
258
259
260
261
262
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
var lexical_units = []; // list of all lexical_units
var base; // base form of lexical unit
var free_luid = -1; // these ids will be temporarely given to new lexical units
var free_sense; // what sense should be given to new lexical unit
var lexical_units_frames = [];
var lexical_units_num = [];
var part_of_speech;
// store lexical units from database
function memorizeLexicalUnits(input_lexical_units) {
lexical_units = input_lexical_units;
var i;
for (i = 0; i < lexical_units.length; i++) {
lexical_unit_examples[lexical_units[i].id] = [];
}
}
function basicLexicalUnitsData(info){
base = info.base;
free_sense = info.sense;
part_of_speech = info.pos;
}
// create new lexical_unit
function createLexicalUnit(refl, glossa, relation, to) {
if (((typeof to) == 'undefined') && (relation != 2)) {
return
}
var refl_text = "";
if (refl == "true") {
refl_text = " się";
} else {
refl_text = "";
}
var lu = {base: base + refl_text, glossa: "" + glossa, definition: "", id: free_luid, luid: -1, refl: refl, glossa: glossa, pos: part_of_speech, sense: free_sense, relation: relation, to: to, location: ""};
var operation = {operation: 'add_unit', unit:lu};
lexical_units.push(lu);
lexical_unit_examples[free_luid] = []
units_operations.push(operation);
free_sense = String.fromCharCode(free_sense.charCodeAt(0) + 1);
free_luid -= 1;
}
// is unit with given luid from PlWN?
function isPlWNUnit(luid) {
var i = indexOfId(lexical_units, luid);
if (i >= 0) {
if (lexical_units[i].luid == -1) {
return false;
}
}
return true;
}
// remove lexical unit (that is not from PlWN)
function destroyLexicalUnit(luid) {
var i = indexOfId(lexical_units, luid);
if (i >= 0) {
if (lexical_units[i].luid == -1) {
lexical_units.splice(i, 1);
var j;
for (j = 0; j < lexical_unit_examples[luid].length; j++) {
var k = indexOfId(examples, lexical_unit_examples[luid][j]);
if (k >= 0) {
examples[k].meanings = [];
}
}
lexical_unit_examples[luid] = [];
var operation = {operation: 'remove_unit', luid: luid};
units_operations.push(operation);
}
}
}
function getGlossa(luid) {
var lu = lexical_units[indexOfId(lexical_units, luid)];
return lu.glossa;
}
// set glossa for unit with given luid
function setGlossa(luid, glossa) {
var i = indexOfId(lexical_units, luid);
lexical_units[i].glossa = "" + glossa;
units_operations.push({operation: 'set_glossa', unit: luid, value: lexical_units[i].glossa});
}
function getLocation(luid) {
if (isPLWNUnit(luid)){
var lu = lexical_units[indexOfId(lexical_units, luid)];
return lu.location;
} else {
return "";
}
}
// save all changes to meanings (lexical units)
function saveMeanings() {
$.ajax({
type: "POST",
dataType: "json",
url: ajax_update_meanings,
data: {"operations": JSON.stringify(units_operations),
"lemma_id": lemma_id},
success: function(data){
memorizeLexicalUnits(data.lexical_units);
basicLexicalUnitsData(data.informations);
updateExamplesConnections();
},
async: false
});
$.ajax({
dataType: "json",
url: ajax_examples,
data: {"lemma_id": lemma_id},
success: function(data){
memorizeExamples(data.examples, true);
},
async: false
});
$.ajax({
dataType: "json",
url: ajax_frames,
data: {"lemma_id": lemma_id},
success: function(data){
getFrames(data.frames_display);
displayFrames();
memorizeConnections(data.connections.connected, data.connections.connected_reverse);
alternationCounts(data.alternations);
$("#semantic-frames-count").empty();
$("#semantic-frames-count").append(data.frames_count);
},
async: false
});
units_operations = [];
}
// get all meanings as radio-button form named "meaning"
function getMeanings() {
var display = "";
var i;
for (i = 0; i < lexical_units.length; i++) {
display += "<input type = \"radio\" name = \"meaning\" value = \"" + lexical_units[i].id + "\">" + lexical_units[i].base + "-" + lexical_units[i].sense + "<div id=\"glossa_" + lexical_units[i].id + "\">" + " <i>" + lexical_units[i].definition + "</i>";
if (lexical_units[i].definition != "") {
display += "<br>";
}
display += lexical_units[i].glossa
if (lexical_units[i].glossa != "") {
display += "<br>";
}
display += lexical_units[i].location + "</div>";
}
return display;
}
// get all meanings as checkbox-type form, meanings with frame are disabled
function getMeaningsSelection() {
var display = "";
var i;
for (i = 0; i < lexical_units.length; i++) {
display += "<input type = \"checkbox\" name = \"meaning\" value = \"" + lexical_units[i].id + "\""
var j;
for (j = 0; j < lexical_units_num.length; j++) {
if (indexOfId(lexical_units_num[j], lexical_units[i].id) != -1) {
display += " disabled = \"True\""
}
}
display += ">" + lexical_units[i].base + "-" + lexical_units[i].sense + "<br><div id=\"glossa_" + lexical_units[i].id + "\">" + lexical_units[i].glossa + "</div>"
}
return display;
}
// get all meanings as checkbox-type form, meanings with frame are disabled
function getMeaningsSelectionForFrame(frame_id) {
var display = "";
var id = "" + frame_id;
// podstawowe znaczenia
display += "<div>";
var i;
for (i = 0; i < lexical_units.length; i++) {
display += "<input type = \"checkbox\" name = \"meaning\" value = \"" + lexical_units[i].id + "\""
var j;
for (j = 0; j < lexical_units_num.length; j++) {
if
(indexOfId(lexical_units_num[j], lexical_units[i].id) != -1) {
if (lexical_units_frames[j].indexOf(id) != -1) {
display += " checked";
} else {
display += " disabled = \"True\"";
}
}
}
display += ">" + lexical_units[i].base + "-" + lexical_units[i].sense + "<br><div id=\"glossa_" + lexical_units[i].id + "\">" + lexical_units[i].glossa + "</div>"
}
display += "</div>";
// znaczenia wielowyrazowe
var lexicalisation = [];
display += "<br/>";
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 < rows.length; j++) {
var options = [];
var vrb = [];
var pre = [];
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++) {
var proper = schemas_content[sch].display.arguments[0][k].csv_id + "alt_" + sid_alt[1] + "_";
if (connected[lem].indexOf(proper) != -1) {
if (schemas_content[sch].display.arguments[0][k].vrb != null &&
schemas_content[sch].display.arguments[0][k].vrb.length > 0) {
pre = pre.concat(schemas_content[sch].display.arguments[0][k].lex);
vrb = schemas_content[sch].display.arguments[0][k].vrb;
} else {
options.push(schemas_content[sch].display.arguments[0][k].lex);
}
}
}
if (vrb.length == 0) {
var lex = {lemma: [base], pre: pre, args: options};
if (hasRefl(sch)) {
if (isNeg(sch)) {
lex.lemma = ["nie " + base + " się"];
} else {
lex.lemma = [base + " się"];
}
} else {
if (isNeg(sch)) {
lex.lemma = ["nie " + base];
} else {
lex.lemma = [base];
}
}
lexicalisation.push(lex);
} else {
var lex = {lemma: vrb, pre: pre, args: options};
if (hasRefl(sch)) {
var l = [];
var k;
for (k=0; k < vrb.length; k++) {
l.push(vrb[k] + " się");
}
lex.lemma = l;
}
lexicalisation.push(lex);
}
}
}
display += getFormForLexicalisation(lexicalisation);
display += "</div>";
return display;
}
function getFormForLexicalisation(lexicalisation) {
var options = [];
var i;
for (i = 0; i < lexicalisation.length; i++) {
var perms = permute(lexicalisation[i].args);
var j;
for (j = 0; j < perms.length; j++) {
options.push({lemma: lexicalisation[i].lemma, pre: lexicalisation[i].pre, post: cartesian(perms[j])});
}
}
result = lexicalisationForm(options);
return result;
}
function permute(list) {
var i;
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;
}
}
function cartesian(llist) {
if (llist.length == 0) {
return [[]];
}
var result = [];
var shortllist = llist.slice();
shortllist.splice(shortllist.length - 1, 1);
var carts = cartesian(shortllist);
var i;
for (i = 0; i < llist[llist.length - 1].length; i++) {
var tail = llist[llist.length - 1][i];
var heads = carts.slice();
var j;
for (j = 0; j < heads.length; j++) {
var tmp = heads[j].slice();
tmp.push(tail);
result.push(tmp);
}
}
return result;
}
function lexicalisationForm(lemmalist) {
var i;
var options = [];
for (k = 0; k < lemmalist.length; k++) {
var lemma = lemmalist[k].lemma;
var pre = lemmalist[k].pre;
var tokenised = lemmalist[k].post;
var list;
if (pre.length == 0) {
list = noSubjUnits(lemma, tokenised);
} else {
list = subjUnits(pre, lemma, tokenised);
}
options = options.concat(list);
}
$.ajax({
type: "POST",
dataType: "json",
url: ajax_get_mwes,
data: {"options": JSON.stringify(options)},
success: function(data){
list = data.mwes;
},
async: false
});
var display = "";
var i, j;
for (i = 0; i < list.length; i++) {
var included = false;
for (j = 0; j < lexical_units.length; j++) {
if (list[i].base == lexical_units[j].base) {
included = true;
}
}
if (!included) {
display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + list[i].base + list[i].sense + "_" + list[i].id + "_" + list[i].luid + "_" + list[i].sid + "\">" + list[i].base + list[i].sense + "<br\>";
}
}
return display;
}
function noSubjUnits(lemmata, dependants) {
var result = [];
var i, j;
for (i = 0; i < lemmata.length; i++) {
if (dependants.length == 0) {
result.push(lemmata[i]);
} else {
for (j = 0; j < dependants.length; j++) {
if (dependants[j].length > 0) {
result.push(lemmata[i] + " " + dependants[j].join(" "));
} else {
result.push(lemmata[i]);
}
}
}
}
return result;
}
function subjUnits(pre, lemmata, dependants) {
var result = [];
var i, j;
var temp = noSubjUnits(lemmata, dependants);
i = decapitate(dependants);
var pre2 = i.heads;
var temp2 = noSubjUnits(lemmata, i.bodies);
for (i = 0; i < pre.length; i++) {
for (j = 0; j < temp.length; j++) {
result.push(pre[i] + " " + temp[j]);
}
for (j = 0; j < pre2.length; j++) {
result.push(pre[i] + " " + pre2[j] + " " + temp2[j]);
}
}
return result;
}
function decapitate(llist) {
var heads = [];
var bodies = [];
var i;
for (i = 0; i < llist.length; i++) {
if (llist[i].length > 0) {
var body = llist[i].slice();
var head = body[0];
body.splice(0, 1);
heads.push(head);
bodies.push(body);
}
}
return {heads: heads, bodies: bodies};
}
// get readable form of lexical unit
function getLexicalUnit(luid) {
var i = indexOfId(lexical_units, luid);
// alert("" + luid + " -> " + i);
var lu = lexical_units[i];
return lu.base + '-' + lu.sense;
}
function addPhraseologicalUnit(mwe, glossa, relation, to) {
var lu = {base: mwe, glossa: "" + glossa, definition: "", id: free_luid, luid: -1, refl: "false", glossa: glossa, pos: part_of_speech, sense: "A", relation: relation, to: to, location: ""};
var operation = {operation: 'add_unit', unit:lu};
lexical_units.push(lu);
lexical_unit_examples[free_luid] = [];
frames_operations.push(operation);
free_luid -= 1;
return (free_luid + 1);
}
function unlockPhraseologicalUnit(mwe) {
var lu = {base: mwe.lu.split('-')[0], glossa: "", definition: "", id: mwe.id, luid: mwe.luid, refl: false, glossa: "", pos: part_of_speech, sense: mwe.lu.split('-')[1], relation: 2, to: -1, location: ""};
lexical_units.push(lu);
return mwe.id;
}
function addPhraseologicalUnits(frame_id, old_units, old_mwes, new_mwes, glossa, relation, to) {
var i;
var units = old_units.slice();
for (i = 0; i < old_mwes.length; i++) {
units.push(unlockPhraseologicalUnit(old_mwes[i]));
}
for (i = 0; i < new_mwes.length; i++) {
units.push(addPhraseologicalUnit(new_mwes[i], glossa, relation, to));
}
changeUnits(frame_id, 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);
}