Commit 9c1f2964ef14aaaef2c727eeb9884660bb57867b
Merge branch 'tomek'
Showing
8 changed files
with
248 additions
and
64 deletions
semantics/management/commands/connect_noun_lexical_units.py
0 → 100644
1 | +#! /usr/bin/python | |
2 | +# -*- coding: utf-8 -*- | |
3 | + | |
4 | +import sys, os, codecs | |
5 | + | |
6 | +from django.core.management.base import BaseCommand | |
7 | + | |
8 | +from dictionary.models import Entry, POS | |
9 | +from wordnet.models import LexicalUnit | |
10 | +from settings import PROJECT_PATH | |
11 | + | |
12 | +class Command(BaseCommand): | |
13 | + args = 'none' | |
14 | + help = '' | |
15 | + | |
16 | + def handle(self, **options): | |
17 | + connect_nouns() | |
18 | + | |
19 | +def connect_nouns(): | |
20 | + noun = POS.objects.get(tag='noun') | |
21 | + entries = Entry.objects.filter(pos=noun) | |
22 | + for entry in entries: | |
23 | + lus = LexicalUnit.objects.filter(base=entry.name, pos=u'rzeczownik') | |
24 | + for lu in lus: | |
25 | + lu.entry = entry | |
26 | + lu.save() | |
27 | + | |
... | ... |
semantics/saving.py
... | ... | @@ -221,10 +221,15 @@ def validate_roles(roles): |
221 | 221 | |
222 | 222 | def change_units(lemma_id, frame_id, luids): |
223 | 223 | frame = SemanticFrame.objects.get(id=frame_id) |
224 | - frame.lexical_units = [] | |
224 | + entry = Lemma.objects.get(id=lemma_id).entry_obj | |
225 | + temp = frame.lexical_units.exclude(entry=entry) | |
226 | + temp2 = [] | |
227 | + for lu in temp: | |
228 | + temp2.append(LexicalUnit.objects.get(id=lu.id)) | |
229 | + frame.lexical_units = temp2 | |
225 | 230 | for id in luids: |
226 | 231 | lu = LexicalUnit.objects.get(id=id) |
227 | - lu.entry = Lemma.objects.get(id=lemma_id).entry_obj | |
232 | + lu.entry = entry | |
228 | 233 | lu.save() |
229 | 234 | frame.lexical_units.add(lu) |
230 | 235 | |
... | ... |
semantics/sem_urls.py
... | ... | @@ -26,4 +26,5 @@ SEMANTIC_PATTERNS = patterns('semantics.views', |
26 | 26 | url(r'^ajax/synset_preference_form/$', 'synset_preference_form'), |
27 | 27 | url(r'^ajax/relational_preference_form/$', 'relational_preference_form'), |
28 | 28 | url(r'^ajax/get_mwe_list/$', 'ajax_get_mwes'), |
29 | + url(r'^ajax/connected/$', 'ajax_connected'), | |
29 | 30 | ) |
... | ... |
semantics/static/js/semantics_connections.js
... | ... | @@ -6,12 +6,14 @@ function memorizeConnections(arguments_connected, frames_connection){ |
6 | 6 | connected_reverse = frames_connection; |
7 | 7 | } |
8 | 8 | |
9 | -function getConnected(frame_id) { /* TODO */ | |
10 | - return []; | |
11 | -} | |
12 | - | |
13 | -function removeFrameConnections(frame_id) { /* TODO */ | |
14 | - return; | |
9 | +function addConnections(arguments_connected, frames_connection){ | |
10 | + var i; | |
11 | + for (i = 0; i < arguments_connected.length; i++) { | |
12 | + var argument = arguments_connected[i]; | |
13 | + if (!connected.hasOwnProperty(argument)) { | |
14 | + connected[argument] = []; | |
15 | + } | |
16 | + } | |
15 | 17 | } |
16 | 18 | |
17 | 19 | function removeArgumentConnections(frame_id, complement_id) { |
... | ... |
semantics/static/js/semantics_frames.js
... | ... | @@ -4,6 +4,23 @@ var free_complement_id = -1; |
4 | 4 | var free_frame_id = -1; |
5 | 5 | var free_preference_id = -1; |
6 | 6 | var semantic_opinion_vals = []; |
7 | +var connected_entries = [] | |
8 | + | |
9 | + | |
10 | +function getConnected(frames_display) { | |
11 | + var i, j; | |
12 | + for (i = 0; i < frames_display.length; i++) { | |
13 | + lexical_units_num.push(frames_display[i].lexical_units); | |
14 | + lexical_units_frames[i] = []; | |
15 | + | |
16 | + var frames = frames_display[i].frames; | |
17 | + for (j = 0; j < frames.length; j++) { | |
18 | + frame_content[frames[j].frame_id] = frames[j]; | |
19 | + frame_localization[frames[j].frame_id] = {"units": i, "position": j}; | |
20 | + lexical_units_frames[i].push(frames[j].frame_id); | |
21 | + } | |
22 | + } | |
23 | +} | |
7 | 24 | |
8 | 25 | function selectedFrame() { |
9 | 26 | return "frame_" + highlighted_id + "_"; |
... | ... | @@ -22,8 +39,12 @@ function getFrames(frames_display){ |
22 | 39 | lexical_units_frames[i] = []; |
23 | 40 | |
24 | 41 | var frames = frames_display[i].frames; |
42 | + var visible = frames_display[i].visible; | |
43 | + var local = frames_display[i].local; | |
25 | 44 | for (j = 0; j < frames.length; j++) { |
26 | 45 | frame_content[frames[j].frame_id] = frames[j]; |
46 | + frame_content[frames[j].frame_id]['visible'] = visible; | |
47 | + frame_content[frames[j].frame_id]['local'] = local; | |
27 | 48 | frame_localization[frames[j].frame_id] = {"units": i, "position": j}; |
28 | 49 | lexical_units_frames[i].push(frames[j].frame_id); |
29 | 50 | } |
... | ... | @@ -49,43 +70,64 @@ function getStatusesForFrame(frame_id){ |
49 | 70 | return display; |
50 | 71 | } |
51 | 72 | |
52 | -function displayFrames(){ | |
53 | - var display = ''; | |
73 | +function getDisplay(visibility, checkboxes) { | |
74 | + display = ''; | |
54 | 75 | var i, j; |
55 | 76 | for ( i = 0; i < lexical_units_num.length; i++) { |
56 | - display += '<div id="lus_' + i + '_">'; | |
57 | - display += '<div>'; | |
58 | - var units = []; | |
59 | - for (j = 0; j < lexical_units_num[i].length; j++) { | |
60 | - var id = parseInt(lexical_units_num[i][j].id); | |
61 | - var lid = indexOfId(lexical_units, id) | |
62 | - var u = '<strong title="'; | |
63 | - u += lexical_units[lid].glossa; | |
64 | - if (lexical_units[lid].glossa != '') { | |
65 | - u += '\n'; | |
77 | + var visible = frame_content[lexical_units_frames[i][0]].visible; | |
78 | + if (visible == visibility) { | |
79 | + display += '<div id="lus_' + i + '_">'; | |
80 | + display += '<div>'; | |
81 | + if (checkboxes) { | |
82 | + var frame_id = frame_content[lexical_units_frames[i][0]].frame_id; | |
83 | + display += '<input type="checkbox" name= "frames" value="' + frame_id + '">'; | |
66 | 84 | } |
67 | - u += lexical_units[lid].definition; | |
68 | - if (lexical_units[lid].definition != '') { | |
69 | - u += '\n'; | |
85 | + | |
86 | + var units = []; | |
87 | + for (j = 0; j < lexical_units_num[i].length; j++) { | |
88 | + var id = parseInt(lexical_units_num[i][j].id); | |
89 | + var lid = indexOfId(lexical_units, id); | |
90 | + var u = ''; | |
91 | + if (lid == -1) { | |
92 | + u += '<em>'; | |
93 | + u += lexical_units_num[i][j].base; | |
94 | + u += '-'; | |
95 | + u += lexical_units_num[i][j].sense; | |
96 | + u += '</em>'; | |
97 | + } else { | |
98 | + u += '<strong title="'; | |
99 | + u += lexical_units[lid].glossa; | |
100 | + if (lexical_units[lid].glossa != '') { | |
101 | + u += '\n'; | |
102 | + } | |
103 | + u += lexical_units[lid].definition; | |
104 | + if (lexical_units[lid].definition != '') { | |
105 | + u += '\n'; | |
106 | + } | |
107 | + u += lexical_units[lid].location; | |
108 | + u +='"> '; | |
109 | + u += lexical_units[lid].base + '-' + lexical_units[lid].sense; | |
110 | + u += '</strong>'; | |
111 | + } | |
112 | + units.push(u); | |
70 | 113 | } |
71 | - u += lexical_units[lid].location; | |
72 | - u +='"> '; | |
73 | - u += lexical_units[lid].base + '-' + lexical_units[lid].sense; | |
74 | - u += '</strong>'; | |
75 | - units.push(u); | |
76 | - } | |
77 | - display += units.join() | |
78 | - var frames = lexical_units_frames[i]; | |
79 | - for (j = 0; j < frames.length; j++) { | |
80 | - display += '<div id="lus_' + i + '_pos_' + j +'_">'; | |
81 | - display += getFrameDisplay(frame_content[frames[j]]); | |
82 | - display += '</div>'; | |
83 | - } | |
84 | - display += '</div>'; | |
85 | - | |
86 | - display += '</div>'; | |
114 | + var frames = lexical_units_frames[i]; | |
115 | + display += units.join() | |
116 | + for (j = 0; j < frames.length; j++) { | |
117 | + display += '<div id="lus_' + i + '_pos_' + j +'_">'; | |
118 | + display += getFrameDisplay(frame_content[frames[j]]); | |
119 | + display += '</div>'; | |
120 | + } | |
121 | + display += '</div>'; | |
122 | + | |
123 | + display += '</div>'; | |
124 | + } | |
87 | 125 | } |
88 | - $("#frames").html(display); | |
126 | + return display; | |
127 | +} | |
128 | + | |
129 | +function displayFrames(){ | |
130 | + $("#frames").html(getDisplay(true, false)); | |
89 | 131 | } |
90 | 132 | |
91 | 133 | function getFrameDisplay(frame_description){ |
... | ... | @@ -333,7 +375,15 @@ function changeUnits(frame_id, units) { |
333 | 375 | var j; |
334 | 376 | for (j = 0; j < lexical_units_num.length; j++) { |
335 | 377 | if (lexical_units_frames[j].indexOf(id) != -1) { |
336 | - lexical_units_num[j] = [] | |
378 | + var temp = []; | |
379 | + var l; | |
380 | + for (l = 0; l < lexical_units_num[j].length; l++) { | |
381 | + var lu = lexical_units_num[j][l] | |
382 | + if (indexOfId(lexical_units, lu.id) == -1) { | |
383 | + temp.push(lu); | |
384 | + } | |
385 | + } | |
386 | + lexical_units_num[j] = temp; | |
337 | 387 | var i; |
338 | 388 | for (i = 0; i < units.length; i++) { |
339 | 389 | var k; |
... | ... | @@ -506,3 +556,5 @@ function saveFrames() { |
506 | 556 | frames_operations = []; |
507 | 557 | } |
508 | 558 | } |
559 | + | |
560 | + | |
... | ... |
semantics/static/js/semantics_view.js
... | ... | @@ -864,6 +864,43 @@ function removeFromFrame() { |
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
867 | +///////////////////////// Frame Sharing ///////////////////////// | |
868 | + | |
869 | +function sharableFrames() { | |
870 | + return getDisplay(false, true); | |
871 | +} | |
872 | + | |
873 | +function shareFrame() { | |
874 | + | |
875 | + var share_frame = { | |
876 | + state0: { | |
877 | + title: 'Współdzielona rama', | |
878 | + html: sharableFrames(), | |
879 | + buttons: { Anuluj: -1, Zatwierdź: 1 }, | |
880 | + focus: 1, | |
881 | + submit: function(e,v,m,f) { | |
882 | + if (v == -1) { | |
883 | + e.preventDefault(); | |
884 | + $.prompt.close(); | |
885 | + } | |
886 | + if (v == 1) { | |
887 | + var frames = normalizeFormData(f.frames); | |
888 | + var i; | |
889 | + for (i = 0; i < frames.length; i++) { | |
890 | + frame_content[frames[i]].visible = true; | |
891 | + } | |
892 | + displayFrames(); | |
893 | + e.preventDefault(); | |
894 | + $.prompt.close(); | |
895 | + } | |
896 | + } | |
897 | + }, | |
898 | + }; | |
899 | + | |
900 | + $.prompt(share_frame); | |
901 | + | |
902 | +} | |
903 | + | |
867 | 904 | //////////////////////////// Display //////////////////////////// |
868 | 905 | |
869 | 906 | function frameClick(clicked_id) { |
... | ... | @@ -899,6 +936,7 @@ function frameClick(clicked_id) { |
899 | 936 | } else { |
900 | 937 | if (clicked_id.split('_').length == 3) { // frame click |
901 | 938 | var frame_id = clicked_id.split('_')[1]; |
939 | + var local = frame_content[frame_id].local; | |
902 | 940 | |
903 | 941 | if (highlighted_id != "") { |
904 | 942 | deselect(); |
... | ... | @@ -922,13 +960,19 @@ function frameClick(clicked_id) { |
922 | 960 | |
923 | 961 | $('#assign_role').attr('disabled', "True"); |
924 | 962 | $('#add_preference').attr('disabled', "True"); |
925 | - $('#delete').removeAttr('disabled'); | |
926 | 963 | $('#multi_lus').removeAttr('disabled'); |
927 | 964 | $('#change_lus').removeAttr('disabled'); |
928 | - $('#change_opinion').removeAttr('disabled'); | |
965 | + if (!local) { | |
966 | + $('#delete').attr('disabled', "True"); | |
967 | + $('#change_opinion').attr('disabled', "True"); | |
968 | + } else { | |
969 | + $('#delete').removeAttr('disabled'); | |
970 | + $('#change_opinion').removeAttr('disabled'); | |
971 | + } | |
929 | 972 | } |
930 | 973 | } else if (clicked_id.split('_')[4] == 'lemma') { // part of lemma click |
931 | 974 | frame_id = clicked_id.split('_')[1] |
975 | + var local = frame_content[frame_id].local; | |
932 | 976 | |
933 | 977 | if (highlighted_id != "") { |
934 | 978 | deselect(); |
... | ... | @@ -954,13 +998,19 @@ function frameClick(clicked_id) { |
954 | 998 | |
955 | 999 | $('#assign_role').attr('disabled', "True"); |
956 | 1000 | $('#add_preference').attr('disabled', "True"); |
957 | - $('#delete').removeAttr('disabled'); | |
958 | 1001 | $('#multi_lus').removeAttr('disabled'); |
959 | 1002 | $('#change_lus').removeAttr('disabled'); |
960 | - $('#change_opinion').removeAttr('disabled'); | |
1003 | + if (!local) { | |
1004 | + $('#delete').attr('disabled', "True"); | |
1005 | + $('#change_opinion').attr('disabled', "True"); | |
1006 | + } else { | |
1007 | + $('#delete').removeAttr('disabled'); | |
1008 | + $('#change_opinion').removeAttr('disabled'); | |
1009 | + } | |
961 | 1010 | } |
962 | 1011 | } else { // argument click |
963 | 1012 | frame_id = clicked_id.split('_')[1] |
1013 | + var local = frame_content[frame_id].local; | |
964 | 1014 | |
965 | 1015 | if (highlighted_id != "") { |
966 | 1016 | deselect(); |
... | ... | @@ -987,13 +1037,20 @@ function frameClick(clicked_id) { |
987 | 1037 | op = "remove_preference"; |
988 | 1038 | } |
989 | 1039 | arg = clicked_id //.split('pref')[0] |
990 | - | |
991 | - $('#assign_role').removeAttr('disabled'); | |
992 | - $('#add_preference').removeAttr('disabled'); | |
993 | - $('#delete').removeAttr('disabled'); | |
1040 | + | |
1041 | + if (!local) { | |
1042 | + $('#assign_role').attr('disabled', "True"); | |
1043 | + $('#add_preference').attr('disabled', "True"); | |
1044 | + $('#delete').attr('disabled', "True"); | |
1045 | + $('#change_opinion').attr('disabled', "True"); | |
1046 | + } else { | |
1047 | + $('#assign_role').removeAttr('disabled'); | |
1048 | + $('#add_preference').removeAttr('disabled'); | |
1049 | + $('#delete').removeAttr('disabled'); | |
1050 | + $('#change_opinion').removeAttr('disabled'); | |
1051 | + } | |
994 | 1052 | $('#multi_lus').removeAttr('disabled'); |
995 | 1053 | $('#change_lus').removeAttr('disabled'); |
996 | - $('#change_opinion').removeAttr('disabled'); | |
997 | 1054 | } |
998 | 1055 | } |
999 | 1056 | } |
... | ... | @@ -1232,6 +1289,10 @@ function schemaClick(class_id, lex) { |
1232 | 1289 | } |
1233 | 1290 | if (op == "add_argument") { |
1234 | 1291 | // highlighted_id = "26" |
1292 | + var local = frame_content[highlighted_id].local; | |
1293 | + if (!local) { | |
1294 | + return; | |
1295 | + } | |
1235 | 1296 | var frame_id = parseInt(highlighted_id); |
1236 | 1297 | |
1237 | 1298 | if (roleFree(frame_id, field_ids)) { |
... | ... |
semantics/templates/semantics.html
... | ... | @@ -40,9 +40,10 @@ |
40 | 40 | memorizeOpinions(data.opinions); |
41 | 41 | $.getJSON(ajax_frames, {lemma_id: {{ lemma.id }}}, function(data){ |
42 | 42 | getFrames(data.frames_display); |
43 | - displayFrames(); | |
44 | - memorizeConnections(data.connections.connected, data.connections.connected_reverse); | |
45 | - alternationCounts(data.alternations); | |
43 | + memorizeConnections(data.connections.connected, | |
44 | + data.connections.connected_reverse); | |
45 | + alternationCounts(data.alternations); | |
46 | + displayFrames(); | |
46 | 47 | $("#semantic-frames-count").empty(); |
47 | 48 | $("#semantic-frames-count").append(data.frames_count); |
48 | 49 | }); |
... | ... | @@ -90,8 +91,9 @@ |
90 | 91 | <div id="control" class="semantics-control-tabs" style="overflow: auto;"> |
91 | 92 | <ul> |
92 | 93 | <li><a href="#select_meanings">Znaczenia</a></li> |
93 | - <li><a href="#select_creating">Tworzenie</a></li> | |
94 | - </ul> | |
94 | + <li><a href="#select_creating">Tworzenie</a></li> | |
95 | + <li><a href="#select_connected">Powiązane</a></li> | |
96 | + </ul> | |
95 | 97 | <div id="select_meanings"> |
96 | 98 | <button type="button" onclick="openMeaningsMenu()" id="create">Modyfikuj</button> |
97 | 99 | </div> |
... | ... | @@ -107,6 +109,9 @@ |
107 | 109 | <br/> |
108 | 110 | <button type="button" onclick="saveFrames()" id="save_frames">Zapisz</button> |
109 | 111 | </div> |
112 | + <div id="select_connected" style="overflow: auto;"> | |
113 | + <button type="button" onclick="shareFrame()" id="share_frames">Kopiuj</button> | |
114 | + </div> | |
110 | 115 | </div> |
111 | 116 | {% endif %} |
112 | 117 | |
... | ... |
semantics/views.py
... | ... | @@ -49,6 +49,7 @@ def ajax_semantics(request, id): |
49 | 49 | 'ajax_predefined_preferences': reverse('ajax_predefined_preferences'), |
50 | 50 | 'ajax_plWN_context_lookup': reverse('ajax_plWN_context_lookup'), |
51 | 51 | 'ajax_get_mwes': reverse('ajax_get_mwes'), |
52 | + 'ajax_connected': reverse('ajax_connected'), | |
52 | 53 | } |
53 | 54 | return context |
54 | 55 | |
... | ... | @@ -82,6 +83,7 @@ def ajax_frames(request, lemma_id): |
82 | 83 | |
83 | 84 | def create_frames_context(lemma_id, user): |
84 | 85 | lemma = Lemma.objects.get(id=lemma_id) |
86 | + connected = lemma.entry_obj.rel_entries.all() | |
85 | 87 | |
86 | 88 | #lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense') |
87 | 89 | # lexical_units = lemma.entry_obj.meanings.order_by('sense') |
... | ... | @@ -89,16 +91,12 @@ def create_frames_context(lemma_id, user): |
89 | 91 | alternations = {} |
90 | 92 | frames_dict = {} |
91 | 93 | frame_units = {} |
92 | -# for lexical_unit in lexical_units: | |
93 | -# frames = lexical_unit.actual_frames() | |
94 | -# for frame in frames: | |
95 | -# alternations[frame.id] = {} | |
96 | -# frames_dict[frame.id] = frame | |
97 | -# if frame.id not in frame_units: | |
98 | -# frame_units[frame.id] = [] | |
99 | -# frame_units[frame.id].append(lexical_unit) | |
100 | 94 | |
101 | 95 | frames = lemma.entry_obj.actual_frames() |
96 | + for entry in connected: | |
97 | + new_frames = entry.actual_frames() | |
98 | + frames |= new_frames | |
99 | + | |
102 | 100 | for frame in frames: |
103 | 101 | alternations[frame.id] = {} |
104 | 102 | frames_dict[frame.id] = frame |
... | ... | @@ -124,10 +122,21 @@ def create_frames_context(lemma_id, user): |
124 | 122 | for t in k: |
125 | 123 | |
126 | 124 | # for t in type_frames: |
127 | - frame_display = {"lexical_units": [], "frames": []} | |
125 | + frame_display = {"lexical_units": [], "frames": [], "visible": False, "local": None} | |
128 | 126 | for lu in list(t): |
129 | 127 | frame_display["lexical_units"].append({"id": str(lu.id), "base": lu.base, "sense": str(lu.sense)}) |
128 | + lu_entry = lu.entry | |
129 | + lemma_entry = lemma.entry_obj | |
130 | + if (lu_entry.name, lu_entry.pos.tag) == (lemma_entry.name, lemma_entry.pos.tag): | |
131 | + frame_display["visible"] = True | |
130 | 132 | for frame in type_frames[t]: |
133 | + frame_entry = frame.entry | |
134 | + lemma_entry = lemma.entry_obj | |
135 | + if (frame_entry.name, frame_entry.pos.tag) == (lemma_entry.name, lemma_entry.pos.tag): | |
136 | + frame_display["local"] = True | |
137 | + else: | |
138 | + frame_display["local"] = False | |
139 | + | |
131 | 140 | # frame_complements = Complement.objects.filter(frame=frame) |
132 | 141 | # frame_complements = frame.complements.all() |
133 | 142 | lemma_role = SemanticRole.objects.get(role="Lemma") |
... | ... | @@ -249,6 +258,28 @@ def create_frames_context(lemma_id, user): |
249 | 258 | |
250 | 259 | return context |
251 | 260 | |
261 | + | |
262 | +@render('connected.json') | |
263 | +@ajax(method='get', encode_result=False) | |
264 | +def ajax_connected(request, lemma_id): | |
265 | + context = create_connected_context(lemma_id, request.user) | |
266 | + return context | |
267 | + | |
268 | +def create_connected_context(lemma_id, user): | |
269 | + lemma = Lemma.objects.get(id=lemma_id) | |
270 | + connected = lemma.entry_obj.rel_entries.all() | |
271 | + context = {'frames_display': [], 'connections':{'connected_reverse': [], 'connected': []}} | |
272 | + | |
273 | + for entry in connected: | |
274 | + lemma = entry.actual_lemma() | |
275 | + frame_context = create_frames_context(lemma.id, user) | |
276 | + context['frames_display'] += frame_context['frames_display'] | |
277 | + context['connections']['connected'] += frame_context['connections']['connected'] | |
278 | + context['connections']['connected_reverse'] += frame_context['connections']['connected_reverse'] | |
279 | + | |
280 | + return context | |
281 | + | |
282 | + | |
252 | 283 | @render('units.json') |
253 | 284 | @ajax(method='get', encode_result=False) |
254 | 285 | def ajax_units(request, lemma_id): |
... | ... |