auto_derivatives.py
3.41 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
from django.db.models import Max
from dictionary.models import Ending, Lexeme, LexemeInflectionPattern, \
Pattern, Gender
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')
n2 = Gender.objects.get(symbol='n2')
def lexeme_derivatives(lexeme):
if lexeme.part_of_speech.symbol == 'v':
proper = lexeme.lexemeattributevalue_set.filter(
attribute__name=u'właściwy', value__in=('', '(Q)'))
if proper:
trans = lexeme.lexemeattributevalue_set.filter(
attribute__name=u'przechodniość', value='T')
q_trans = lexeme.lexemeattributevalue_set.filter(
attribute__name=u'przechodniość', value='qT')
imperf = lexeme.lexemeattributevalue_set.filter(
attribute__name=u'aspekt').exclude(value='dk')
lips = list(lexeme.lexemeinflectionpattern_set.all())
for lip in lips:
pattern = lip.pattern
endings3 = Ending.objects.filter(
pattern=pattern, base_form_label__symbol='3')
endings10 = Ending.objects.filter(
pattern=pattern, base_form_label__symbol='10')
endings11 = Ending.objects.filter(
pattern=pattern, base_form_label__symbol='11')
endings12 = Ending.objects.filter(
pattern=pattern, base_form_label__symbol='12')
for ending in endings11:
yield ('ger', lip.root + ending.string + 'ie')
if trans or q_trans:
pos = 'ppas' if trans else 'appas'
for ending in endings10:
for ending12 in endings12:
yield (pos, lip.root + ending.string + 'y',
lip.root + ending12.string)
if imperf:
for ending in endings3:
yield ('pact', lip.root + ending.string + 'cy')
def create_derivative(lexeme, part_of_speech, entry, pl=None):
next_id = Lexeme.objects.aggregate(Max('id'))['id__max'] + 1
der = Lexeme(
id=next_id, entry=entry, part_of_speech_id=part_of_speech,
status=lexeme.status, owner_vocabulary=lexeme.owner_vocabulary)
der.fix_homonym_number()
der.save()
lexeme.owner_vocabulary.add_lexeme(der)
lip = LexemeInflectionPattern(lexeme=der)
if part_of_speech in ('ppas', 'appas'):
# -ty/-ci
if entry.endswith('ty'):
lip.pattern = P28
# -iony/-eni
elif entry.endswith('iony') and not pl.endswith('ieni'):
lip.pattern = P20
# -ony/-eni
elif entry.endswith('eni'):
lip.pattern = P19
# -ny/-ni
else:
lip.pattern = P12
elif part_of_speech == 'pact':
lip.pattern = P07
elif part_of_speech == 'ger':
lip.gender = n2
if entry.endswith('cie'):
lip.pattern = P0195
else: # -nie
lip.pattern = P0196
lip.root = lip.get_root()
lip.save()
# skopiować atrybuty, które mają sens
# imiesłowy -> dać nieobecne opcjonalne formy
# skopiować kwalifikatory?
# odsyłacze w obie strony
pass