convert_derivatives.py
2.46 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand
import itertools
from common.util import no_history
from dictionary.models import PartOfSpeech, Pattern, Gender
class Command(BaseCommand):
help = "My shiny new management command."
def handle(self, *args, **options):
convert_derivatives()
def convert_derivatives():
no_history()
pact = PartOfSpeech.objects.get(symbol='pact')
ppas = PartOfSpeech.objects.get(symbol='ppas')
appas = PartOfSpeech.objects.get(symbol='appas')
ger = PartOfSpeech.objects.get(symbol='ger')
n2 = Gender.objects.get(symbol='n2')
for pos in (pact, ppas, appas):
pos.lexical_class_id = 'adj'
pos.save()
ger.lexical_class_id = 'subst'
ger.save()
p07 = Pattern.objects.get(name='P07')
p28 = Pattern.objects.get(name='P28')
p12 = Pattern.objects.get(name='P12')
p19 = Pattern.objects.get(name='P19')
p20 = Pattern.objects.get(name='P20')
p0196 = Pattern.objects.get(name='0196')
p0195 = Pattern.objects.get(name='0195')
for l in pact.lexeme_set.all():
for lip in l.lexemeinflectionpattern_set.all():
lip.pattern = p07
lip.root = l.get_root(lip.pattern)
lip.save()
for l in itertools.chain(ppas.lexeme_set.all(), appas.lexeme_set.all()):
for lip in l.lexemeinflectionpattern_set.all():
end10 = lip.pattern.endings.get(base_form_label__symbol='10')
end12 = lip.pattern.endings.get(base_form_label__symbol='12')
# -ty/-ci
if end10.string.endswith('t'):
lip.pattern = p28
# -iony/-eni
elif end10.string.endswith('ion') and not end12.string.endswith('ieni'):
lip.pattern = p20
# -ony/-eni
elif end12.string.endswith('eni'):
lip.pattern = p19
# -ny/-ni
else:
lip.pattern = p12
lip.root = l.get_root(lip.pattern)
lip.save()
for l in ger.lexeme_set.all():
for lip in l.lexemeinflectionpattern_set.all():
end11 = lip.pattern.endings.get(base_form_label__symbol='11')
# -nie
if end11.string.endswith('n'):
lip.pattern = p0196
# -cie
else:
lip.pattern = p0195
lip.gender = n2
lip.root = l.get_root(lip.pattern, n2)
lip.save()