semantics_schemas.js
7.71 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
var ranks = {}; // lexical unit based rank of schema
var schemas_content = []; // schemas in html form
var default_order = []; // default order of schemas
var position_arguments = []; // list of all position for given position csv id
var alternation_counts = []; // how many alternatiove versions of connections are there for given frame and schema
function isPositionId(csv_id) {
// not fully tested, only some basic assumptions
// @TODO
if (csv_id.split('_').length == 7) {
return true;
} else {
return false;
}
}
function isArgumentId(csv_id) {
// not fully tested, only some basic assumptions
// @TODO
if (csv_id.split('_').length == 9) {
return true;
} else {
return false;
}
}
function functionCsvId(csv_id) {
return csv_id.split('arg')[0] + 'alt' + csv_id.split('alt')[1]
}
function schemaId(csv_id) {
return parseInt(csv_id.split('_')[1]);
}
function positionId(csv_id) {
return parseInt(csv_id.split('_')[3]);
}
function argument_id(csv_id) {
return parseInt(csv_id.split('_')[5]);
}
function alternationId(csv_id) {
if (isPositionId(csv_id)) {
return parseInt(csv_id.split('_')[5]);
} else {
return parseInt(csv_id.split('_')[7]);
}
}
function alternations(frame_id, schema_id) {
// alert('frame_id ' + frame_id);
// alert('schema_id ' + schema_id)
// alert('alternations ' + alternation_counts[frame_id][schema_id]);
if (typeof(alternation_counts[frame_id]) != 'undefined') {
if (typeof(alternation_counts[frame_id][schema_id]) != 'undefined') {
return alternation_counts[frame_id][schema_id];
}
}
return 1;
}
function duplicateSchema(clickEvent, schema_id) {
clickEvent.cancelBubble=true;
clickEvent.stopPropagation();
var frame_id = highlighted_id;
if (typeof(alternation_counts[frame_id]) != 'undefined') {
if (typeof(alternation_counts[frame_id][schema_id]) != 'undefined') {
alternation_counts[frame_id][schema_id] += 1
} else {
alternation_counts[frame_id][schema_id] = 2
}
} else {
alternation_counts[frame_id] = {schema_id: 2}
}
select(frame_id, arg)
}
function memorizeRanks(schema_ranks){
ranks = schema_ranks;
}
function schemaTable(schema){
var schema_table = '';
schema_table += '<table class="InactiveFrameTable"';
if (schema.phraseologic) {
schema_table += ' style="border:10px double gray;"';
}
schema_table += '>';
return schema_table;
}
function schemaHeader(schema, alternates){
var schema_header = '';
schema_header += '<tr><td class="ColumnHeader">Schemat:</td><td class="schema_' + schema.schema_id + '_" id="schema_' + schema.schema_id + '_" onclick="selectSchema(' + schema.schema_id + ')" colspan="' + schema.colspan + '">';
schema_header += '<span class="Opinion">' + schema.grade + ' [' + schema.schema_id + ']</span>';
if (alternates && control == "connect") {
schema_header += '<span><button type="button" onclick="duplicateSchema(event, ' + schema.schema_id + ')" style="float: right">Autoalternacja</button></span>';
}
schema_header += '</tr>';
return schema_header;
}
function schemaBody(schema, alternation){
var schema_body = '';
if (alternation != 1) {
schema_body += '<tr style="border-top: solid">';
} else {
schema_body += '<tr>';
}
schema_body += '<td class="ColumnHeader">Funkcja:</td>';
var display = schema.display;
for (k = 0; k < display.categories.length; k++) {
schema_body += '<td class="' + display.categories[k].csv_class + 'alt_' + alternation + '_" id="' + display.categories[k].csv_class + 'alt_' + alternation + '_" onclick="schemaClick(\'' + display.categories[k].csv_id + 'alt_' + alternation + '_\')">';
schema_body += display.categories[k].argument;
schema_body += '</td>';
position_arguments[display.categories[k].csv_class + 'alt_' + alternation + '_'] = [];
}
schema_body += '</tr>';
schema_body += '<tr>';
schema_body += '<td class="ColumnHeader" rowspan="' + schema.rowspan + '">Typy fraz:</td>';
for (k = 0; k < display.arguments.length; k++) {
for (l = 0; l < display.arguments[k].length; l++) {
schema_body += '<td id="' + display.arguments[k][l].csv_id + 'alt_' + alternation + '_" class="' + display.arguments[k][l].csv_class + 'alt_' + alternation + '_" onclick="schemaClick(\'' + display.arguments[k][l].csv_id + 'alt_' + alternation +'_\')">';
schema_body += display.arguments[k][l].argument;
schema_body += '</td>';
if (parseInt(display.arguments[k][l].csv_id.split('_')[5]) >= 0) {
position_arguments[display.arguments[k][l].csv_class + 'alt_' + alternation + '_'].push(display.arguments[k][l].csv_id + 'alt_' + alternation + '_');
}
}
schema_body += '</tr><tr>';
}
schema_body += '</tr>';
return schema_body;
}
function alternationCounts(alternations) {
alternation_counts = alternations;
}
function displaySchemas(lemma, characteristic_display){
var i, j, k, l;
var schemas_display = "";
for (i = 0; i < characteristic_display.length; i++) {
char_id = characteristic_display[i].characteristic_id;
char_display = characteristic_display[i].characteristic_display;
schemas_display += "<div><strong>" + lemma + " " + char_display + ":</strong></div>";
default_order[char_id] = [];
for (j = 0; j < characteristic_display[i].schemas.length; j++) {
schemas_content["schema_" + characteristic_display[i].schemas[j].schema_id + "_"] = characteristic_display[i].schemas[j];
schema_examples["schema_" + characteristic_display[i].schemas[j].schema_id + "_"] = [];
default_order[char_id].push("schema_" + characteristic_display[i].schemas[j].schema_id + "_");
schemas_display += '<table><tr><td id="char_' + char_id + '_' + j +'_">';
schemas_display += '</td></tr></table>';
}
}
$("#schemas").html(schemas_display);
for (var char in default_order) {
for (i = 0; i < default_order[char].length; i++) {
var schema = schemas_content[default_order[char][i]];
var schema_table = schemaTable(schema) + schemaHeader(schema, false) + schemaBody(schema, 1) + '</table>';
$("#char_" + char + "_" + i + "_").html(schema_table);
}
}
}
function redrawSchemas(frame) {
if (typeof(frame) == 'undefined') {
for (var char in default_order) {
var i;
for (i = 0; i < default_order[char].length; i++) {
var schema = schemas_content[default_order[char][i]];
var schema_table = schemaTable(schema);
schema_table += schemaHeader(schema, false);
schema_table += schemaBody(schema, 1);
schema_table += '</table>';
$("#char_" + char + "_" + i + "_").html(schema_table);
}
}
} else {
for (var char in default_order) {
var i;
for (i = 0; i < default_order[char].length; i++) {
var schema = schemas_content[default_order[char][i]];
var alts = alternations(frame, schema.schema_id);
var schema_table = schemaTable(schema);
schema_table += schemaHeader(schema, (alts < 2));
var j;
for (j = 0; j < alts; j++){
schema_table += schemaBody(schema, j + 1);
}
schema_table += '</table>';
$("#char_" + char + "_" + i + "_").html(schema_table);
}
}
}
}