Commit 8610849fc7f7c9bbfe40094c9d95e97e811dc241

Authored by janek37
1 parent ba47f911

w stronę automatycznych derywatów

dictionary/ajax_lexeme_view.py
... ... @@ -42,12 +42,10 @@ def inflection_tables(request, variant, lexeme_id):
42 42  
43 43 @render_ajax(template='table_preview.html', method='get')
44 44 def table_preview(request, lexeme_id, lip_id, pattern, attr_data=None,
45   - gender=None, entry=None):
  45 + gender=None):
46 46 lexeme = Lexeme.all_objects.get(pk=lexeme_id)
47 47 if not lexeme.perm(request.user, 'view'):
48 48 raise AjaxError('access denied')
49   - if entry is None:
50   - entry = lexeme.entry
51 49 try:
52 50 pattern = Pattern.objects.get(name=pattern)
53 51 gender = Gender.objects.get(id=gender) if gender else None
... ... @@ -62,7 +60,7 @@ def table_preview(request, lexeme_id, lip_id, pattern, attr_data=None,
62 60 lip = LexemeInflectionPattern.objects.get(pk=int(lip_id[3:]))
63 61 lip.pattern = pattern
64 62 lip.gender = gender
65   - lip.root = get_root(entry, pattern, gender)
  63 + lip.root = lip.get_root()
66 64 qualifiers = visible_qualifiers(request.user)
67 65 table = lip.inflection_table('0', separated=True,
68 66 qualifiers=qualifiers, edit_view=True, attr_vals=attr_vals)
... ...
dictionary/auto_derivatives.py
1 1 # -*- coding: utf-8 -*-
2   -from dictionary.models import Ending
  2 +from django.db.models import Max
  3 +from dictionary.models import Ending, Lexeme, LexemeInflectionPattern, \
  4 + Pattern, Gender
3 5  
  6 +P07 = Pattern.objects.get(name='P07')
  7 +P28 = Pattern.objects.get(name='P28')
  8 +P12 = Pattern.objects.get(name='P12')
  9 +P19 = Pattern.objects.get(name='P19')
  10 +P20 = Pattern.objects.get(name='P20')
  11 +P0196 = Pattern.objects.get(name='0196')
  12 +P0195 = Pattern.objects.get(name='0195')
  13 +n2 = Gender.objects.get(symbol='n2')
4 14  
5 15 def lexeme_derivatives(lexeme):
6 16 if lexeme.part_of_speech.symbol == 'v':
7 17 proper = lexeme.lexemeattributevalue_set.filter(
8 18 attribute__name=u'właściwy', value__in=('', '(Q)'))
9 19 if proper:
10   - # ger, pact, ppas, appas
11   - patterns = list(lexeme.patterns.all())
12   - endings3 = Ending.objects.filter(
13   - pattern__in=patterns, base_form_label='3')
14   - endings10 = Ending.objects.filter(
15   - pattern__in=patterns, base_form_label='10')
16   - endings11 = Ending.objects.filter(
17   - pattern__in=patterns, base_form_label='11')
18   - endings12 = Ending.objects.filter(
19   - pattern__in=patterns, base_form_label='12')
20   - for ending in endings11:
21   - # ger
22   - pass
  20 + trans = lexeme.lexemeattributevalue_set.filter(
  21 + attribute__name=u'przechodniość', value='T')
  22 + q_trans = lexeme.lexemeattributevalue_set.filter(
  23 + attribute__name=u'przechodniość', value='qT')
  24 + imperf = lexeme.lexemeattributevalue_set.filter(
  25 + attribute__name=u'aspekt').exclude(value='dk')
  26 + lips = list(lexeme.lexemeinflectionpattern_set.all())
  27 + for lip in lips:
  28 + pattern = lip.pattern
  29 + endings3 = Ending.objects.filter(
  30 + pattern=pattern, base_form_label__symbol='3')
  31 + endings10 = Ending.objects.filter(
  32 + pattern=pattern, base_form_label__symbol='10')
  33 + endings11 = Ending.objects.filter(
  34 + pattern=pattern, base_form_label__symbol='11')
  35 + endings12 = Ending.objects.filter(
  36 + pattern=pattern, base_form_label__symbol='12')
  37 + for ending in endings11:
  38 + yield ('ger', lip.root + ending.string + 'ie')
  39 + if trans or q_trans:
  40 + pos = 'ppas' if trans else 'appas'
  41 + for ending in endings10:
  42 + for ending12 in endings12:
  43 + yield (pos, lip.root + ending.string + 'y',
  44 + lip.root + ending12.string)
  45 + if imperf:
  46 + for ending in endings3:
  47 + yield ('pact', lip.root + ending.string + 'cy')
23 48  
24 49  
25   -def create_derivative(lexeme, part_of_speech, root):
  50 +def create_derivative(lexeme, part_of_speech, entry, pl=None):
  51 + next_id = Lexeme.objects.aggregate(Max('id'))['id__max'] + 1
  52 + der = Lexeme(
  53 + id=next_id, entry=entry, part_of_speech_id=part_of_speech,
  54 + status=lexeme.status, owner_vocabulary=lexeme.owner_vocabulary)
  55 + der.fix_homonym_number()
  56 + der.save()
  57 + lexeme.owner_vocabulary.add_lexeme(der)
  58 + lip = LexemeInflectionPattern(lexeme=der)
  59 + if part_of_speech in ('ppas', 'appas'):
  60 + # -ty/-ci
  61 + if entry.endswith('ty'):
  62 + lip.pattern = P28
  63 + # -iony/-eni
  64 + elif entry.endswith('iony') and not pl.endswith('ieni'):
  65 + lip.pattern = P20
  66 + # -ony/-eni
  67 + elif entry.endswith('eni'):
  68 + lip.pattern = P19
  69 + # -ny/-ni
  70 + else:
  71 + lip.pattern = P12
  72 + elif part_of_speech == 'pact':
  73 + lip.pattern = P07
  74 + elif part_of_speech == 'ger':
  75 + lip.gender = n2
  76 + if entry.endswith('cie'):
  77 + lip.pattern = P0195
  78 + else: # -nie
  79 + lip.pattern = P0196
  80 + lip.root = lip.get_root()
  81 + lip.save()
  82 + # skopiować atrybuty, które mają sens
  83 + # imiesłowy -> dać nieobecne opcjonalne formy
  84 + # skopiować kwalifikatory?
  85 + # odsyłacze w obie strony
26 86 pass
... ...
dictionary/models.py
... ... @@ -546,8 +546,7 @@ class Lexeme(Model):
546 546 self.lexemeformqualifier_set.create(qualifier=qualifier)
547 547  
548 548 def get_root(self, pattern, gender=None):
549   - basic_form = self.entry
550   - return get_root(basic_form, pattern, gender)
  549 + return get_root(self.entry, pattern, gender)
551 550  
552 551 def visible_vocabularies(self, user):
553 552 return visible_vocabularies(user) & self.vocabularies.all()
... ... @@ -583,8 +582,7 @@ class Lexeme(Model):
583 582 def fix_homonym_number(self):
584 583 homonym_numbers = (Lexeme.objects.filter(
585 584 entry=self.entry, part_of_speech=self.part_of_speech)
586   - .exclude(pk=self.pk)).values_list('homonym_number',
587   - flat=True)
  585 + .exclude(pk=self.pk)).values_list('homonym_number', flat=True)
588 586 for i in xrange(1, len(homonym_numbers) + 2):
589 587 if i not in homonym_numbers:
590 588 self.homonym_number = i
... ... @@ -818,6 +816,9 @@ class LexemeInflectionPattern(Model):
818 816 def editable_vocabularies(self, user):
819 817 return self.lexeme.editable_vocabularies(user)
820 818  
  819 + def get_root(self):
  820 + return get_root(self.lexeme.entry, self.pattern, self.gender)
  821 +
821 822 def __unicode__(self):
822 823 return '%s : %s/%s : %s' % (
823 824 self.lexeme.entry,
... ...