Commit a84017318b489e1d123a102d78de476ed7c91d04
Merge branch 'master' into bartek
Showing
5 changed files
with
62 additions
and
20 deletions
dictionary/management/commands/get_payments.py
1 | 1 | #-*- coding:utf-8 -*- |
2 | 2 | |
3 | 3 | import codecs |
4 | +import datetime | |
4 | 5 | |
5 | 6 | from django.contrib.auth.models import User |
6 | 7 | from django.core.management.base import BaseCommand |
... | ... | @@ -14,7 +15,8 @@ class Command(BaseCommand): |
14 | 15 | get_payments() |
15 | 16 | |
16 | 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 | 20 | payments_file = codecs.open(payments_path, 'wt', 'utf-8') |
19 | 21 | users = User.objects.order_by('username') |
20 | 22 | |
... | ... |
dictionary/models.py
... | ... | @@ -763,7 +763,10 @@ class Argument(Model): |
763 | 763 | return False |
764 | 764 | |
765 | 765 | def sort_arguments(arguments): |
766 | - return sortArguments(arguments) | |
766 | + return sortArguments(arguments) | |
767 | + | |
768 | +def reflex_phrase_types(): | |
769 | + return ['refl', 'recip'] | |
767 | 770 | |
768 | 771 | class ArgRealization(Model): |
769 | 772 | # # !NOWE! |
... | ... |
dictionary/teixml.py
... | ... | @@ -43,7 +43,7 @@ def createteixml(outpath, lemmas, frame_char_models, |
43 | 43 | form_dict, q_frame_opinions): |
44 | 44 | root = write_root() |
45 | 45 | write_header(root) |
46 | - lemmas = lemmas.filter(entry=u'administrować') | |
46 | + #lemmas = lemmas.filter(entry=u'administrować') | |
47 | 47 | write_entries(root, lemmas, frame_char_models, |
48 | 48 | form_dict, q_frame_opinions) |
49 | 49 | with codecs.open(outpath, 'wt', 'utf-8') as output_file: |
... | ... |
semantics/validation.py
1 | 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 | 6 | from semantics.models import LexicalUnitExamples |
5 | 7 | from semantics.utils import get_matching_frame |
6 | 8 | |
... | ... | @@ -9,12 +11,12 @@ def validate_frames(lemma_id): |
9 | 11 | actual_frames = lemma.entry_obj.actual_frames() |
10 | 12 | error_msg = u'' |
11 | 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 | 15 | if error_msg: |
14 | 16 | break |
15 | 17 | return error_msg |
16 | 18 | |
17 | -def frame_valid(frame, actual_frames): | |
19 | +def frame_valid(lemma, frame, actual_frames): | |
18 | 20 | error_msg = '' |
19 | 21 | complements = frame.complements.all() |
20 | 22 | if not arguments_exists(complements): |
... | ... | @@ -29,8 +31,8 @@ def frame_valid(frame, actual_frames): |
29 | 31 | error_msg = u'Semantyka: Rama semantyczna %d nie ma dopiętych przykładów.' % frame.id |
30 | 32 | elif duplicates_exists(frame, actual_frames): |
31 | 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 | 36 | elif nonch_pinned(frame): |
35 | 37 | error_msg = u'Semantyka: Rama semantyczna %d jest dopięta do typu frazy nonch.' % frame.id |
36 | 38 | elif multiplied_same_arg_in_schema(frame): |
... | ... | @@ -88,19 +90,47 @@ def duplicates_exists(frame, actual_frames): |
88 | 90 | return True |
89 | 91 | return False |
90 | 92 | |
91 | -def schemas_reflex_agreed(frame): | |
93 | +def schemas_reflex_agreed(lemma, frame): | |
94 | + agreed = True | |
92 | 95 | complements = frame.complements.all() |
93 | 96 | 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): | |
98 | - return False | |
97 | + for schema in lemma.frames.all(): | |
98 | + schema_agreed = False | |
99 | + for lex_unit in lexical_units: | |
100 | + if schema_lex_unit_reflex_agree(lex_unit, schema, complements): | |
101 | + schema_agreed = True | |
102 | + break | |
103 | + if not schema_agreed: | |
104 | + agreed = False | |
105 | + break | |
106 | + return agreed | |
107 | + | |
108 | +def schema_lex_unit_reflex_agree(lexical_unit, schema, complements): | |
109 | + if complements.filter(realizations__frame=schema).exists(): | |
110 | + if (not reflex_with_self_mark_agreed(lexical_unit, schema) and | |
111 | + not (lexical_unit.is_reflexive() and not lexical_unit.is_new() and | |
112 | + reflex_with_phrase_types_agreed(lexical_unit, schema, complements))): | |
113 | + return False | |
114 | + return True | |
115 | + | |
116 | +def reflex_with_self_mark_agreed(lexical_unit, schema): | |
117 | + schema_self_mark = schema.get_char_value('ZWROTNOŚĆ').value | |
118 | + if not lexical_unit.is_reflexive() == bool(schema_self_mark): | |
119 | + return False | |
99 | 120 | return True |
100 | - | |
101 | -def reflex_in_lexical_units(lexical_units, reflex): | |
102 | - for lex_unit in lexical_units: | |
103 | - if lex_unit.is_reflexive() == bool(reflex): | |
121 | + | |
122 | +def reflex_with_phrase_types_agreed(lexical_unit, schema, complements): | |
123 | + max_alternations = complements.all().aggregate(Max('realizations__alternation'))['realizations__alternation__max'] | |
124 | + for alternation in range(1, max_alternations+1): | |
125 | + if not reflex_with_alternation_phrase_types_agreed(complements, schema, alternation): | |
126 | + return False | |
127 | + return True | |
128 | + | |
129 | +def reflex_with_alternation_phrase_types_agreed(complements, schema, alternation): | |
130 | + for compl in complements: | |
131 | + if compl.realizations.filter(argument__type__in=reflex_phrase_types(), | |
132 | + alternation=alternation, | |
133 | + frame=schema).exists(): | |
104 | 134 | return True |
105 | 135 | return False |
106 | 136 | |
... | ... | @@ -151,13 +181,15 @@ def validate_lexical_units(lemma_id): |
151 | 181 | lexical_units = lemma.entry_obj.lexical_units() |
152 | 182 | for lex_unit in lexical_units.all(): |
153 | 183 | if not examples_reflex_agreed(lex_unit): |
154 | - error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady ze schematów o niezgodnej zwrotności.' % unicode(lex_unit) | |
184 | + error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady o niezgodnej zwrotności.' % unicode(lex_unit) | |
155 | 185 | return error_msg |
156 | 186 | |
157 | 187 | def examples_reflex_agreed(lexical_unit): |
158 | 188 | lex_examples = LexicalUnitExamples.objects.filter(lexical_unit=lexical_unit) |
159 | 189 | for lex_example in lex_examples: |
160 | 190 | schema_reflex = lex_example.example.frame.get_char_value('ZWROTNOŚĆ').value |
161 | - if not (lexical_unit.is_reflexive() == bool(schema_reflex)): | |
191 | + if (not (lexical_unit.is_reflexive() == bool(schema_reflex)) and | |
192 | + not (lexical_unit.is_reflexive() and not lexical_unit.is_new() and | |
193 | + lex_example.example.arguments.filter(arguments__type__in=reflex_phrase_types()).exists())): | |
162 | 194 | return False |
163 | 195 | return True |
... | ... |
wordnet/models.py
... | ... | @@ -40,6 +40,11 @@ class LexicalUnit(models.Model): |
40 | 40 | def actual_frames(self): |
41 | 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 | 48 | def is_reflexive(self): |
44 | 49 | base_parts = self.base.split() |
45 | 50 | if len(base_parts) > 1 and base_parts[1] == u'się': |
... | ... |