Skip to content
Snippets Groups Projects
Commit 266378e6 authored by dcz's avatar dcz
Browse files

Correct slowal frame argument display (unification view).

Replace slowal frame argument position.
Slowal frame status change implementation.
parent 3e797193
No related branches found
No related tags found
No related merge requests found
"use strict"; "use strict";
var unified_view_frame_content; var unified_view_frame_content;
var curr_unified_frame;
function change_slowal2unified_fram_argument_mapping(slowal_frame_id) {
var argument_ids = [];
$('.argument.active').each(function() {
var id = $(this).data('argument_id').split('-')[1];
if(id.startsWith('_')) {
id = -parseInt(id.split('_')[1])
} else {
id = parseInt(id)
}
argument_ids.push(id);
});
var choosed_slowal_frame_id = null;
$('.frame.active').each(function() {
choosed_slowal_frame_id = $(this).data('frame_id');
});
if(choosed_slowal_frame_id == slowal_frame_id && argument_ids.length == 2) {
change_slowal2unified_fram_argument_mapping_post(curr_unified_frame.id, choosed_slowal_frame_id, argument_ids);
get_unified_frame(curr_unified_frame.id);
}
}
function frames2dom_unidief_view(frames) {
var fragment = document.createDocumentFragment();
for (var i in frames) {
let frameDiv = frame2dom(frames[i]);
var table = document.createElement('table');
table.className = 'table m-0 table-borderless border border-secondary text-dark';
var tbody = document.createElement('tbody');
// roles and selectional preferences
var roles_row = document.createElement('tr');
var frame_col = document.createElement('th');
frame_col.scope = 'row';
frame_col.class = 'py-0 px-1 text-secondary';
frame_col.append(frameDiv)
var button_col = document.createElement('th');
button_col.scope = 'row';
button_col.class = 'py-0 px-1 text-secondary';
var button_col_div = document.createElement('div');
button_col_div.innerHTML = '<div class="custom-control custom-checkbox">\n' +
' <input type="checkbox" id="defaultUnchecked" class="custom-control-input" '+(frames[i].verified ? 'checked' : '')+' onclick="change_slowal2unified_mapping_verification('+frames[i].id+', this.checked)">\n' +
' <label class="custom-control-label" for="defaultUnchecked">Zweryfikowane</label>\n' +
' <br><br>' +
' <a href="#" class="btn btn-sm btn-dark" role="button" onclick="change_slowal2unified_fram_argument_mapping('+frames[i].id+')">Z</a>' +
'</div>';
button_col.append(button_col_div);
roles_row.append(frame_col);
roles_row.append(button_col);
tbody.append(roles_row);
table.append(tbody);
fragment.append(table);
}
if (fragment.childNodes.length === 0) {
return '<p>(' + gettext('brak ram') + ')</p>';
}
return fragment;
}
function show_semantics_unified_view(frames, subentries) {
$('#semantics-no-examples').hide();
var schemata_dom = subentries2dom(subentries);
$('#semantics-schemata').append($(schemata_dom));
var frames_dom = frames2dom_unidief_view(frames);
$('#semantics-frames').append($(frames_dom));
$('.frame').mouseenter(function() {
var frame = $(this);
if (!frame.hasClass('active')) {
$(this).addClass('highlight bg-highlight');
show_info(gettext('Kliknij, aby wyświetlić przykłady dla tej ramy oraz jej realizacje składniowe.'));
}
}).mouseleave(function() {
$(this).removeClass('highlight bg-highlight');
clear_info();
}).click(function() {
var frame = $(this);
if (!frame.hasClass('active')) {
select_frame(frame);
}
clear_info();
});
$('.lu-plwn, .synset-plwn').click(function(event) {
// don’t make link click select the frame
event.stopPropagation();
});
// if there’s one frame, select it immediately
if ($('.frame').length === 1) {
select_frame($('.frame').first());
}
// if there’s no frames, disable the tab
if ($('.frame').length === 0) {
$('#semantics-tab').addClass('disabled');
} else {
$('#semantics-tab').removeClass('disabled');
}
}
function change_slowal2unified_fram_argument_mapping_post(unified_frame_id, slowal_frame_id, slowal_frame_selected_arguments) {
check_import_status();
show_entry_spinners();
var data = { 'unified_frame_id' : unified_frame_id, 'slowal_frame_id' : slowal_frame_id, 'slowal_frame_selected_arguments' : JSON.stringify(slowal_frame_selected_arguments) };
$.ajax({
type : 'post',
url : '/' + lang + '/unifier/change_slowal2unified_fram_argument_mapping/',
dataType : 'json',
data : data,
timeout : 60000,
success : function(response) {
},
error: function(request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
}
});
}
function change_slowal2unified_mapping_verification(slowal_frame_id, verified) {
check_import_status();
show_entry_spinners();
var data = { 'unified_frame_id' : curr_unified_frame.id, 'slowal_frame_id' : slowal_frame_id, 'verified' : verified };
$.ajax({
type : 'post',
url : '/' + lang + '/unifier/change_slowal2unified_mapping_verification/',
dataType : 'json',
data : data,
timeout : 60000,
success : function(response) {
},
error: function(request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
}
});
}
function get_unified_frame(unified_frame_id, related) { function get_unified_frame(unified_frame_id, related) {
check_import_status(); check_import_status();
...@@ -15,7 +165,8 @@ function get_unified_frame(unified_frame_id, related) { ...@@ -15,7 +165,8 @@ function get_unified_frame(unified_frame_id, related) {
data : data, data : data,
timeout : 60000, timeout : 60000,
success : function(response) { success : function(response) {
unified_view_frame_content = response.frames; curr_unified_frame = response.unified_frame;
unified_view_frame_content = response.frames
curr_entry = unified_frame_id; curr_entry = unified_frame_id;
curr_no_filters = related; curr_no_filters = related;
clear_info(); clear_info();
...@@ -30,7 +181,8 @@ function get_unified_frame(unified_frame_id, related) { ...@@ -30,7 +181,8 @@ function get_unified_frame(unified_frame_id, related) {
// show_syntax(response.subentries); // show_syntax(response.subentries);
show_unified_frame(response.unified_frame, response.frames) show_unified_frame(response.unified_frame, response.frames)
show_unified_frame_lexical_units(response.frames) show_unified_frame_lexical_units(response.frames)
show_semantics(response.frames, response.subentries); fulfill_slowal_frames_arguments_with_empty_elems(response.unified_frame, response.frames)
show_semantics_unified_view(response.frames, response.subentries);
// show_unmatched_examples(); // show_unmatched_examples();
// if current tab is empty, switch to an active tab // if current tab is empty, switch to an active tab
...@@ -80,6 +232,38 @@ function slowal_frames2selecional_preferencies(unified_frame, slowal_frames) { ...@@ -80,6 +232,38 @@ function slowal_frames2selecional_preferencies(unified_frame, slowal_frames) {
return unified_argument_2_selecional_preferencies; return unified_argument_2_selecional_preferencies;
} }
function fulfill_slowal_frames_arguments_with_empty_elems(unified_frame, slowal_frames) {
for (var i in unified_frame.slowal_frame_mapping) {
var slowal_frame_mapping = unified_frame.slowal_frame_mapping[i];
let slowal_frame = slowal_frames.find(o => o.id === slowal_frame_mapping.slowal_frame_id);
let new_slowal_frame_arguments = [];
for (var j in unified_frame.arguments) {
var unified_frame_argument = unified_frame.arguments[j];
let unified_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping.find(o => o.unified_frame_agrument_id === unified_frame_argument.id);
let slowal_frame_argument = null;
if(unified_frame_argument_mapping == null) {
slowal_frame_argument = {
'str' : 'Empty',
'id' : slowal_frame.id+'-_'+(unified_frame_argument.id),
'role' : 'Empty',
'role_type' : 'Empty',
'preferences' : [],
'proposed_roles': [],
}
} else {
slowal_frame_argument = slowal_frame.arguments.find(o => o.argument_id === unified_frame_argument_mapping.slowal_frame_agrument_id);
}
new_slowal_frame_arguments.push(slowal_frame_argument)
}
slowal_frame.arguments = new_slowal_frame_arguments;
}
}
function unifiedFrame2dom(unifiedFrame, slowal_frames) { function unifiedFrame2dom(unifiedFrame, slowal_frames) {
var div = document.createElement('div'); var div = document.createElement('div');
div.className = 'unifiedFrame mb-3'; div.className = 'unifiedFrame mb-3';
......
...@@ -107,6 +107,7 @@ class UnifiedRelationalSelectionalPreference(models.Model): ...@@ -107,6 +107,7 @@ class UnifiedRelationalSelectionalPreference(models.Model):
class UnifiedFrame2SlowalFrameMapping(models.Model): class UnifiedFrame2SlowalFrameMapping(models.Model):
verified = models.BooleanField(default=False)
unified_frame = models.ForeignKey(UnifiedFrame, related_name='unified_frame_2_slowal_frame', on_delete=models.PROTECT) unified_frame = models.ForeignKey(UnifiedFrame, related_name='unified_frame_2_slowal_frame', on_delete=models.PROTECT)
slowal_frame = models.OneToOneField(Frame, related_name='slowal_frame_2_unified_frame', on_delete=models.PROTECT) slowal_frame = models.OneToOneField(Frame, related_name='slowal_frame_2_unified_frame', on_delete=models.PROTECT)
......
...@@ -11,5 +11,8 @@ urlpatterns = [ ...@@ -11,5 +11,8 @@ urlpatterns = [
path('get_unified_frames/', views.get_unified_frames, name='get_unified_frames'), 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('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'), path('extract_frames_to_new_frame/', views.extract_frames_to_new_frame, name='extract_frames_to_new_frame'),
path('change_slowal2unified_fram_argument_mapping/', views.change_slowal2unified_fram_argument_mapping, name='change_slowal2unified_fram_argument_mapping'),
path('change_slowal2unified_mapping_verification/', views.change_slowal2unified_mapping_verification, name='change_slowal2unified_mapping_verification'),
] ]
...@@ -8,7 +8,7 @@ from entries.views import get_scroller_params, get_alternations, get_prefs_list, ...@@ -8,7 +8,7 @@ from entries.views import get_scroller_params, get_alternations, get_prefs_list,
from semantics.models import Frame from semantics.models import Frame
from syntax.models import Schema from syntax.models import Schema
from unifier.models import UnifiedFrameArgument, UnifiedRelationalSelectionalPreference, UnifiedFrame, \ from unifier.models import UnifiedFrameArgument, UnifiedRelationalSelectionalPreference, UnifiedFrame, \
UnifiedFrame2SlowalFrameMapping UnifiedFrame2SlowalFrameMapping, UnifiedFrameArgumentSlowalFrameMapping
@ajax_required @ajax_required
...@@ -157,11 +157,20 @@ def get_examples(frames): ...@@ -157,11 +157,20 @@ def get_examples(frames):
def get_unified_frame_json(unifiedFrame, request): def get_unified_frame_json(unifiedFrame, request):
slowal_frames = [connection.slowal_frame for connection in unifiedFrame.unified_frame_2_slowal_frame.all()] slowal_frames_and_verified = [(connection.slowal_frame, connection.verified) for connection in unifiedFrame.unified_frame_2_slowal_frame.all()]
slowal_frames = [tuple[0] for tuple in slowal_frames_and_verified]
all_schema_objects = Schema.objects.filter(schema_hooks__argument_connections__argument__frame__in=slowal_frames).distinct() 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] slowal_frames_dict = []
for slowal_frame_and_verified in slowal_frames_and_verified:
slowal_frame = slowal_frame_and_verified[0]
verified = slowal_frame_and_verified[1]
dict = frame2dict(slowal_frame, slowal_frame.lexical_units.all())
dict['verified'] = verified
slowal_frames_dict.append(dict)
alternations, realisation_phrases, realisation_descriptions = get_alternations(all_schema_objects, slowal_frames) alternations, realisation_phrases, realisation_descriptions = get_alternations(all_schema_objects, slowal_frames)
examples = get_examples(slowal_frames) examples = get_examples(slowal_frames)
...@@ -205,3 +214,53 @@ def extract_frames_to_new_frame(request): ...@@ -205,3 +214,53 @@ def extract_frames_to_new_frame(request):
new_frame_fullfiled_and_saved = unified_frame.extract_frames_to(slowal_frames=slowal_frames, new_frame=new_unified_frame) 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(get_unified_frame_json(new_frame_fullfiled_and_saved, request))
return JsonResponse({}) return JsonResponse({})
@ajax_required
def change_slowal2unified_fram_argument_mapping(request):
if request.method == 'POST':
unified_frame_id = request.POST['unified_frame_id']
slowal_frame_id = request.POST['slowal_frame_id']
slowal_frame_selected_arguments = json.loads(request.POST['slowal_frame_selected_arguments'])
unifiedFrame2SlowalFrameMapping = UnifiedFrame2SlowalFrameMapping.objects.get(unified_frame_id=unified_frame_id, slowal_frame=slowal_frame_id)
arg1_id = int(slowal_frame_selected_arguments[0])
arg2_id = int(slowal_frame_selected_arguments[1])
unifiedFrameArgumentMapping1 = UnifiedFrameArgumentSlowalFrameMapping.objects.get(unified_frame_mapping=unifiedFrame2SlowalFrameMapping,
slowal_agrument_id=arg1_id) if arg1_id >= 0 else None
unifiedFrameArgumentMapping2 = UnifiedFrameArgumentSlowalFrameMapping.objects.get(unified_frame_mapping=unifiedFrame2SlowalFrameMapping,
slowal_agrument_id=arg2_id) if arg2_id >= 0 else None
if unifiedFrameArgumentMapping1 is not None and unifiedFrameArgumentMapping2 is not None:
#mamy oba argumenty, zamieniamy miescami
unifiedFrameArgumentMapping1.slowal_agrument_id = arg2_id
unifiedFrameArgumentMapping2.slowal_agrument_id = arg1_id
unifiedFrameArgumentMapping1.save()
unifiedFrameArgumentMapping2.save()
elif unifiedFrameArgumentMapping1 is not None and unifiedFrameArgumentMapping2 is None:
#mamy lewy argument, prawy jest Empty
unifiedFrameArgumentMapping1.unified_agrument_id = -arg2_id
unifiedFrameArgumentMapping1.save()
elif unifiedFrameArgumentMapping1 is None and unifiedFrameArgumentMapping2 is not None:
#mamy prawy argument, lewy jest Empty
unifiedFrameArgumentMapping2.unified_agrument_id = -arg1_id
unifiedFrameArgumentMapping2.save()
return JsonResponse({})
return JsonResponse({})
@ajax_required
def change_slowal2unified_mapping_verification(request):
if request.method == 'POST':
unified_frame_id = request.POST['unified_frame_id']
slowal_frame_id = request.POST['slowal_frame_id']
verified = request.POST['verified']
unifiedFrame2SlowalFrameMapping = UnifiedFrame2SlowalFrameMapping.objects.get(unified_frame_id=unified_frame_id, slowal_frame=slowal_frame_id)
unifiedFrame2SlowalFrameMapping.verified = True if verified == 'true' else False
unifiedFrame2SlowalFrameMapping.save()
return JsonResponse({})
return JsonResponse({})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment