From ac9edb28faff6c08c15ecfcdf126a181f4d35b77 Mon Sep 17 00:00:00 2001 From: Bartłomiej Nitoń <bartomiej@raven.(none)> Date: Wed, 9 Dec 2015 10:21:29 +0100 Subject: [PATCH] Added multi positions message in syntactic validation. --- common/js_to_obj.py | 3 ++- dictionary/ajax_lemma_view.py | 3 ++- dictionary/saving.py | 10 ++++++---- dictionary/static/js/argument_form_utils.js | 4 ++-- dictionary/validation.py | 24 ++++++++++++++++++++++++ semantics/models.py | 11 +++++++++++ semantics/validation.py | 13 +++++-------- 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/common/js_to_obj.py b/common/js_to_obj.py index 3ed916e..ddf7a02 100644 --- a/common/js_to_obj.py +++ b/common/js_to_obj.py @@ -43,7 +43,8 @@ def jsFrameToObj(frame, lemma_entry): for position in frame['positions']: if len(position['arguments']) > 0: pos_obj = jsPosToObj(position) - positions_objs.append(pos_obj) + positions_objs.append(pos_obj) + position['id'] = pos_obj.id sorted_positions = [] sorted_pos_dict = sortPositions(positions_objs) diff --git a/dictionary/ajax_lemma_view.py b/dictionary/ajax_lemma_view.py index 09b0c24..110fd98 100644 --- a/dictionary/ajax_lemma_view.py +++ b/dictionary/ajax_lemma_view.py @@ -59,7 +59,7 @@ from dictionary.validation import find_similar_frames, get_all_test_missing_fram get_wrong_aspect_frames, validate_B_frames, get_deriv_miss_frames_message, \ validate_phraseology_binded_frames, validate_rule_5, \ validate_examples_and_mark_errors, validate_schemas_and_mark_errors, \ - get_missing_aspects_msg + get_missing_aspects_msg, validate_same_positions_schemata from semantics.models import LexicalUnitExamples @@ -2650,6 +2650,7 @@ def validate_new_frames(request, data, id, examples, lemma_examples, message_content += u'\t- %s\n' % (miss_frame.text_rep) message_content += '\n' message_content += deriv_miss_frames_msg + message_content += validate_same_positions_schemata(old_object) frames_to_merge = find_similar_frames(old_object.frames.all()) if len(frames_to_merge) > 0: message_content += u'Sugerowane jest połączenie poniższych schematów, zawierają one często koordynujące się typy fraz:\n' diff --git a/dictionary/saving.py b/dictionary/saving.py index f5a552c..11eb61e 100644 --- a/dictionary/saving.py +++ b/dictionary/saving.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from common.js_to_obj import jsPosToObj -from dictionary.models import Argument +from dictionary.models import Argument, Position from semantics.models import Complement, LexicalUnitExamples from semantics.saving import modify_frames, update_meanings from wordnet.models import LexicalUnit @@ -21,7 +21,8 @@ def get_semantic_operations(lemma, schemata_conversions): def get_reconnect_operations_and_extend_connections(connections, schema, js_schema): operations = [] for js_position in js_schema['positions']: - position = jsPosToObj(js_position) + #position = jsPosToObj(js_position) + position = schema.positions.get(id=js_position['id']) for js_phrase_type in js_position['arguments']: phrase_type = Argument.objects.get(id=js_phrase_type['id']) new_connection_target = {'schema': schema, @@ -46,10 +47,11 @@ def reconnect_operations(connection, new_target): realization = compl.realizations.get(id=real_id) old_phrase_type_ref = create_phrase_type_ref(realization.frame, realization.position, realization.argument, realization.alternation) - operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref)) new_phrase_type_ref = create_phrase_type_ref(new_target['schema'], new_target['position'], new_target['phrase_type'], realization.alternation) - operations.append(create_operation('connect', arg_ref, new_phrase_type_ref)) + if new_phrase_type_ref != old_phrase_type_ref: + operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref)) + operations.append(create_operation('connect', arg_ref, new_phrase_type_ref)) return operations def create_argument_ref(complement): diff --git a/dictionary/static/js/argument_form_utils.js b/dictionary/static/js/argument_form_utils.js index a6e2723..86a807b 100644 --- a/dictionary/static/js/argument_form_utils.js +++ b/dictionary/static/js/argument_form_utils.js @@ -11,14 +11,14 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ // argument class -function argument(id, text_rep, type, complements) +function argument(id, text_rep, type, connections) { this.id = id this.text_rep = text_rep; this.type = type; this.error = false; this.tooltip = ''; - this.complements = complements; + this.connections = connections; } function arguments_form_change(lastActualValueIdx, arg_id, this_form, lemma_id) { diff --git a/dictionary/validation.py b/dictionary/validation.py index 92aa1b8..db12685 100644 --- a/dictionary/validation.py +++ b/dictionary/validation.py @@ -418,6 +418,30 @@ def create_miss_binded_frames_msg_content(missing_frames): message_content += '\n' return message_content +####################### same positions validation ####################### +def validate_same_positions_schemata(lemma): + msg_content = '' + same_positions_schemata = get_same_positions_schemata(lemma) + if len(same_positions_schemata) > 0: + msg_content = same_positions_message(same_positions_schemata) + return msg_content + +def get_same_positions_schemata(lemma): + same_positions_schemata = [] + for schema in lemma.frames.all(): + for pos in schema.positions.all(): + if schema.positions.filter(text_rep=pos.text_rep).count() > 1: + same_positions_schemata.append(schema) + break + return same_positions_schemata + +def same_positions_message(same_positions_schemata): + message_content = u'W następujących schematach występuje więcej niż jedna identyczna pozycja:\n' + for schema in same_positions_schemata: + message_content += u'\t- [%d] %s\n' % (schema.id, schema.text_rep) + message_content += '\n' + return message_content + ####################### WALIDACJA ############################ def get_napprv_examples(lemma): nApprovedExamples = lemma.nkjp_examples.filter(source__confirmation_required=True, diff --git a/semantics/models.py b/semantics/models.py index d4b3a94..4e98ed9 100644 --- a/semantics/models.py +++ b/semantics/models.py @@ -49,6 +49,11 @@ class SemanticFrame(models.Model): return True return False + def opinion_selected(self): + if not self.opinion: + return False + return True + def __unicode__(self): complements_str_tab = [unicode(compl) for compl in self.complements.all()] return u'%d --> %s' % (self.id, u'+'.join(complements_str_tab)) @@ -114,6 +119,12 @@ class Complement(models.Model): # pola z ramki # realizacje tego argumentu w schematach składniowych realizations = models.ManyToManyField(FramePosition) + def has_only_phraseologic_realizations(self): + for real in self.realizations.all(): + if not real.argument.is_phraseologic(): + return False + return True + def __unicode__(self): return u'%d:%s' % (self.id, self.roles.all()) diff --git a/semantics/validation.py b/semantics/validation.py index ce5cef6..9455284 100644 --- a/semantics/validation.py +++ b/semantics/validation.py @@ -2,7 +2,7 @@ from django.db.models import Max -from dictionary.models import Lemma, reflex_phrase_types +from dictionary.models import Lemma, reflex_phrase_types, Argument_Model from semantics.models import LexicalUnitExamples from semantics.utils import get_matching_frame @@ -21,7 +21,7 @@ def frame_valid(lemma, frame, actual_frames): complements = frame.complements.all() if not arguments_exists(complements): error_msg = u'Semantyka: Rama semantyczna %d jest pusta.' % frame.id - elif not opinion_selected(frame): + elif not frame.opinion_selected(): error_msg = u'Semantyka: Rama semantyczna %d nie ma wybranej opinii.' % frame.id elif not roles_unique(complements): error_msg = u'Semantyka: Rama semantyczna %d nie zawiera unikalnych ról.' % frame.id @@ -44,11 +44,6 @@ def frame_valid(lemma, frame, actual_frames): def arguments_exists(complements): return complements.exists() -def opinion_selected(frame): - if not frame.opinion: - return False - return True - def roles_unique(complements): roles = set() for complement in complements: @@ -69,7 +64,9 @@ def arguments_pinned(complements): def preferences_selected(complements): for complement in complements: - if not preference_valid(complement): + if complement.realizations.exists() and complement.has_only_phraseologic_realizations(): + pass + elif not preference_valid(complement): return False return True -- libgit2 0.22.2