convert_tables.py
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
from django.core.management import BaseCommand
from common.util import GroupDict
from dictionary.models import Cell, NewTableTemplate, LexicalClass, PatternType, NewCell
class Command(BaseCommand):
args = 'none'
help = 'blah'
def handle(self, **options):
convert_tables()
TABLE_TEMPLATES = [
('rzeczowniki', '1', ('subst', 'osc', 'skrs'), ('f', 'm', 'n', '0'), ()),
('pron', '1', ('subst',), ('z0', "z0'", 'z1', 'z1p', 'z2'), ()),
]
def convert_tables():
for name, variant, poses, p_types, attrs in TABLE_TEMPLATES:
cells = Cell.objects.filter(
table_template__variant__id=variant,
table_template__inflection_characteristic__part_of_speech__symbol__in=
poses)
if p_types:
cells = cells.filter(
table_template__pattern_type__symbol__in=p_types)
# TODO attrs - zinterpretować jako charfle?
new_template = NewTableTemplate(name=name, variant_id=variant)
new_template.save()
for pos in poses:
new_template.parts_of_speech.add(pos) #add
lexical_classes = LexicalClass.objects.filter(
partofspeech__symbol__in=poses)
pattern_types = PatternType.objects.filter(
lexical_class__in=lexical_classes, symbol__in=p_types)
for pt in pattern_types:
new_template.pattern_types.add(pt) #add
# TODO attrs
cell_groups = GroupDict()
for cell in cells:
cell_groups.add(
(cell.prefix, cell.base_form_label, cell.suffix), cell)
for key, cell_group in cell_groups.iteritems():
new_cell = NewCell(
table_template=new_template, base_form_label=key[1],
prefix=key[0], suffix=key[1])