semantics_lexical_units.js
5.73 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
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 = [];
// 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;
}
// 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: "czasownik", sense: free_sense, relation: relation, to: to};
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});
}
// save all changes to meanings (lexical units)
function saveMeanings() {
$.ajax({
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
});
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 + " <i>" + lexical_units[i].definition + "</i><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 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;
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>"
}
return display;
}
// 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;
}