diff --git a/common/migrations/__init__.py b/common/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/connections/migrations/__init__.py b/connections/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/entries/static/entries/js/unification.js b/entries/static/entries/js/unification.js index 7dc4e68bd05c398c08aba98eaef7ab7ea9ae436e..3869d824b5fa16579782e6d5f239fdf7802c1523 100644 --- a/entries/static/entries/js/unification.js +++ b/entries/static/entries/js/unification.js @@ -221,3 +221,25 @@ function show_unified_frame_lexical_units(frames) { $('#unified-frame-lexical-units').empty(); $('#unified-frame-lexical-units').append($(lexical_units_dom)); } + +function extract_frames_to_new_frame(unified_frame_id, slowal_frame_ids, new_unified_frame_id) { + check_import_status(); + clear_entry(); + show_entry_spinners(); + var data = { 'unified_frame_id' : unified_frame_id, 'slowal_frame_ids' : JSON.stringify(slowal_frame_ids), 'new_unified_frame_id': new_unified_frame_id }; + $.ajax({ + type : 'post', + url : '/' + lang + '/unifier/extract_frames_to_new_frame/', + dataType : 'json', + data : data, + timeout : 60000, + success : function(response) { + unified_frame_id = response.unified_frame_id; + + }, + error: function(request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); +} + diff --git a/entries/templates/unification_edit_display.html b/entries/templates/unification_edit_display.html index 9fbd7434b79638ba1b59c9649d77a30bafdcb75d..bae37f41ae2d34c4d9096034d00d1b45118fc0f0 100644 --- a/entries/templates/unification_edit_display.html +++ b/entries/templates/unification_edit_display.html @@ -44,9 +44,66 @@ <br> <div id="unified-frame"></div> <div id="unified-frame-lexical-units"></div> + <br> + <table class="table-button-menu" cellspacing="1"> + <tr style="background-color: white;"> + <td id="wrong-frame" style="padding: 10px 15px 10px 15px; color: #000000;"> + Błędna + </td> + <td id="extract-frame" style="padding: 10px 15px 10px 15px; color: #000000;" + onclick="extract_frames_to_new_frame(1, [1,2], null)"> + Rozdziel + </td> + <td id="hide-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"> + Ukryj + </td> + <td id="ready-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"> + Gotowe + </td> + <td id="filter-slowal-frames" style="padding: 10px 15px 10px 15px; color: #000000;"> + Filtruj + </td> + </tr> + <tr style="background-color: white;"> + <td id="inccorect-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"> + Niepasująca + </td> + <td id="move-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" + onclick="extract_frames_to_new_frame(7, [1], 1)"> + Przerzuć + </td> + <td id="show-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"> + Pokaż + </td> + <td id="reollback-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"> + Przywróć + </td> + <td id="empty" style="padding: 10px 15px 10px 15px; color: #000000;"> + + </td> + </tr> + </table> + <br> <div id="semantics-frames"></div> </div> <div class="col h-100 px-1 pt-0 pb-0 overflow-auto" id="semantics-schemata-pane"> + <ul class="nav nav-pills nav-justified p-1" id="entryTabs" role="tablist"> + <li class="nav-item mr-1"> + <a class="btn btn-sm btn-outline-dark nav-link active" id="unified-frame-semantics-tab" data-toggle="tab" href="#semantics" role="tab" aria-controls="semantics" aria-selected="true"> + {% trans "Schematy" %} + </a> + </li> + <li class="nav-item mr-1"> + <a class="btn btn-sm btn-outline-dark nav-link" id="unified-frame-view2-tab" data-toggle="tab" href="#syntax" role="tab" aria-controls="syntax" aria-selected="false"> + {% trans "Podgląd ram" %} + </a> + </li> + <li class="nav-item mr-0"> + <a class="btn btn-sm btn-outline-dark nav-link" id="unified-frame-notes-tab" data-toggle="tab" href="#examples" role="tab" aria-controls="examples" aria-selected="false"> + {% trans "Notatki" %} + </a> + </li> + </ul> <div id="semantics-schemata"></div> </div> </div> diff --git a/examples/migrations/__init__.py b/examples/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/meanings/migrations/__init__.py b/meanings/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/phrase_expansions/migrations/__init__.py b/phrase_expansions/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/semantics/migrations/__init__.py b/semantics/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/syntax/migrations/__init__.py b/syntax/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/unifier/migrations/__init__.py b/unifier/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/unifier/models.py b/unifier/models.py index 2408c485d44b4c48e57f18d926b75d852a3be946..f9a296732ed15844ff94cf5f356f8ab814c7807f 100644 --- a/unifier/models.py +++ b/unifier/models.py @@ -35,9 +35,46 @@ class UnifiedFrame(models.Model): def extract_frames_to( self, slowal_frames: List[Frame], new_frame: Optional["UnifiedFrame"] = None ) -> "UnifiedFrame": + new_unified_frame_arguments = None if not new_frame: - new_frame = UnifiedFrame.objects.create(title=self.title) - raise NotImplementedError() # TODO move slowal frames to `new_frame` + new_frame = UnifiedFrame.objects.create(title='[Kopia] '+self.title if self.title is not None else '[Kopia]') + new_frame.save() + unified_frame_arguments = UnifiedFrameArgument.objects.filter(unified_frame=self) + cnt = UnifiedFrameArgument.objects.count()+1 + old_2_new_argument_mapping = {} + for unified_frame_argument in unified_frame_arguments: + new_unified_frame_argument = UnifiedFrameArgument.objects.create(id=cnt, + role_type=unified_frame_argument.role_type, + role=unified_frame_argument.role, + unified_frame=new_frame) + new_unified_frame_argument.proposed_roles.set(unified_frame_argument.proposed_roles.all()) + new_unified_frame_argument.save() + old_2_new_argument_mapping[unified_frame_argument.id] = new_unified_frame_argument.id + cnt = cnt + 1 + else: + new_unified_frame_arguments = UnifiedFrameArgument.objects.filter(unified_frame=new_frame).all() + unified_frame_arguments = UnifiedFrameArgument.objects.filter(unified_frame=self).all() + if len(new_unified_frame_arguments) < len(unified_frame_arguments): + raise Exception('Target frame has to little arguments, required: ' + len(unified_frame_arguments)+', but found: '+len(new_unified_frame_arguments)) + + for slowal_frame in slowal_frames: + mapping = UnifiedFrame2SlowalFrameMapping.objects.get(unified_frame=self, slowal_frame=slowal_frame) + mapping.unified_frame = new_frame + mapping.save() + argument_mappings = UnifiedFrameArgumentSlowalFrameMapping.objects.filter(unified_frame_mapping=mapping) + for i, argument_mapping in enumerate(argument_mappings): + if new_unified_frame_arguments is None: + argument_mapping.unified_agrument_id = old_2_new_argument_mapping[argument_mapping.unified_agrument_id] + else: + argument_mapping.unified_agrument_id = new_unified_frame_arguments[i] + argument_mapping.save() + + curr_mapping = UnifiedFrame2SlowalFrameMapping.objects.filter(unified_frame=self).all() + if len(curr_mapping) == 0: + unified_frame_arguments = UnifiedFrameArgument.objects.filter(unified_frame=self).all() + unified_frame_arguments.delete() + self.delete() + return new_frame diff --git a/unifier/urls.py b/unifier/urls.py index e3b88c0cea93b29c7fae835e40aa6e8d938cb715..6902b0925925059f497703fd30fc73e3592aa616 100644 --- a/unifier/urls.py +++ b/unifier/urls.py @@ -10,5 +10,6 @@ urlpatterns = [ path('save_relational_selectional_preference/', views.save_relational_selectional_preference, name='save_relational_selectional_preference'), path('get_unified_frames/', views.get_unified_frames, name='get_unified_frames'), path('get_unified_frame/', views.get_unified_frame, name='get_unified_frame'), + path('extract_frames_to_new_frame/', views.extract_frames_to_new_frame, name='extract_frames_to_new_frame'), ] diff --git a/unifier/views.py b/unifier/views.py index c9426e74851b965d0ce5b4a6e44f720c67060b61..069dc40d30153ff00c8144d6c01e4032695ff673 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -1,8 +1,11 @@ +import json + from django.http import JsonResponse from common.decorators import ajax_required from entries.polish_strings import EXAMPLE_SOURCE, EXAMPLE_OPINION from entries.views import get_scroller_params, get_alternations, get_prefs_list, schema2dict, frame2dict +from semantics.models import Frame from syntax.models import Schema from unifier.models import UnifiedFrameArgument, UnifiedRelationalSelectionalPreference, UnifiedFrame, \ UnifiedFrame2SlowalFrameMapping @@ -152,6 +155,27 @@ def get_examples(frames): examples.append(elem) return sorted(examples, key=lambda x: x['sentence']) +def get_unified_frame_json(unifiedFrame, request): + + slowal_frames = [connection.slowal_frame for connection in unifiedFrame.unified_frame_2_slowal_frame.all()] + + all_schema_objects = Schema.objects.filter(schema_hooks__argument_connections__argument__frame__in=slowal_frames).distinct() + + slowal_frames_dict = [frame2dict(slowal_frame, slowal_frame.lexical_units.all()) for slowal_frame in slowal_frames] + alternations, realisation_phrases, realisation_descriptions = get_alternations(all_schema_objects, slowal_frames) + examples = get_examples(slowal_frames) + + all_schema_objects_dict = [schema2dict(schema, schema.subentries.all()[0].negativity, request.LANGUAGE_CODE) for schema in all_schema_objects] + + subentries = [{ + 'str': None, + 'schemata': all_schema_objects_dict + }] + + unifiedFrame_dict = unifiedFrame2dict(unifiedFrame) + + return { 'unified_frame_id': unifiedFrame.id, 'unified_frame': unifiedFrame_dict, 'subentries': subentries, 'frames' : slowal_frames_dict, 'alternations' : alternations, 'realisation_phrases' : realisation_phrases, 'realisation_descriptions' : realisation_descriptions, 'examples' : examples, 'last_visited' : request.session['last_visited'] } + @ajax_required def get_unified_frame(request): if request.method == 'POST': @@ -161,26 +185,23 @@ def get_unified_frame(request): #TODO (*) if unified_frame_id.isdigit():# and form.is_valid(): unified_frame_id = int(unified_frame_id) - # TODO check that Entry has no import errors + request.session.modified = True unifiedFrame = UnifiedFrame.objects.get(id=unified_frame_id) + return JsonResponse(get_unified_frame_json(unifiedFrame, request)) - slowal_frames = [connection.slowal_frame for connection in unifiedFrame.unified_frame_2_slowal_frame.all()] - - all_schema_objects = Schema.objects.filter(schema_hooks__argument_connections__argument__frame__in=slowal_frames).distinct() - - slowal_frames_dict = [frame2dict(slowal_frame, slowal_frame.lexical_units.all()) for slowal_frame in slowal_frames] - alternations, realisation_phrases, realisation_descriptions = get_alternations(all_schema_objects, slowal_frames) - examples = get_examples(slowal_frames) - - all_schema_objects_dict = [schema2dict(schema, schema.subentries.all()[0].negativity, request.LANGUAGE_CODE) for schema in all_schema_objects] - - subentries = [{ - 'str': None, - 'schemata': all_schema_objects_dict - }] - - unifiedFrame_dict = unifiedFrame2dict(unifiedFrame) + return JsonResponse({}) - request.session.modified = True - return JsonResponse({ 'unified_frame_id': unified_frame_id, 'unified_frame': unifiedFrame_dict, 'subentries': subentries, 'frames' : slowal_frames_dict, 'alternations' : alternations, 'realisation_phrases' : realisation_phrases, 'realisation_descriptions' : realisation_descriptions, 'examples' : examples, 'last_visited' : request.session['last_visited'] }) +@ajax_required +def extract_frames_to_new_frame(request): + if request.method == 'POST': + unified_frame_id = request.POST['unified_frame_id'] + new_unified_frame_id = request.POST['new_unified_frame_id'] + slowal_frame_ids = json.loads(request.POST['slowal_frame_ids']) + unified_frame = UnifiedFrame.objects.get(id=unified_frame_id) + slowal_frames = Frame.objects.filter(id__in=slowal_frame_ids) + new_unified_frame = None + if new_unified_frame_id != '': + new_unified_frame = UnifiedFrame.objects.get(id=new_unified_frame_id) + new_frame_fullfiled_and_saved = unified_frame.extract_frames_to(slowal_frames=slowal_frames, new_frame=new_unified_frame) + return JsonResponse(get_unified_frame_json(new_frame_fullfiled_and_saved, request)) return JsonResponse({}) diff --git a/users/migrations/__init__.py b/users/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391