Commit 9f7ed3ffab27bb9eeb4b8c1a5b5c83662f2f2b8d
1 parent
74bcb2d2
Changed reflex validation rules in semantic validation.
Showing
4 changed files
with
53 additions
and
24 deletions
dictionary/management/commands/get_payments.py
1 | #-*- coding:utf-8 -*- | 1 | #-*- coding:utf-8 -*- |
2 | 2 | ||
3 | import codecs | 3 | import codecs |
4 | +import datetime | ||
4 | 5 | ||
5 | from django.contrib.auth.models import User | 6 | from django.contrib.auth.models import User |
6 | from django.core.management.base import BaseCommand | 7 | from django.core.management.base import BaseCommand |
@@ -14,7 +15,8 @@ class Command(BaseCommand): | @@ -14,7 +15,8 @@ class Command(BaseCommand): | ||
14 | get_payments() | 15 | get_payments() |
15 | 16 | ||
16 | def get_payments(): | 17 | def get_payments(): |
17 | - payments_path = 'data/payments_20150907.csv' | 18 | + now = datetime.datetime.now().strftime('%Y%m%d') |
19 | + payments_path = 'data/payments_%s.csv' % now | ||
18 | payments_file = codecs.open(payments_path, 'wt', 'utf-8') | 20 | payments_file = codecs.open(payments_path, 'wt', 'utf-8') |
19 | users = User.objects.order_by('username') | 21 | users = User.objects.order_by('username') |
20 | 22 |
dictionary/models.py
@@ -406,9 +406,6 @@ class Frame(Model): | @@ -406,9 +406,6 @@ class Frame(Model): | ||
406 | positions_str_tab = [position['position'].text_rep for position in sorted_positions] | 406 | positions_str_tab = [position['position'].text_rep for position in sorted_positions] |
407 | return u'%s:%s' % (':'.join(frame_chars_str_tab), ' + '.join(positions_str_tab)) | 407 | return u'%s:%s' % (':'.join(frame_chars_str_tab), ' + '.join(positions_str_tab)) |
408 | 408 | ||
409 | - def has_refl_args(self): | ||
410 | - return self.positions.filter(arguments__type__in=['refl', 'recip']).exists() | ||
411 | - | ||
412 | def __unicode__(self): | 409 | def __unicode__(self): |
413 | return '%s' % (self.text_rep) | 410 | return '%s' % (self.text_rep) |
414 | 411 | ||
@@ -766,7 +763,10 @@ class Argument(Model): | @@ -766,7 +763,10 @@ class Argument(Model): | ||
766 | return False | 763 | return False |
767 | 764 | ||
768 | def sort_arguments(arguments): | 765 | def sort_arguments(arguments): |
769 | - return sortArguments(arguments) | 766 | + return sortArguments(arguments) |
767 | + | ||
768 | +def reflex_phrase_types(): | ||
769 | + return ['refl', 'recip'] | ||
770 | 770 | ||
771 | class ArgRealization(Model): | 771 | class ArgRealization(Model): |
772 | # # !NOWE! nie dodalem tego jeszcze na produkcyjnym | 772 | # # !NOWE! nie dodalem tego jeszcze na produkcyjnym |
semantics/validation.py
1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
2 | 2 | ||
3 | -from dictionary.models import Lemma | 3 | +from django.db.models import Max |
4 | + | ||
5 | +from dictionary.models import Lemma, reflex_phrase_types | ||
4 | from semantics.models import LexicalUnitExamples | 6 | from semantics.models import LexicalUnitExamples |
5 | from semantics.utils import get_matching_frame | 7 | from semantics.utils import get_matching_frame |
6 | 8 | ||
@@ -9,12 +11,12 @@ def validate_frames(lemma_id): | @@ -9,12 +11,12 @@ def validate_frames(lemma_id): | ||
9 | actual_frames = lemma.entry_obj.actual_frames() | 11 | actual_frames = lemma.entry_obj.actual_frames() |
10 | error_msg = u'' | 12 | error_msg = u'' |
11 | for frame in actual_frames.all(): | 13 | for frame in actual_frames.all(): |
12 | - error_msg = frame_valid(frame, actual_frames) | 14 | + error_msg = frame_valid(lemma, frame, actual_frames) |
13 | if error_msg: | 15 | if error_msg: |
14 | break | 16 | break |
15 | return error_msg | 17 | return error_msg |
16 | 18 | ||
17 | -def frame_valid(frame, actual_frames): | 19 | +def frame_valid(lemma, frame, actual_frames): |
18 | error_msg = '' | 20 | error_msg = '' |
19 | complements = frame.complements.all() | 21 | complements = frame.complements.all() |
20 | if not arguments_exists(complements): | 22 | if not arguments_exists(complements): |
@@ -29,8 +31,8 @@ def frame_valid(frame, actual_frames): | @@ -29,8 +31,8 @@ def frame_valid(frame, actual_frames): | ||
29 | error_msg = u'Semantyka: Rama semantyczna %d nie ma dopiętych przykładów.' % frame.id | 31 | error_msg = u'Semantyka: Rama semantyczna %d nie ma dopiętych przykładów.' % frame.id |
30 | elif duplicates_exists(frame, actual_frames): | 32 | elif duplicates_exists(frame, actual_frames): |
31 | error_msg = u'Semantyka: Rama semantyczna %d posiada duplikaty.' % frame.id | 33 | error_msg = u'Semantyka: Rama semantyczna %d posiada duplikaty.' % frame.id |
32 | - elif not schemas_reflex_agreed(frame): | ||
33 | - error_msg = u'Semantyka: Rama semantyczna %d ma dopięte schematy o niezgodnej ze znaczeniami zwrotności.' % frame.id | 34 | + elif not schemas_reflex_agreed(lemma, frame): |
35 | + error_msg = u'Semantyka: Rama semantyczna %d ma dopięte elementy o niezgodnej zwrotności.' % frame.id | ||
34 | elif nonch_pinned(frame): | 36 | elif nonch_pinned(frame): |
35 | error_msg = u'Semantyka: Rama semantyczna %d jest dopięta do typu frazy nonch.' % frame.id | 37 | error_msg = u'Semantyka: Rama semantyczna %d jest dopięta do typu frazy nonch.' % frame.id |
36 | elif multiplied_same_arg_in_schema(frame): | 38 | elif multiplied_same_arg_in_schema(frame): |
@@ -88,23 +90,41 @@ def duplicates_exists(frame, actual_frames): | @@ -88,23 +90,41 @@ def duplicates_exists(frame, actual_frames): | ||
88 | return True | 90 | return True |
89 | return False | 91 | return False |
90 | 92 | ||
91 | -def schemas_reflex_agreed(frame): | 93 | +def schemas_reflex_agreed(lemma, frame): |
92 | complements = frame.complements.all() | 94 | complements = frame.complements.all() |
93 | lexical_units = frame.lexical_units.all() | 95 | lexical_units = frame.lexical_units.all() |
94 | - for compl in complements: | ||
95 | - for real in compl.realizations.all(): | ||
96 | - schema_reflex = real.frame.get_char_value('ZWROTNOŚĆ').value | ||
97 | - if (not reflex_in_lexical_units(lexical_units, schema_reflex)): | 96 | + for lex_unit in lexical_units: |
97 | + for schema in lemma.frames.all(): | ||
98 | + if not schema_lex_unit_reflex_agree(lex_unit, schema, complements): | ||
98 | return False | 99 | return False |
99 | return True | 100 | return True |
100 | 101 | ||
101 | -#def refl_like_phrase_type_pinned(compl, real): | ||
102 | -# same_frame_realizations = compl.realizations.filter(frame=real.frame, | ||
103 | -# alternation=real.alternation) | ||
104 | - | ||
105 | -def reflex_in_lexical_units(lexical_units, reflex): | ||
106 | - for lex_unit in lexical_units: | ||
107 | - if lex_unit.is_reflexive() == bool(reflex): | 102 | +def schema_lex_unit_reflex_agree(lexical_unit, schema, complements): |
103 | + if complements.filter(realizations__frame=schema).exists(): | ||
104 | + if (not reflex_with_self_mark_agreed(lexical_unit, schema) and | ||
105 | + not (lexical_unit.is_reflexive() and not lexical_unit.is_new() and | ||
106 | + reflex_with_phrase_types_agreed(lexical_unit, schema, complements))): | ||
107 | + return False | ||
108 | + return True | ||
109 | + | ||
110 | +def reflex_with_self_mark_agreed(lexical_unit, schema): | ||
111 | + schema_self_mark = schema.get_char_value('ZWROTNOŚĆ').value | ||
112 | + if not lexical_unit.is_reflexive() == bool(schema_self_mark): | ||
113 | + return False | ||
114 | + return True | ||
115 | + | ||
116 | +def reflex_with_phrase_types_agreed(lexical_unit, schema, complements): | ||
117 | + max_alternations = complements.all().aggregate(Max('realizations__alternation'))['realizations__alternation__max'] | ||
118 | + for alternation in range(1, max_alternations+1): | ||
119 | + if not reflex_with_alternation_phrase_types_agreed(complements, schema, alternation): | ||
120 | + return False | ||
121 | + return True | ||
122 | + | ||
123 | +def reflex_with_alternation_phrase_types_agreed(complements, schema, alternation): | ||
124 | + for compl in complements: | ||
125 | + if compl.realizations.filter(argument__type__in=reflex_phrase_types(), | ||
126 | + alternation=alternation, | ||
127 | + frame=schema).exists(): | ||
108 | return True | 128 | return True |
109 | return False | 129 | return False |
110 | 130 | ||
@@ -155,13 +175,15 @@ def validate_lexical_units(lemma_id): | @@ -155,13 +175,15 @@ def validate_lexical_units(lemma_id): | ||
155 | lexical_units = lemma.entry_obj.lexical_units() | 175 | lexical_units = lemma.entry_obj.lexical_units() |
156 | for lex_unit in lexical_units.all(): | 176 | for lex_unit in lexical_units.all(): |
157 | if not examples_reflex_agreed(lex_unit): | 177 | if not examples_reflex_agreed(lex_unit): |
158 | - error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady ze schematów o niezgodnej zwrotności.' % unicode(lex_unit) | 178 | + error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady o niezgodnej zwrotności.' % unicode(lex_unit) |
159 | return error_msg | 179 | return error_msg |
160 | 180 | ||
161 | def examples_reflex_agreed(lexical_unit): | 181 | def examples_reflex_agreed(lexical_unit): |
162 | lex_examples = LexicalUnitExamples.objects.filter(lexical_unit=lexical_unit) | 182 | lex_examples = LexicalUnitExamples.objects.filter(lexical_unit=lexical_unit) |
163 | for lex_example in lex_examples: | 183 | for lex_example in lex_examples: |
164 | schema_reflex = lex_example.example.frame.get_char_value('ZWROTNOŚĆ').value | 184 | schema_reflex = lex_example.example.frame.get_char_value('ZWROTNOŚĆ').value |
165 | - if not (lexical_unit.is_reflexive() == bool(schema_reflex)): | 185 | + if (not (lexical_unit.is_reflexive() == bool(schema_reflex)) and |
186 | + not (lexical_unit.is_reflexive() and not lexical_unit.is_new() and | ||
187 | + lex_example.arguments.filter(arguments__type__in=reflex_phrase_types()).exists())): | ||
166 | return False | 188 | return False |
167 | return True | 189 | return True |
wordnet/models.py
@@ -40,6 +40,11 @@ class LexicalUnit(models.Model): | @@ -40,6 +40,11 @@ class LexicalUnit(models.Model): | ||
40 | def actual_frames(self): | 40 | def actual_frames(self): |
41 | return self.frames.filter(next__isnull=True, removed=False) | 41 | return self.frames.filter(next__isnull=True, removed=False) |
42 | 42 | ||
43 | + def is_new(self): | ||
44 | + if self.luid < 0: | ||
45 | + return True | ||
46 | + return False | ||
47 | + | ||
43 | def is_reflexive(self): | 48 | def is_reflexive(self): |
44 | base_parts = self.base.split() | 49 | base_parts = self.base.split() |
45 | if len(base_parts) > 1 and base_parts[1] == u'się': | 50 | if len(base_parts) > 1 and base_parts[1] == u'się': |