Commit be91fb93367f300b43422a3c4fe2aea4e29e0441

Authored by janek37
1 parent c2ef4260

poprawka do generowania form

dictionary/lexeme_form_query.py
... ... @@ -21,6 +21,8 @@ join zakonczenia z
21 21 on (o.w_id = z.w_id and tc.base_form_label_id = z.efobaz)
22 22 '''
23 23  
  24 +WHERE_CLAUSES = '(not tt.takes_gender or tc_g.gender_id = o.gender_id)'
  25 +
24 26 def value_combinations(attributes, attr_vals=None):
25 27 if len(attributes) == 0:
26 28 yield ()
... ...
dictionary/management/commands/cache_form_qualifiers.py
... ... @@ -2,7 +2,8 @@
2 2  
3 3 from django.db import connection, transaction
4 4 from django.core.management.base import BaseCommand
5   -from dictionary.lexeme_form_query import FROM_CLAUSES, attr_clauses_combinations
  5 +from dictionary.lexeme_form_query import FROM_CLAUSES, WHERE_CLAUSES, \
  6 + attr_clauses_combinations
6 7 from dictionary.models import TableTemplate
7 8  
8 9  
... ... @@ -34,10 +35,10 @@ def create_forms():
34 35 select_query = '''
35 36 select distinct l.id as lexeme_id,
36 37 kz.qualifier_id as qualifier_id
37   - ''' + FROM_CLAUSES + '''
38   - join kwalifikatory_zakonczen kz
  38 + %s join kwalifikatory_zakonczen kz
39 39 on (z.id = kz.ending_id)
40   - where ''' + ' and '.join(attr_clauses)
  40 + where %s and ''' % (FROM_CLAUSES, WHERE_CLAUSES)
  41 + select_query += ' and '.join(attr_clauses)
41 42 cursor.execute('''
42 43 insert into dictionary_lexemeformqualifier
43 44 (lexeme_id, qualifier_id) (%s)''' % select_query,
... ...
dictionary/management/commands/convert_derivatives.py
1 1 # -*- coding: utf-8 -*-
2   -from django.core.exceptions import ObjectDoesNotExist
  2 +from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
3 3 from django.core.management.base import BaseCommand
4 4 import itertools
5 5 from common.util import no_history
... ... @@ -7,7 +7,7 @@ from dictionary.models import PartOfSpeech, Pattern, Gender
7 7  
8 8  
9 9 class Command(BaseCommand):
10   - help = "My shiny new management command."
  10 + help = "Convert derivatives so they don't use verb patterns"
11 11  
12 12 def handle(self, *args, **options):
13 13 convert_derivatives()
... ... @@ -39,7 +39,13 @@ def convert_derivatives():
39 39 lip.save()
40 40 for l in itertools.chain(ppas.lexeme_set.all(), appas.lexeme_set.all()):
41 41 for lip in l.lexemeinflectionpattern_set.all():
42   - end10 = lip.pattern.endings.get(base_form_label__symbol='10')
  42 + ends10 = lip.pattern.endings.filter(base_form_label__symbol='10')
  43 + for end in ends10:
  44 + if l.entry.endswith(end.string + 'y'):
  45 + end10 = end
  46 + break
  47 + else:
  48 + assert False
43 49 end12 = lip.pattern.endings.get(base_form_label__symbol='12')
44 50 # -ty/-ci
45 51 if end10.string.endswith('t'):
... ... @@ -55,15 +61,15 @@ def convert_derivatives():
55 61 lip.pattern = p12
56 62 lip.root = l.get_root(lip.pattern)
57 63 lip.save()
58   - for l in ger.lexeme_set.all():
  64 + for l in ger.lexeme_set.filter(entry__endswith='nie'):
59 65 for lip in l.lexemeinflectionpattern_set.all():
60   - end11 = lip.pattern.endings.get(base_form_label__symbol='11')
61   - # -nie
62   - if end11.string.endswith('n'):
63   - lip.pattern = p0196
64   - # -cie
65   - else:
66   - lip.pattern = p0195
  66 + lip.pattern = p0196
  67 + lip.gender = n2
  68 + lip.root = l.get_root(lip.pattern, n2)
  69 + lip.save()
  70 + for l in ger.lexeme_set.filter(entry__endswith='cie'):
  71 + for lip in l.lexemeinflectionpattern_set.all():
  72 + lip.pattern = p0195
67 73 lip.gender = n2
68 74 lip.root = l.get_root(lip.pattern, n2)
69 75 lip.save()
70 76 \ No newline at end of file
... ...
dictionary/management/commands/create_forms.py
... ... @@ -3,7 +3,8 @@
3 3 from django.db import connection, transaction
4 4 from django.core.management.base import BaseCommand
5 5 from common.util import uniprint
6   -from dictionary.lexeme_form_query import FROM_CLAUSES, value_combinations, attr_clauses_combinations
  6 +from dictionary.lexeme_form_query import FROM_CLAUSES, WHERE_CLAUSES, \
  7 + attr_clauses_combinations
7 8 from dictionary.models import TableTemplate
8 9  
9 10  
... ... @@ -35,7 +36,8 @@ def create_forms():
35 36 select_query = '''
36 37 select distinct l.id as lexeme_id,
37 38 tc.prefix||o.rdzen||z.zak||tc.suffix as form
38   - ''' + FROM_CLAUSES + 'where ' + ' and '.join(attr_clauses)
  39 + %s where %s and ''' % (FROM_CLAUSES, WHERE_CLAUSES)
  40 + select_query += ' and '.join(attr_clauses)
39 41 cursor.execute('''
40 42 insert into dictionary_lexemeform (lexeme_id, form)
41 43 (%s)''' % select_query,
... ...