Commit ac9edb28faff6c08c15ecfcdf126a181f4d35b77
1 parent
09020185
Added multi positions message in syntactic validation.
Showing
7 changed files
with
52 additions
and
16 deletions
common/js_to_obj.py
... | ... | @@ -43,7 +43,8 @@ def jsFrameToObj(frame, lemma_entry): |
43 | 43 | for position in frame['positions']: |
44 | 44 | if len(position['arguments']) > 0: |
45 | 45 | pos_obj = jsPosToObj(position) |
46 | - positions_objs.append(pos_obj) | |
46 | + positions_objs.append(pos_obj) | |
47 | + position['id'] = pos_obj.id | |
47 | 48 | |
48 | 49 | sorted_positions = [] |
49 | 50 | sorted_pos_dict = sortPositions(positions_objs) |
... | ... |
dictionary/ajax_lemma_view.py
... | ... | @@ -59,7 +59,7 @@ from dictionary.validation import find_similar_frames, get_all_test_missing_fram |
59 | 59 | get_wrong_aspect_frames, validate_B_frames, get_deriv_miss_frames_message, \ |
60 | 60 | validate_phraseology_binded_frames, validate_rule_5, \ |
61 | 61 | validate_examples_and_mark_errors, validate_schemas_and_mark_errors, \ |
62 | - get_missing_aspects_msg | |
62 | + get_missing_aspects_msg, validate_same_positions_schemata | |
63 | 63 | |
64 | 64 | from semantics.models import LexicalUnitExamples |
65 | 65 | |
... | ... | @@ -2650,6 +2650,7 @@ def validate_new_frames(request, data, id, examples, lemma_examples, |
2650 | 2650 | message_content += u'\t- %s\n' % (miss_frame.text_rep) |
2651 | 2651 | message_content += '\n' |
2652 | 2652 | message_content += deriv_miss_frames_msg |
2653 | + message_content += validate_same_positions_schemata(old_object) | |
2653 | 2654 | frames_to_merge = find_similar_frames(old_object.frames.all()) |
2654 | 2655 | if len(frames_to_merge) > 0: |
2655 | 2656 | message_content += u'Sugerowane jest połączenie poniższych schematów, zawierają one często koordynujące się typy fraz:\n' |
... | ... |
dictionary/saving.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | |
3 | 3 | from common.js_to_obj import jsPosToObj |
4 | -from dictionary.models import Argument | |
4 | +from dictionary.models import Argument, Position | |
5 | 5 | from semantics.models import Complement, LexicalUnitExamples |
6 | 6 | from semantics.saving import modify_frames, update_meanings |
7 | 7 | from wordnet.models import LexicalUnit |
... | ... | @@ -21,7 +21,8 @@ def get_semantic_operations(lemma, schemata_conversions): |
21 | 21 | def get_reconnect_operations_and_extend_connections(connections, schema, js_schema): |
22 | 22 | operations = [] |
23 | 23 | for js_position in js_schema['positions']: |
24 | - position = jsPosToObj(js_position) | |
24 | + #position = jsPosToObj(js_position) | |
25 | + position = schema.positions.get(id=js_position['id']) | |
25 | 26 | for js_phrase_type in js_position['arguments']: |
26 | 27 | phrase_type = Argument.objects.get(id=js_phrase_type['id']) |
27 | 28 | new_connection_target = {'schema': schema, |
... | ... | @@ -46,10 +47,11 @@ def reconnect_operations(connection, new_target): |
46 | 47 | realization = compl.realizations.get(id=real_id) |
47 | 48 | old_phrase_type_ref = create_phrase_type_ref(realization.frame, realization.position, |
48 | 49 | realization.argument, realization.alternation) |
49 | - operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref)) | |
50 | 50 | new_phrase_type_ref = create_phrase_type_ref(new_target['schema'], new_target['position'], |
51 | 51 | new_target['phrase_type'], realization.alternation) |
52 | - operations.append(create_operation('connect', arg_ref, new_phrase_type_ref)) | |
52 | + if new_phrase_type_ref != old_phrase_type_ref: | |
53 | + operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref)) | |
54 | + operations.append(create_operation('connect', arg_ref, new_phrase_type_ref)) | |
53 | 55 | return operations |
54 | 56 | |
55 | 57 | def create_argument_ref(complement): |
... | ... |
dictionary/static/js/argument_form_utils.js
... | ... | @@ -11,14 +11,14 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
11 | 11 | */ |
12 | 12 | |
13 | 13 | // argument class |
14 | -function argument(id, text_rep, type, complements) | |
14 | +function argument(id, text_rep, type, connections) | |
15 | 15 | { |
16 | 16 | this.id = id |
17 | 17 | this.text_rep = text_rep; |
18 | 18 | this.type = type; |
19 | 19 | this.error = false; |
20 | 20 | this.tooltip = ''; |
21 | - this.complements = complements; | |
21 | + this.connections = connections; | |
22 | 22 | } |
23 | 23 | |
24 | 24 | function arguments_form_change(lastActualValueIdx, arg_id, this_form, lemma_id) { |
... | ... |
dictionary/validation.py
... | ... | @@ -418,6 +418,30 @@ def create_miss_binded_frames_msg_content(missing_frames): |
418 | 418 | message_content += '\n' |
419 | 419 | return message_content |
420 | 420 | |
421 | +####################### same positions validation ####################### | |
422 | +def validate_same_positions_schemata(lemma): | |
423 | + msg_content = '' | |
424 | + same_positions_schemata = get_same_positions_schemata(lemma) | |
425 | + if len(same_positions_schemata) > 0: | |
426 | + msg_content = same_positions_message(same_positions_schemata) | |
427 | + return msg_content | |
428 | + | |
429 | +def get_same_positions_schemata(lemma): | |
430 | + same_positions_schemata = [] | |
431 | + for schema in lemma.frames.all(): | |
432 | + for pos in schema.positions.all(): | |
433 | + if schema.positions.filter(text_rep=pos.text_rep).count() > 1: | |
434 | + same_positions_schemata.append(schema) | |
435 | + break | |
436 | + return same_positions_schemata | |
437 | + | |
438 | +def same_positions_message(same_positions_schemata): | |
439 | + message_content = u'W następujących schematach występuje więcej niż jedna identyczna pozycja:\n' | |
440 | + for schema in same_positions_schemata: | |
441 | + message_content += u'\t- [%d] %s\n' % (schema.id, schema.text_rep) | |
442 | + message_content += '\n' | |
443 | + return message_content | |
444 | + | |
421 | 445 | ####################### WALIDACJA ############################ |
422 | 446 | def get_napprv_examples(lemma): |
423 | 447 | nApprovedExamples = lemma.nkjp_examples.filter(source__confirmation_required=True, |
... | ... |
semantics/models.py
... | ... | @@ -49,6 +49,11 @@ class SemanticFrame(models.Model): |
49 | 49 | return True |
50 | 50 | return False |
51 | 51 | |
52 | + def opinion_selected(self): | |
53 | + if not self.opinion: | |
54 | + return False | |
55 | + return True | |
56 | + | |
52 | 57 | def __unicode__(self): |
53 | 58 | complements_str_tab = [unicode(compl) for compl in self.complements.all()] |
54 | 59 | return u'%d --> %s' % (self.id, u'+'.join(complements_str_tab)) |
... | ... | @@ -114,6 +119,12 @@ class Complement(models.Model): # pola z ramki |
114 | 119 | # realizacje tego argumentu w schematach składniowych |
115 | 120 | realizations = models.ManyToManyField(FramePosition) |
116 | 121 | |
122 | + def has_only_phraseologic_realizations(self): | |
123 | + for real in self.realizations.all(): | |
124 | + if not real.argument.is_phraseologic(): | |
125 | + return False | |
126 | + return True | |
127 | + | |
117 | 128 | def __unicode__(self): |
118 | 129 | return u'%d:%s' % (self.id, self.roles.all()) |
119 | 130 | |
... | ... |
semantics/validation.py
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | from django.db.models import Max |
4 | 4 | |
5 | -from dictionary.models import Lemma, reflex_phrase_types | |
5 | +from dictionary.models import Lemma, reflex_phrase_types, Argument_Model | |
6 | 6 | from semantics.models import LexicalUnitExamples |
7 | 7 | from semantics.utils import get_matching_frame |
8 | 8 | |
... | ... | @@ -21,7 +21,7 @@ def frame_valid(lemma, frame, actual_frames): |
21 | 21 | complements = frame.complements.all() |
22 | 22 | if not arguments_exists(complements): |
23 | 23 | error_msg = u'Semantyka: Rama semantyczna %d jest pusta.' % frame.id |
24 | - elif not opinion_selected(frame): | |
24 | + elif not frame.opinion_selected(): | |
25 | 25 | error_msg = u'Semantyka: Rama semantyczna %d nie ma wybranej opinii.' % frame.id |
26 | 26 | elif not roles_unique(complements): |
27 | 27 | 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): |
44 | 44 | def arguments_exists(complements): |
45 | 45 | return complements.exists() |
46 | 46 | |
47 | -def opinion_selected(frame): | |
48 | - if not frame.opinion: | |
49 | - return False | |
50 | - return True | |
51 | - | |
52 | 47 | def roles_unique(complements): |
53 | 48 | roles = set() |
54 | 49 | for complement in complements: |
... | ... | @@ -69,7 +64,9 @@ def arguments_pinned(complements): |
69 | 64 | |
70 | 65 | def preferences_selected(complements): |
71 | 66 | for complement in complements: |
72 | - if not preference_valid(complement): | |
67 | + if complement.realizations.exists() and complement.has_only_phraseologic_realizations(): | |
68 | + pass | |
69 | + elif not preference_valid(complement): | |
73 | 70 | return False |
74 | 71 | return True |
75 | 72 | |
... | ... |