Commit 56eabc6c5785e69abd8456f5e67e1a9ab6264523
Merge branch 'master' into bartek
Conflicts: semantics/views.py
Showing
8 changed files
with
170 additions
and
18 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/saving.py
| ... | ... | @@ -7,7 +7,7 @@ from semantics.change_log import store_old_versions |
| 7 | 7 | from semantics.models import Complement, GeneralSelectivePreference, FramePosition,\ |
| 8 | 8 | LexicalUnitExamples, RelationalSelectivePreference, \ |
| 9 | 9 | SelectivePreference, SelectivePreferenceRelations, \ |
| 10 | - SemanticFrame, SemanticRole | |
| 10 | + SemanticFrame, SemanticRole, FrameOpinion | |
| 11 | 11 | from wordnet.models import Hypernymy, LexicalUnit, Synonymy, Synset |
| 12 | 12 | |
| 13 | 13 | def modify_frames(lemma_id, operations, user): |
| ... | ... | @@ -93,6 +93,13 @@ def make_operations(operations): |
| 93 | 93 | frame_id = int(operation['frame_id']) |
| 94 | 94 | luids = [int(m) for m in operation['units']] |
| 95 | 95 | change_units(frame_id, luids) |
| 96 | + elif operation['operation'] == "set_opinion": | |
| 97 | + if int(operation['frame_id']) in translation['frame_id']: | |
| 98 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
| 99 | + else: | |
| 100 | + frame_id = int(operation['frame_id']) | |
| 101 | + opinion = operation['opinion'] | |
| 102 | + set_opinion(frame_id, opinion) | |
| 96 | 103 | elif operation['operation'] == "add_preference": |
| 97 | 104 | # {operation: 'add_preference', frame_id: frame_id, complement_id: complement_id, preference_id: preference_id, preference: preference} |
| 98 | 105 | if int(operation['frame_id']) in translation['frame_id']: |
| ... | ... | @@ -204,6 +211,12 @@ def change_units(frame_id, luids): |
| 204 | 211 | lu = LexicalUnit.objects.get(id=id) |
| 205 | 212 | frame.lexical_units.add(lu) |
| 206 | 213 | |
| 214 | +def set_opinion(frame_id, opinion): | |
| 215 | + frame = SemanticFrame.objects.get(id=frame_id) | |
| 216 | + frame_opinion = FrameOpinion.objects.get(short=opinion) | |
| 217 | + frame.opinion = frame_opinion | |
| 218 | + frame.save() | |
| 219 | + | |
| 207 | 220 | # preference_id = add_preference(frame_id, complement_id, operation['preference']['type'], operation['preference']['content']) |
| 208 | 221 | def add_preference(frame_id, complement_id, preference_type, preference_content): |
| 209 | 222 | |
| ... | ... |
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 | |
| ... | ... | @@ -73,11 +76,9 @@ |
| 73 | 76 | <div id="semantics-vsplit-top"> |
| 74 | 77 | |
| 75 | 78 | <div id="frames"> |
| 76 | - Trwa ładowanie... | |
| 77 | 79 | </div> |
| 78 | 80 | |
| 79 | 81 | <div id="schemas"> |
| 80 | - Trwa ładowanie... | |
| 81 | 82 | </div> |
| 82 | 83 | |
| 83 | 84 | </div> |
| ... | ... | @@ -96,10 +97,14 @@ |
| 96 | 97 | </div> |
| 97 | 98 | <div id="select_creating"> |
| 98 | 99 | <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> | |
| 100 | + <button type="button" onclick="removeFromFrame()" id="delete" disabled="True">Usuń</button> | |
| 101 | + <br/> | |
| 100 | 102 | <button type="button" onclick="changeLexicalUnits()" id="change_lus" disabled="True">Zmień jednostki</button> |
| 103 | + <button type="button" onclick="changeOpinion()" id="change_opinion" disabled="True">Ustaw ocenę</button> | |
| 104 | + <br/> | |
| 101 | 105 | <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> | |
| 106 | + <button type="button" onclick="addSelectivePreference()" id="add_preference" disabled="True">Dodaj preferencje</button> | |
| 107 | + <br/> | |
| 103 | 108 | <button type="button" onclick="saveFrames()" id="save_frames">Zapisz</button> |
| 104 | 109 | </div> |
| 105 | 110 | </div> |
| ... | ... |
semantics/views.py
| ... | ... | @@ -3,7 +3,8 @@ |
| 3 | 3 | from semantics.models import SemanticRole, SemanticFrame, Complement, \ |
| 4 | 4 | LexicalUnit, FrameRankings, SemanticRolesDisplay, \ |
| 5 | 5 | LexicalUnitExamples, SelectivePreferenceRelations, \ |
| 6 | - GeneralSelectivePreference | |
| 6 | + GeneralSelectivePreference, FrameOpinion | |
| 7 | + | |
| 7 | 8 | from dictionary.models import Frame_Char_Model, Lemma, Lemma_Status, \ |
| 8 | 9 | sort_arguments, sort_positions |
| 9 | 10 | from dictionary.ajax_lemma_view import user_can_modify |
| ... | ... | @@ -31,6 +32,7 @@ def ajax_semantics(request, id): |
| 31 | 32 | 'ajax_schemas': reverse('ajax_schemas'), |
| 32 | 33 | 'ajax_units': reverse('ajax_units'), |
| 33 | 34 | 'ajax_roles': reverse('ajax_roles'), |
| 35 | + 'ajax_opinions': reverse('ajax_opinions'), | |
| 34 | 36 | 'ajax_create_frame': reverse('ajax_create_frame'), |
| 35 | 37 | 'ajax_create_complement': reverse('ajax_create_complement'), |
| 36 | 38 | 'ajax_examples': reverse('ajax_examples'), |
| ... | ... | @@ -158,7 +160,11 @@ def ajax_frames(request, lemma_id): |
| 158 | 160 | frame_preferences.append([{'csv_id': i, 'csv_class': c, 'preference': p} for i, c, p in zip(idents, frame_ids, row)]) |
| 159 | 161 | |
| 160 | 162 | display = {"roles": frame_roles, "preferences": frame_preferences} |
| 161 | - 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}) | |
| 163 | + if frame.opinion is None: | |
| 164 | + status = u'brak' | |
| 165 | + else: | |
| 166 | + status = frame.opinion.value | |
| 167 | + 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}) | |
| 162 | 168 | |
| 163 | 169 | for complement, complement_class in zip(frame_complements, frame_ids): |
| 164 | 170 | if complement_class not in complement_arguments: |
| ... | ... | @@ -257,6 +263,18 @@ def ajax_relations(request): |
| 257 | 263 | |
| 258 | 264 | return context |
| 259 | 265 | |
| 266 | +@render('opinions.json') | |
| 267 | +@ajax(method='get', encode_result=False) | |
| 268 | +def ajax_opinions(request): | |
| 269 | + | |
| 270 | + opinions = [{"id": opinion.short, "name": opinion.value} for opinion in FrameOpinion.objects.all().order_by('priority')] | |
| 271 | + | |
| 272 | + context = { | |
| 273 | + 'opinions': opinions, | |
| 274 | + } | |
| 275 | + | |
| 276 | + return context | |
| 277 | + | |
| 260 | 278 | @render('roles.json') |
| 261 | 279 | @ajax(method='get', encode_result=False) |
| 262 | 280 | def ajax_roles(request): |
| ... | ... |