Commit 4481197cf6b1697344116a4c1b7c4e85adbe18fe
1 parent
316b760a
Removed possibility of assiging two roles to single syntactic phrase/position
Showing
5 changed files
with
101 additions
and
66 deletions
semantics/static/js/semantics_connections.js
1 | var connected = {}; // dictionaries of connections and disconnections between frames and schemas | 1 | var connected = {}; // dictionaries of connections and disconnections between frames and schemas |
2 | -var disconnected = {}; | ||
3 | 2 | ||
4 | 3 | ||
5 | -function memorizeConnections(arguments_connected, arguments_disconnected){ | 4 | +function memorizeConnections(arguments_connected, frames_connection){ |
6 | connected = arguments_connected; | 5 | connected = arguments_connected; |
7 | - disconnected = arguments_disconnected; | 6 | + connected_reverse = frames_connection; |
8 | } | 7 | } |
9 | 8 | ||
10 | function getConnected(frame_id) { /* TODO */ | 9 | function getConnected(frame_id) { /* TODO */ |
semantics/static/js/semantics_frames.js
@@ -197,6 +197,16 @@ function removeFrame(frame_id) { | @@ -197,6 +197,16 @@ function removeFrame(frame_id) { | ||
197 | frames_operations.push({operation: "remove_frame", id: frame_id, units: units, connections: connections}); | 197 | frames_operations.push({operation: "remove_frame", id: frame_id, units: units, connections: connections}); |
198 | } | 198 | } |
199 | 199 | ||
200 | +function roleFree(frame_id, field_ids) { | ||
201 | + var i; | ||
202 | + for (i = 0; i < field_ids.length; i++) { | ||
203 | + if (connected_reverse[field_ids[i]].indexOf('frame_' + frame_id + '_') >= 0) { | ||
204 | + return false; | ||
205 | + } | ||
206 | + } | ||
207 | + return true; | ||
208 | +} | ||
209 | + | ||
200 | function addArgument(frame_id, field_ids, roles) { | 210 | function addArgument(frame_id, field_ids, roles) { |
201 | 211 | ||
202 | if (validateRoles(roles)) { | 212 | if (validateRoles(roles)) { |
@@ -207,6 +217,11 @@ function addArgument(frame_id, field_ids, roles) { | @@ -207,6 +217,11 @@ function addArgument(frame_id, field_ids, roles) { | ||
207 | frame_content[frame_id].display.preferences[i].push({csv_class: 'frame_' + frame_id + '_comp_' + free_complement_id + '_', csv_id: 'frame_' + frame_id + '_comp_' + free_complement_id + '_pref_-' + i + '_', preference: ''}); | 217 | frame_content[frame_id].display.preferences[i].push({csv_class: 'frame_' + frame_id + '_comp_' + free_complement_id + '_', csv_id: 'frame_' + frame_id + '_comp_' + free_complement_id + '_pref_-' + i + '_', preference: ''}); |
208 | } | 218 | } |
209 | connected['frame_' + frame_id + '_comp_' + free_complement_id + '_'] = field_ids; | 219 | connected['frame_' + frame_id + '_comp_' + free_complement_id + '_'] = field_ids; |
220 | + | ||
221 | + for(i = 0; i < field_ids.length; i++) { | ||
222 | + connected_reverse[field_ids[i]].append('frame_' + frame_id + '_'); | ||
223 | + } | ||
224 | + | ||
210 | var complement_id = free_complement_id; | 225 | var complement_id = free_complement_id; |
211 | free_complement_id = free_complement_id - 1; | 226 | free_complement_id = free_complement_id - 1; |
212 | 227 |
semantics/static/js/semantics_view.js
@@ -989,50 +989,55 @@ function schemaClick(class_id) { | @@ -989,50 +989,55 @@ function schemaClick(class_id) { | ||
989 | // highlighted_id = "26" | 989 | // highlighted_id = "26" |
990 | var frame_id = parseInt(highlighted_id); | 990 | var frame_id = parseInt(highlighted_id); |
991 | 991 | ||
992 | - var choose_role = { | ||
993 | - state0: { | ||
994 | - title: 'Wybierz rolę', | ||
995 | - html: roles_display_table, | ||
996 | - buttons: { Anuluj: -1, Zatwierdź: 1 }, | ||
997 | - focus: 1, | ||
998 | - close: function(){return result;}, | ||
999 | - submit: function(e,v,m,f){ | ||
1000 | - | ||
1001 | - if (v == -1) { | ||
1002 | - e.preventDefault(); | ||
1003 | - $.prompt.close(); | ||
1004 | - } | ||
1005 | - if (v == 1) { | ||
1006 | - e.preventDefault(); | ||
1007 | - | ||
1008 | - var roles = normalizeFormData(f.roles); | ||
1009 | - | ||
1010 | - var frame_id = parseInt(highlighted_id); | ||
1011 | - var complement_id = addArgument(frame_id, field_ids, roles); | ||
1012 | - | ||
1013 | - if (complement_id) { | ||
1014 | - var h = "frame_" + highlighted_id + "_"; | ||
1015 | - var a = "frame_" + highlighted_id + "_comp_" + complement_id + "_"; | 992 | + if (roleFree(frame_id, field_ids)) { |
993 | + | ||
994 | + var choose_role = { | ||
995 | + state0: { | ||
996 | + title: 'Wybierz rolę', | ||
997 | + html: roles_display_table, | ||
998 | + buttons: { Anuluj: -1, Zatwierdź: 1 }, | ||
999 | + focus: 1, | ||
1000 | + close: function(){return result;}, | ||
1001 | + submit: function(e,v,m,f){ | ||
1002 | + | ||
1003 | + if (v == -1) { | ||
1004 | + e.preventDefault(); | ||
1005 | + $.prompt.close(); | ||
1006 | + } | ||
1007 | + if (v == 1) { | ||
1008 | + e.preventDefault(); | ||
1016 | 1009 | ||
1017 | - // re-draw and re-color frame | ||
1018 | - frameClick(h); | ||
1019 | - displayFrames(); | ||
1020 | - frameClick(a); | 1010 | + var roles = normalizeFormData(f.roles); |
1011 | + | ||
1012 | + // var frame_id = parseInt(highlighted_id); | ||
1013 | + var complement_id = addArgument(frame_id, field_ids, roles); | ||
1021 | 1014 | ||
1022 | - result = true; | ||
1023 | - $.prompt.close(); | ||
1024 | - } else { | ||
1025 | - alert("Wybrano niepoprawne role!"); | 1015 | + if (complement_id) { |
1016 | + var h = "frame_" + highlighted_id + "_"; | ||
1017 | + var a = "frame_" + highlighted_id + "_comp_" + complement_id + "_"; | ||
1018 | + | ||
1019 | + // re-draw and re-color frame | ||
1020 | + frameClick(h); | ||
1021 | + displayFrames(); | ||
1022 | + frameClick(a); | ||
1023 | + | ||
1024 | + result = true; | ||
1025 | + $.prompt.close(); | ||
1026 | + } else { | ||
1027 | + alert("Wybrano niepoprawne role!"); | ||
1028 | + } | ||
1026 | } | 1029 | } |
1030 | + | ||
1027 | } | 1031 | } |
1028 | - | ||
1029 | - } | ||
1030 | - }, | ||
1031 | - }; | ||
1032 | - if (change == true) { | ||
1033 | - alertSemantics(); | 1032 | + }, |
1033 | + }; | ||
1034 | + if (change == true) { | ||
1035 | + alertSemantics(); | ||
1036 | + } else { | ||
1037 | + $.prompt(choose_role); | ||
1038 | + } | ||
1034 | } else { | 1039 | } else { |
1035 | - $.prompt(choose_role); | 1040 | + alert("Nie można ponownie podłączyć tej samej pozycji składniowej"); |
1036 | } | 1041 | } |
1037 | 1042 | ||
1038 | } | 1043 | } |
@@ -1046,21 +1051,42 @@ function schemaClick(class_id) { | @@ -1046,21 +1051,42 @@ function schemaClick(class_id) { | ||
1046 | } else { | 1051 | } else { |
1047 | // arg = "frame_26_comp_36_" | 1052 | // arg = "frame_26_comp_36_" |
1048 | var i, j; | 1053 | var i, j; |
1054 | + var can_connect = true; | ||
1055 | + if (roleFree(frame_id, field_ids)) { | ||
1056 | + can_connect = false; | ||
1057 | + } | ||
1058 | + var connect = true; | ||
1049 | for (i = 0; i < field_ids.length; i++) { | 1059 | for (i = 0; i < field_ids.length; i++) { |
1050 | - if ((j = connected[arg].indexOf(field_ids[i])) != -1) { | ||
1051 | - // disconnect | ||
1052 | - connected[arg].splice(j, 1); | ||
1053 | - frames_operations.push({operation: 'disconnect', arg: arg, connect: field_ids[i]}); | ||
1054 | - var a = arg; | ||
1055 | - frameClick(""); | ||
1056 | - frameClick(a); | ||
1057 | - } else { | ||
1058 | - //connect | ||
1059 | - connected[arg].push(field_ids[i]); | ||
1060 | - frames_operations.push({operation: 'connect', arg: arg, connect: field_ids[i]}); | ||
1061 | - var a = arg; | ||
1062 | - frameClick(""); | ||
1063 | - frameClick(a); | 1060 | + if (connected[arg].indexOf(field_ids[i]) != -1) { |
1061 | + connect = false; | ||
1062 | + break; | ||
1063 | + } | ||
1064 | + } | ||
1065 | + if (connect && !can_connect) { | ||
1066 | + alert("Nie można ponownie podłączyć tej samej pozycji składniowej"); | ||
1067 | + } else { | ||
1068 | + for (i = 0; i < field_ids.length; i++) { | ||
1069 | + if (!connect) { | ||
1070 | + // disconnect | ||
1071 | + j = connected[arg].indexOf(field_ids[i]) | ||
1072 | + if (j != -1) { | ||
1073 | + connected[arg].splice(j, 1); | ||
1074 | + frames_operations.push({operation: 'disconnect', arg: arg, connect: field_ids[i]}); | ||
1075 | + var a = arg; | ||
1076 | + frameClick(""); | ||
1077 | + frameClick(a); | ||
1078 | + } | ||
1079 | + } else { | ||
1080 | + //connect | ||
1081 | + j = connected[arg].indexOf(field_ids[i]) | ||
1082 | + if (j == -1) { // redundant | ||
1083 | + connected[arg].push(field_ids[i]); | ||
1084 | + frames_operations.push({operation: 'connect', arg: arg, connect: field_ids[i]}); | ||
1085 | + var a = arg; | ||
1086 | + frameClick(""); | ||
1087 | + frameClick(a); | ||
1088 | + } | ||
1089 | + } | ||
1064 | } | 1090 | } |
1065 | } | 1091 | } |
1066 | } | 1092 | } |
semantics/templates/semantics.html
@@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
39 | $.getJSON(ajax_frames, {lemma_id: {{ lemma.id }}}, function(data){ | 39 | $.getJSON(ajax_frames, {lemma_id: {{ lemma.id }}}, function(data){ |
40 | getFrames(data.frames_display); | 40 | getFrames(data.frames_display); |
41 | displayFrames(); | 41 | displayFrames(); |
42 | - memorizeConnections(data.connections.connected, data.connections.disconnected); | 42 | + memorizeConnections(data.connections.connected, data.connections.connected_reverse); |
43 | alternationCounts(data.alternations); | 43 | alternationCounts(data.alternations); |
44 | $("#semantic-frames-count").empty(); | 44 | $("#semantic-frames-count").empty(); |
45 | $("#semantic-frames-count").append(data.frames_count); | 45 | $("#semantic-frames-count").append(data.frames_count); |
semantics/views.py
@@ -166,9 +166,6 @@ def ajax_frames(request, lemma_id): | @@ -166,9 +166,6 @@ def ajax_frames(request, lemma_id): | ||
166 | display = {"roles": frame_roles, "preferences": frame_preferences} | 166 | display = {"roles": frame_roles, "preferences": frame_preferences} |
167 | frame_display["frames"].append({"frame_id": str(frame.id), "colspan": str(max(len(frame_roles), 1)), "rowspan": str(frame_preferences_rowspan), "status": u'pewna', "display": display}) | 167 | frame_display["frames"].append({"frame_id": str(frame.id), "colspan": str(max(len(frame_roles), 1)), "rowspan": str(frame_preferences_rowspan), "status": u'pewna', "display": display}) |
168 | 168 | ||
169 | - | ||
170 | - arguments_frame_connected[frame.id] = [] | ||
171 | - | ||
172 | for complement, complement_class in zip(frame_complements, frame_ids): | 169 | for complement, complement_class in zip(frame_complements, frame_ids): |
173 | if complement_class not in complement_arguments: | 170 | if complement_class not in complement_arguments: |
174 | complement_arguments[complement_class] = [] | 171 | complement_arguments[complement_class] = [] |
@@ -180,7 +177,9 @@ def ajax_frames(request, lemma_id): | @@ -180,7 +177,9 @@ def ajax_frames(request, lemma_id): | ||
180 | alternation = schema_position.alternation | 177 | alternation = schema_position.alternation |
181 | realization_id = u'schema_' + str(schema.id) + u'_pos_' + str(position.id) + '_arg_' + str(argument.id) + '_' + 'alt_' + str(alternation) + '_' | 178 | realization_id = u'schema_' + str(schema.id) + u'_pos_' + str(position.id) + '_arg_' + str(argument.id) + '_' + 'alt_' + str(alternation) + '_' |
182 | complement_arguments[complement_class].append(realization_id) | 179 | complement_arguments[complement_class].append(realization_id) |
183 | - arguments_frame_connected[frame.id].append(realization_id) | 180 | + if realization_id not in arguments_frame_connected: |
181 | + arguments_frame_connected[realization_id] = [] | ||
182 | + arguments_frame_connected[realization_id].append('frame_' + str(frame.id) + '_') | ||
184 | if schema.id in alternations[frame.id]: | 183 | if schema.id in alternations[frame.id]: |
185 | alternations[frame.id][schema.id] = max(alternations[frame.id][schema.id], alternation) | 184 | alternations[frame.id][schema.id] = max(alternations[frame.id][schema.id], alternation) |
186 | else: | 185 | else: |
@@ -189,16 +188,12 @@ def ajax_frames(request, lemma_id): | @@ -189,16 +188,12 @@ def ajax_frames(request, lemma_id): | ||
189 | 188 | ||
190 | 189 | ||
191 | frames_display.append(frame_display) | 190 | frames_display.append(frame_display) |
192 | - | ||
193 | - arguments_not_connected = {} | ||
194 | - # for complement_class in complement_arguments: | ||
195 | - # arguments_not_connected[complement_class] = list(all_schema_classes.difference(arguments_frame_connected[int(complement_class.split('_')[1])])) | ||
196 | 191 | ||
197 | # ala["ma"] = "kot" | 192 | # ala["ma"] = "kot" |
198 | 193 | ||
199 | context = { | 194 | context = { |
200 | 'frames_display': frames_display, | 195 | 'frames_display': frames_display, |
201 | - 'connections': {'connected': complement_arguments, 'disconnected': arguments_not_connected}, | 196 | + 'connections': {'connected': complement_arguments, 'connected_reverse': arguments_frame_connected}, |
202 | 'frames_count': lemma.entry_obj.actual_frames().count(), | 197 | 'frames_count': lemma.entry_obj.actual_frames().count(), |
203 | 'alternations': alternations | 198 | 'alternations': alternations |
204 | } | 199 | } |