semantics_examples.js
4.09 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
var examples = []; // list of all examples connected to lemma
var lexical_unit_examples = []; // lexical_unit_examples[lu.id] = list of examples connected to lexical unit lu
var schema_examples = []; // lexical_unit_examples["schema_" + schema.id] = list of examples connected to schema
var displayed_examples = [];
function memorizeExamples(examples_data, hard) {
var examples_old = examples;
examples = examples_data;
if (!hard) {
var i, j;
for (i = 0; i < examples_old.length; i++) {
var id = examples_old[i].id;
var meanings = examples_old[i].meanings;
for(j = 0; j < examples.length; j++) {
if (examples[j].id == id) {
examples[j].meanings = meanings;
break;
}
}
}
}
var i;
for (i = 0; i < lexical_units.length; i++) {
lexical_unit_examples[lexical_units[i].id] = [];
}
for (i = 0; i < examples.length; i++) {
var id = examples[i].id;
var schema = examples[i].schema;
schema_examples[schema].push(id);
for (j = 0; j < examples[i].meanings.length; j++) {
lexical_unit_examples[examples[i].meanings[j]].push("" + id);
}
}
}
function setExamples(luid, new_examples) {
var j;
for(j = 0; j < new_examples.length; j++) {
if (lexical_unit_examples[luid].indexOf(new_examples[j]) == -1) {
var i = indexOfId(examples, new_examples[j]);
examples[i].meanings.push(parseInt(luid));
units_operations.push({operation: 'add_example', unit: luid, example: new_examples[j]});
}
}
for(j = 0; j < lexical_unit_examples[luid].length; j++) {
if (new_examples.indexOf(lexical_unit_examples[luid][j]) == -1) {
var i = indexOfId(examples, lexical_unit_examples[luid][j]);
examples[i].meanings.splice(indexOfId(examples[i].meanings, luid), 1);
units_operations.push({operation: 'remove_example', unit: luid, example: lexical_unit_examples[luid][j]});
}
}
lexical_unit_examples[luid] = new_examples
}
function hasExample(luid) {
for (i = 0; i < examples.length; i++){
if (examples[i].meanings.length == 1) {
if (examples[i].meanings[0] == luid) {
return true;
}
}
}
return false;
}
// get examples connected to lexical unit as table formatted html form
function getExamples(luid) {
$.ajax({
dataType: "json",
url: ajax_examples,
data: {lemma_id: lemma_id},
success: function(data){ memorizeExamples(data.examples, false) },
async: false
});
var table = '<table id="nkjp_table" class="ChangeControlTable">';
table += '<tr>';
table += '<td class="ColumnHeader">Dotyczy:</td>';
table += '<td class="ColumnHeader">Identyfikator:</td>';
table += '<td class="ColumnHeader">Przykład:</td>';
table += '<td class="ColumnHeader">Źródło:</td>';
table += '<td class="ColumnHeader">Ocena:</td>';
table += '</tr>';
var i;
for (i = 0; i < examples.length; i++){
table += '<tr id="nkjp_' + examples.id + '" class="ExampleRow">';
if (examples[i].meanings.length == 1) {
if (examples[i].meanings[0] == luid) {
table += '<td class="ColumnHeader"><input type="checkbox" name="connect" value="' + examples[i].id + '" checked></td>';
} else {
table += '<td class="ColumnHeader">' + getLexicalUnit(examples[i].meanings[0]) + '</td>';
}
} else {
table += '<td class="ColumnHeader"><input type="checkbox" name="connect" value="' + examples[i].id + '"></td>';
}
table += '<td class="ColumnHeader">' + examples[i].id + '</td>';
table += '<td class="ColumnHeader">' + examples[i].sentence + '</td>';
table += '<td class="ColumnHeader">' + examples[i].source + '</td>';
table += '<td class="ColumnHeader">' + examples[i].opinion + '</td>';
table += '</tr>';
}
table += '</table>';
return table;
}