Commit 9a4af6ae99eeeb93bf7b29f74794067f4b42c9cd
Merge branch 'tomek'
Showing
7 changed files
with
168 additions
and
15 deletions
semantics/management/commands/import_opinions.py
0 → 100644
1 | +#! /usr/bin/python | |
2 | +# -*- coding: utf-8 -*- | |
3 | + | |
4 | +from django.core.management.base import BaseCommand | |
5 | +from settings import PROJECT_PATH | |
6 | + | |
7 | +from semantics.models import FrameOpinion | |
8 | + | |
9 | +OPINIONS = [(70, u'met', u'metaforyczna'), (60, u'vul', u'wulgarna'), (50, u'col', u'potoczna'), (40, u'dat', u'archaiczna'), (30, u'bad', u'zła'), (20, u'unc', u'wątpliwa'), (10, u'cer', u'pewna')] | |
10 | + | |
11 | +#==========================================================# | |
12 | +class Command(BaseCommand): | |
13 | + args = 'none' | |
14 | + help = '' | |
15 | + | |
16 | + def handle(self, **options): | |
17 | + import_opinions() | |
18 | + | |
19 | +def import_opinions(): | |
20 | + opinions = [] | |
21 | + for priority, short, value in OPINIONS: | |
22 | + o=FrameOpinion(value=value, short=short, priority=priority) | |
23 | + opinions.append(o) | |
24 | + | |
25 | + FrameOpinion.objects.bulk_create(opinions) | |
26 | + | |
... | ... |
semantics/models.py
... | ... | @@ -21,7 +21,16 @@ class SemanticRole(models.Model): # lista dostępnych ról semantycznych |
21 | 21 | |
22 | 22 | def __unicode__(self): |
23 | 23 | return '%s' % self.role |
24 | - | |
24 | + | |
25 | +class FrameOpinion(models.Model): | |
26 | + value = models.CharField(max_length=16, unique=True) | |
27 | + short = models.CharField(max_length=16, blank=True, null=True) | |
28 | + # okresla kolejnosc prezentowania opinii | |
29 | + priority = models.PositiveIntegerField(blank=True, null=True) | |
30 | + | |
31 | + def __unicode__(self): | |
32 | + return '%s' % (self.value) | |
33 | + | |
25 | 34 | class SemanticFrame(models.Model): |
26 | 35 | # identyfikator ramki |
27 | 36 | id = models.AutoField(primary_key=True) |
... | ... | @@ -33,6 +42,7 @@ class SemanticFrame(models.Model): |
33 | 42 | next = models.ForeignKey('SemanticFrame', null=True) |
34 | 43 | removed = models.BooleanField(default=False) |
35 | 44 | author = models.ForeignKey(User, null=True) |
45 | + opinion = models.ForeignKey(FrameOpinion, null=True) | |
36 | 46 | |
37 | 47 | def role_exists(self, role_name): |
38 | 48 | if self.complements.filter(roles__role=role_name).exists(): |
... | ... |
semantics/sem_urls.py
... | ... | @@ -10,6 +10,7 @@ SEMANTIC_PATTERNS = patterns('semantics.views', |
10 | 10 | url(r'^ajax/relations/$', 'ajax_relations'), |
11 | 11 | url(r'^ajax/predefined_preferences/$', 'ajax_predefined_preferences'), |
12 | 12 | url(r'^ajax/roles/$', 'ajax_roles'), |
13 | + url(r'^ajax/opinions/$', 'ajax_opinions'), | |
13 | 14 | url(r'^ajax/schemas/$', 'ajax_schemas'), |
14 | 15 | url(r'^ajax/frames/$', 'ajax_frames'), |
15 | 16 | url(r'^ajax/create_frame/$', 'ajax_create_frame'), |
... | ... |
semantics/static/js/semantics_frames.js
... | ... | @@ -3,6 +3,7 @@ var frame_content = []; // list of contents of all frames |
3 | 3 | var free_complement_id = -1; |
4 | 4 | var free_frame_id = -1; |
5 | 5 | var free_preference_id = -1; |
6 | +var semantic_opinion_vals = []; | |
6 | 7 | |
7 | 8 | function selectedFrame() { |
8 | 9 | return "frame_" + highlighted_id + "_"; |
... | ... | @@ -28,6 +29,25 @@ function getFrames(frames_display){ |
28 | 29 | } |
29 | 30 | } |
30 | 31 | |
32 | +function memorizeOpinions(opinions_list){ | |
33 | + var i; | |
34 | + | |
35 | + for (i = 0; i < opinions_list.length; i++){ | |
36 | + semantic_opinion_vals[opinions_list[i].id] = opinions_list[i].name; | |
37 | + } | |
38 | +} | |
39 | + | |
40 | +function getStatusesForFrame(frame_id){ | |
41 | + // TODO: limit possible values | |
42 | + var display = ""; | |
43 | + | |
44 | + for (var id in semantic_opinion_vals){ | |
45 | + display += "<input type = \"radio\" name = \"opinion\" value = \"" + id + "\">" + semantic_opinion_vals[id] + "<br>"; | |
46 | + } | |
47 | + | |
48 | + return display; | |
49 | +} | |
50 | + | |
31 | 51 | function displayFrames(){ |
32 | 52 | var display = ''; |
33 | 53 | var i, j; |
... | ... | @@ -40,7 +60,11 @@ function displayFrames(){ |
40 | 60 | var lid = indexOfId(lexical_units, id) |
41 | 61 | var u = '<strong title="'; |
42 | 62 | u += lexical_units[lid].glossa; |
43 | - u +='"> '; | |
63 | + if (lexical_units[lid].glossa != '') { | |
64 | + u += '\n'; | |
65 | + } | |
66 | + u += lexical_units[lid].definition; | |
67 | + u +='"> '; | |
44 | 68 | u += lexical_units[lid].base + '-' + lexical_units[lid].sense; |
45 | 69 | u += '</strong>'; |
46 | 70 | units.push(u); |
... | ... | @@ -63,7 +87,7 @@ function getFrameDisplay(frame_description){ |
63 | 87 | var i, j; |
64 | 88 | var display = '<table><tr><td>'; |
65 | 89 | display += '<table class="InactiveFrameTable">'; |
66 | - display += '<tr><td class="ColumnHeader">Ocena ramy:</td><td id="frame_' + frame_description.frame_id + '_" class="frame_' + frame_description.frame_id + '_" colspan="' + frame_description.colspan + '" onclick="frameClick(\'frame_' + frame_description.frame_id + '_\', \'frame_' + frame_description.frame_id + '_\')">'; | |
90 | + display += '<tr><td class="ColumnHeader">Rama:</td><td id="frame_' + frame_description.frame_id + '_" class="frame_' + frame_description.frame_id + '_" colspan="' + frame_description.colspan + '" onclick="frameClick(\'frame_' + frame_description.frame_id + '_\', \'frame_' + frame_description.frame_id + '_\')">'; | |
67 | 91 | display += '<span class="Opinion">' + frame_description.status + ' [' + frame_description.frame_id + ']</span>'; |
68 | 92 | display += '<tr>'; |
69 | 93 | display += '<td class="ColumnHeader">Rola:</td>'; |
... | ... | @@ -90,7 +114,7 @@ function getFrameDisplay(frame_description){ |
90 | 114 | } |
91 | 115 | display += '</tr>'; |
92 | 116 | display += '<tr>'; |
93 | - display += '<td class="ColumnHeader" rowspan="' + frame_description.rowspan + '">Preferencje selekcyjne:</td>'; | |
117 | + display += '<td class="ColumnHeader" rowspan="' + frame_description.rowspan + '">Preferencje <br/>selekcyjne:</td>'; | |
94 | 118 | for (i = 0; i < frame_description.display.preferences.length; i++) { |
95 | 119 | for (j = 0; j < frame_description.display.preferences[i].length; j++) { |
96 | 120 | display += '<td id="' + frame_description.display.preferences[i][j].csv_id + '" class="' + frame_description.display.preferences[i][j].csv_class + '" onclick="frameClick(\'' + frame_description.display.preferences[i][j].csv_id + '\', \'' + frame_description.display.preferences[i][j].csv_class + '\')">'; |
... | ... | @@ -294,6 +318,14 @@ function changeUnits(frame_id, units) { |
294 | 318 | |
295 | 319 | frames_operations.push({operation: "change_units", frame_id: frame_id, units: units}); |
296 | 320 | } |
321 | + | |
322 | +function setOpinion(frame_id, opinion) { | |
323 | + var id = "" + frame_id; | |
324 | + | |
325 | + frame_content[frame_id].status = semantic_opinion_vals[opinion]; | |
326 | + | |
327 | + frames_operations.push({operation: "set_opinion", frame_id: frame_id, opinion: opinion[0]}); | |
328 | +} | |
297 | 329 | |
298 | 330 | function isNewPreference(frame_id, complement_id, preference) { |
299 | 331 | |
... | ... |
semantics/static/js/semantics_view.js
... | ... | @@ -417,6 +417,49 @@ function changeLexicalUnits() { |
417 | 417 | |
418 | 418 | } |
419 | 419 | |
420 | +function changeOpinion() { | |
421 | + | |
422 | + var change_opinion = { | |
423 | + state0: { | |
424 | + title: 'Ustawianie statusu ramy', | |
425 | + html: getStatusesForFrame(highlighted_id), | |
426 | + buttons: { "Anuluj": -1, "Potwierdź": 1 }, | |
427 | + focus: 1, | |
428 | + submit:function(e,v,m,f){ | |
429 | + e.preventDefault(); | |
430 | + if (v == -1) { | |
431 | + $.prompt.close(); | |
432 | + } | |
433 | + if (v == 1) { | |
434 | + | |
435 | + var opinion = normalizeFormData(f.opinion); | |
436 | + if (opinion.length > 0) { | |
437 | + | |
438 | + var a = semantics_selected_id; | |
439 | + setOpinion(highlighted_id, opinion); | |
440 | + frameClick(""); | |
441 | + displayFrames(); | |
442 | + frameClick(a); | |
443 | + | |
444 | + $.prompt.close(); | |
445 | + | |
446 | + } else { | |
447 | + | |
448 | + alert("Nie wybrano żadnego statusu"); | |
449 | + | |
450 | + } | |
451 | + } | |
452 | + } | |
453 | + }, | |
454 | + }; | |
455 | + if (change == true) { | |
456 | + alertSemantics(); | |
457 | + } else { | |
458 | + $.prompt(change_opinion); | |
459 | + } | |
460 | + | |
461 | +} | |
462 | + | |
420 | 463 | // assign role to selected complement |
421 | 464 | function assignRole() { |
422 | 465 | |
... | ... | @@ -725,6 +768,7 @@ function frameClick(clicked_id) { |
725 | 768 | $('#add_preference').attr('disabled', "True"); |
726 | 769 | $('#delete').attr('disabled', "True"); |
727 | 770 | $('#change_lus').attr('disabled', "True"); |
771 | + $('#change_opinion').attr('disabled', "True"); | |
728 | 772 | } else { |
729 | 773 | select(frame_id, clicked_id); |
730 | 774 | highlighted_id = frame_id; |
... | ... | @@ -735,6 +779,7 @@ function frameClick(clicked_id) { |
735 | 779 | $('#add_preference').attr('disabled', "True"); |
736 | 780 | $('#delete').removeAttr('disabled'); |
737 | 781 | $('#change_lus').removeAttr('disabled'); |
782 | + $('#change_opinion').removeAttr('disabled'); | |
738 | 783 | } |
739 | 784 | } else { // argument click |
740 | 785 | frame_id = clicked_id.split('_')[1] |
... | ... | @@ -751,6 +796,7 @@ function frameClick(clicked_id) { |
751 | 796 | $('#add_preference').attr('disabled', "True"); |
752 | 797 | $('#delete').attr('disabled', "True"); |
753 | 798 | $('#change_lus').attr('disabled', "True"); |
799 | + $('#change_opinion').attr('disabled', "True"); | |
754 | 800 | } else { |
755 | 801 | select(frame_id, clicked_id); |
756 | 802 | |
... | ... | @@ -767,6 +813,7 @@ function frameClick(clicked_id) { |
767 | 813 | $('#add_preference').removeAttr('disabled'); |
768 | 814 | $('#delete').removeAttr('disabled'); |
769 | 815 | $('#change_lus').removeAttr('disabled'); |
816 | + $('#change_opinion').removeAttr('disabled'); | |
770 | 817 | } |
771 | 818 | } |
772 | 819 | } |
... | ... |
semantics/templates/semantics.html
... | ... | @@ -36,13 +36,16 @@ |
36 | 36 | |
37 | 37 | $.getJSON(ajax_roles, function(data){ |
38 | 38 | memorizeRoles(data.roles_display); |
39 | - $.getJSON(ajax_frames, {lemma_id: {{ lemma.id }}}, function(data){ | |
40 | - getFrames(data.frames_display); | |
41 | - displayFrames(); | |
42 | - memorizeConnections(data.connections.connected, data.connections.connected_reverse); | |
43 | - alternationCounts(data.alternations); | |
44 | - $("#semantic-frames-count").empty(); | |
45 | - $("#semantic-frames-count").append(data.frames_count); | |
39 | + $.getJSON(ajax_opinions, {lemma_id: {{ lemma.id }}}, function(data){ | |
40 | + memorizeOpinions(data.opinions); | |
41 | + $.getJSON(ajax_frames, {lemma_id: {{ lemma.id }}}, function(data){ | |
42 | + getFrames(data.frames_display); | |
43 | + displayFrames(); | |
44 | + memorizeConnections(data.connections.connected, data.connections.connected_reverse); | |
45 | + alternationCounts(data.alternations); | |
46 | + $("#semantic-frames-count").empty(); | |
47 | + $("#semantic-frames-count").append(data.frames_count); | |
48 | + }); | |
46 | 49 | }); |
47 | 50 | }); |
48 | 51 | |
... | ... | @@ -96,10 +99,14 @@ |
96 | 99 | </div> |
97 | 100 | <div id="select_creating"> |
98 | 101 | <button type="button" onclick="createFrame()" id="create_frame">Nowa rama</button> |
99 | - <button type="button" onclick="addSelectivePreference()" id="add_preference" disabled="True">Dodaj preferencje</button> | |
102 | + <button type="button" onclick="removeFromFrame()" id="delete" disabled="True">Usuń</button> | |
103 | + <br/> | |
100 | 104 | <button type="button" onclick="changeLexicalUnits()" id="change_lus" disabled="True">Zmień jednostki</button> |
105 | + <button type="button" onclick="changeOpinion()" id="change_opinion" disabled="True">Ustaw ocenę</button> | |
106 | + <br/> | |
101 | 107 | <button type="button" onclick="assignRole()" id="assign_role" disabled="True">Zmień rolę</button> |
102 | - <button type="button" onclick="removeFromFrame()" id="delete" disabled="True">Usuń</button> | |
108 | + <button type="button" onclick="addSelectivePreference()" id="add_preference" disabled="True">Dodaj preferencje</button> | |
109 | + <br/> | |
103 | 110 | <button type="button" onclick="saveFrames()" id="save_frames">Zapisz</button> |
104 | 111 | </div> |
105 | 112 | </div> |
... | ... |
semantics/views.py
... | ... | @@ -5,7 +5,7 @@ from semantics.models import SemanticRole, SemanticFrame, Complement, \ |
5 | 5 | LexicalUnit, FrameRankings, SemanticRolesDisplay, \ |
6 | 6 | LexicalUnitExamples, FramePosition, SelectivePreference, \ |
7 | 7 | RelationalSelectivePreference, SelectivePreferenceRelations, \ |
8 | - GeneralSelectivePreference | |
8 | + GeneralSelectivePreference, FrameOpinion | |
9 | 9 | from dictionary.models import Frame_Char_Model, Lemma, Lemma_Status, \ |
10 | 10 | sort_arguments, sort_positions, NKJP_Example, \ |
11 | 11 | Frame, Position, Argument |
... | ... | @@ -37,6 +37,7 @@ def ajax_semantics(request, id): |
37 | 37 | 'ajax_schemas': reverse('ajax_schemas'), |
38 | 38 | 'ajax_units': reverse('ajax_units'), |
39 | 39 | 'ajax_roles': reverse('ajax_roles'), |
40 | + 'ajax_opinions': reverse('ajax_opinions'), | |
40 | 41 | 'ajax_create_frame': reverse('ajax_create_frame'), |
41 | 42 | 'ajax_create_complement': reverse('ajax_create_complement'), |
42 | 43 | 'ajax_examples': reverse('ajax_examples'), |
... | ... | @@ -164,7 +165,11 @@ def ajax_frames(request, lemma_id): |
164 | 165 | frame_preferences.append([{'csv_id': i, 'csv_class': c, 'preference': p} for i, c, p in zip(idents, frame_ids, row)]) |
165 | 166 | |
166 | 167 | 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}) | |
168 | + if frame.opinion is None: | |
169 | + status = u'brak' | |
170 | + else: | |
171 | + status = frame.opinion.value | |
172 | + frame_display["frames"].append({"frame_id": str(frame.id), "colspan": str(max(len(frame_roles), 1)), "rowspan": str(frame_preferences_rowspan), "status": status, "display": display}) | |
168 | 173 | |
169 | 174 | for complement, complement_class in zip(frame_complements, frame_ids): |
170 | 175 | if complement_class not in complement_arguments: |
... | ... | @@ -263,6 +268,18 @@ def ajax_relations(request): |
263 | 268 | |
264 | 269 | return context |
265 | 270 | |
271 | +@render('opinions.json') | |
272 | +@ajax(method='get', encode_result=False) | |
273 | +def ajax_opinions(request): | |
274 | + | |
275 | + opinions = [{"id": opinion.short, "name": opinion.value} for opinion in FrameOpinion.objects.all().order_by('priority')] | |
276 | + | |
277 | + context = { | |
278 | + 'opinions': opinions, | |
279 | + } | |
280 | + | |
281 | + return context | |
282 | + | |
266 | 283 | @render('roles.json') |
267 | 284 | @ajax(method='get', encode_result=False) |
268 | 285 | def ajax_roles(request): |
... | ... | @@ -616,6 +633,13 @@ def ajax_modify_frames(request, operations, lemma_id): |
616 | 633 | frame_id = int(operation['frame_id']) |
617 | 634 | luids = [int(m) for m in operation['units']] |
618 | 635 | change_units(frame_id, luids) |
636 | + elif operation['operation'] == "set_opinion": | |
637 | + if int(operation['frame_id']) in translation['frame_id']: | |
638 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
639 | + else: | |
640 | + frame_id = int(operation['frame_id']) | |
641 | + opinion = operation['opinion'] | |
642 | + set_opinion(frame_id, opinion) | |
619 | 643 | elif operation['operation'] == "add_preference": |
620 | 644 | # {operation: 'add_preference', frame_id: frame_id, complement_id: complement_id, preference_id: preference_id, preference: preference} |
621 | 645 | if int(operation['frame_id']) in translation['frame_id']: |
... | ... | @@ -664,6 +688,12 @@ def change_units(frame_id, luids): |
664 | 688 | lu = LexicalUnit.objects.get(id=id) |
665 | 689 | frame.lexical_units.add(lu) |
666 | 690 | |
691 | +def set_opinion(frame_id, opinion): | |
692 | + frame = SemanticFrame.objects.get(id=frame_id) | |
693 | + frame_opinion = FrameOpinion.objects.get(short=opinion) | |
694 | + frame.opinion = frame_opinion | |
695 | + frame.save() | |
696 | + | |
667 | 697 | def remove_frame(frame_id): |
668 | 698 | frame = SemanticFrame.objects.get(id=frame_id) |
669 | 699 | frame.removed = True |
... | ... |