diff --git a/dictionary/management/commands/get_payments.py b/dictionary/management/commands/get_payments.py index df2b093..0a08e94 100644 --- a/dictionary/management/commands/get_payments.py +++ b/dictionary/management/commands/get_payments.py @@ -1,6 +1,7 @@ #-*- coding:utf-8 -*- import codecs +import datetime from django.contrib.auth.models import User from django.core.management.base import BaseCommand @@ -14,7 +15,8 @@ class Command(BaseCommand): get_payments() def get_payments(): - payments_path = 'data/payments_20150907.csv' + now = datetime.datetime.now().strftime('%Y%m%d') + payments_path = 'data/payments_%s.csv' % now payments_file = codecs.open(payments_path, 'wt', 'utf-8') users = User.objects.order_by('username') diff --git a/dictionary/models.py b/dictionary/models.py index a921c6a..caa65c5 100644 --- a/dictionary/models.py +++ b/dictionary/models.py @@ -406,9 +406,6 @@ class Frame(Model): positions_str_tab = [position['position'].text_rep for position in sorted_positions] return u'%s:%s' % (':'.join(frame_chars_str_tab), ' + '.join(positions_str_tab)) - def has_refl_args(self): - return self.positions.filter(arguments__type__in=['refl', 'recip']).exists() - def __unicode__(self): return '%s' % (self.text_rep) @@ -766,7 +763,10 @@ class Argument(Model): return False def sort_arguments(arguments): - return sortArguments(arguments) + return sortArguments(arguments) + +def reflex_phrase_types(): + return ['refl', 'recip'] class ArgRealization(Model): # # !NOWE! nie dodalem tego jeszcze na produkcyjnym diff --git a/semantics/validation.py b/semantics/validation.py index 77b49d1..40c6ca7 100644 --- a/semantics/validation.py +++ b/semantics/validation.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- -from dictionary.models import Lemma +from django.db.models import Max + +from dictionary.models import Lemma, reflex_phrase_types from semantics.models import LexicalUnitExamples from semantics.utils import get_matching_frame @@ -9,12 +11,12 @@ def validate_frames(lemma_id): actual_frames = lemma.entry_obj.actual_frames() error_msg = u'' for frame in actual_frames.all(): - error_msg = frame_valid(frame, actual_frames) + error_msg = frame_valid(lemma, frame, actual_frames) if error_msg: break return error_msg -def frame_valid(frame, actual_frames): +def frame_valid(lemma, frame, actual_frames): error_msg = '' complements = frame.complements.all() if not arguments_exists(complements): @@ -29,8 +31,8 @@ def frame_valid(frame, actual_frames): error_msg = u'Semantyka: Rama semantyczna %d nie ma dopiętych przykładów.' % frame.id elif duplicates_exists(frame, actual_frames): error_msg = u'Semantyka: Rama semantyczna %d posiada duplikaty.' % frame.id - elif not schemas_reflex_agreed(frame): - error_msg = u'Semantyka: Rama semantyczna %d ma dopięte schematy o niezgodnej ze znaczeniami zwrotności.' % frame.id + elif not schemas_reflex_agreed(lemma, frame): + error_msg = u'Semantyka: Rama semantyczna %d ma dopięte elementy o niezgodnej zwrotności.' % frame.id elif nonch_pinned(frame): error_msg = u'Semantyka: Rama semantyczna %d jest dopięta do typu frazy nonch.' % frame.id elif multiplied_same_arg_in_schema(frame): @@ -88,23 +90,41 @@ def duplicates_exists(frame, actual_frames): return True return False -def schemas_reflex_agreed(frame): +def schemas_reflex_agreed(lemma, frame): complements = frame.complements.all() lexical_units = frame.lexical_units.all() - for compl in complements: - for real in compl.realizations.all(): - schema_reflex = real.frame.get_char_value('ZWROTNOŚĆ').value - if (not reflex_in_lexical_units(lexical_units, schema_reflex)): + for lex_unit in lexical_units: + for schema in lemma.frames.all(): + if not schema_lex_unit_reflex_agree(lex_unit, schema, complements): return False return True -#def refl_like_phrase_type_pinned(compl, real): -# same_frame_realizations = compl.realizations.filter(frame=real.frame, -# alternation=real.alternation) - -def reflex_in_lexical_units(lexical_units, reflex): - for lex_unit in lexical_units: - if lex_unit.is_reflexive() == bool(reflex): +def schema_lex_unit_reflex_agree(lexical_unit, schema, complements): + if complements.filter(realizations__frame=schema).exists(): + if (not reflex_with_self_mark_agreed(lexical_unit, schema) and + not (lexical_unit.is_reflexive() and not lexical_unit.is_new() and + reflex_with_phrase_types_agreed(lexical_unit, schema, complements))): + return False + return True + +def reflex_with_self_mark_agreed(lexical_unit, schema): + schema_self_mark = schema.get_char_value('ZWROTNOŚĆ').value + if not lexical_unit.is_reflexive() == bool(schema_self_mark): + return False + return True + +def reflex_with_phrase_types_agreed(lexical_unit, schema, complements): + max_alternations = complements.all().aggregate(Max('realizations__alternation'))['realizations__alternation__max'] + for alternation in range(1, max_alternations+1): + if not reflex_with_alternation_phrase_types_agreed(complements, schema, alternation): + return False + return True + +def reflex_with_alternation_phrase_types_agreed(complements, schema, alternation): + for compl in complements: + if compl.realizations.filter(argument__type__in=reflex_phrase_types(), + alternation=alternation, + frame=schema).exists(): return True return False @@ -155,13 +175,15 @@ def validate_lexical_units(lemma_id): lexical_units = lemma.entry_obj.lexical_units() for lex_unit in lexical_units.all(): if not examples_reflex_agreed(lex_unit): - error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady ze schematów o niezgodnej zwrotności.' % unicode(lex_unit) + error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady o niezgodnej zwrotności.' % unicode(lex_unit) return error_msg def examples_reflex_agreed(lexical_unit): lex_examples = LexicalUnitExamples.objects.filter(lexical_unit=lexical_unit) for lex_example in lex_examples: schema_reflex = lex_example.example.frame.get_char_value('ZWROTNOŚĆ').value - if not (lexical_unit.is_reflexive() == bool(schema_reflex)): + if (not (lexical_unit.is_reflexive() == bool(schema_reflex)) and + not (lexical_unit.is_reflexive() and not lexical_unit.is_new() and + lex_example.arguments.filter(arguments__type__in=reflex_phrase_types()).exists())): return False return True diff --git a/wordnet/models.py b/wordnet/models.py index a6d9baf..7cae7a9 100644 --- a/wordnet/models.py +++ b/wordnet/models.py @@ -40,6 +40,11 @@ class LexicalUnit(models.Model): def actual_frames(self): return self.frames.filter(next__isnull=True, removed=False) + def is_new(self): + if self.luid < 0: + return True + return False + def is_reflexive(self): base_parts = self.base.split() if len(base_parts) > 1 and base_parts[1] == u'się':