wrong_derivatives.py 2.43 KB
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
from django.db import transaction
from common.util import uniprint, no_history
from dictionary.auto_derivatives import ppas_data, pact_data, create_derivative
from dictionary.models import Pattern, Lexeme, LexemeAttributeValue, Ending, \
    LexemeForm


class Command(BaseCommand):
    help = "Convert derivatives so they don't use verb patterns"

    def handle(self, *args, **options):
        wrong_derivatives()

INTRANS = LexemeAttributeValue.objects.get(
    attribute__name=u'przechodniość', value='iT')
DK = LexemeAttributeValue.objects.get(attribute__name=u'aspekt', value='dk')
NDK = LexemeAttributeValue.objects.get(attribute__name=u'aspekt', value='ndk')

def wrong_derivatives():
    transaction.commit_unless_managed()
    transaction.enter_transaction_management()
    transaction.managed()

    no_history()
    verbs = Lexeme.objects.filter(part_of_speech='v', owner_vocabulary='SGJP')
    intrans = verbs.filter(lexemeattributevalue=INTRANS)
    dk = verbs.filter(lexemeattributevalue=DK)
    ndk = verbs.filter(lexemeattributevalue=NDK)

    wrong_participles = set()
    for l in intrans:
        for data in ppas_data(l):
            der = create_derivative(
                l, data['pos'], data['entry'], data['index'], pl=data['pl'])
            wrong_participles |= der.all_forms()
    for l in dk:
        for data in pact_data(l):
            der = create_derivative(
                l, data['pos'], data['entry'], data['index'])
            wrong_participles |= der.all_forms()
        lips = list(l.lexemeinflectionpattern_set.all())
        for lip in lips:
            pattern = lip.pattern
            endings3 = Ending.objects.filter(
                pattern=pattern, base_form_label__symbol='3')
            for ending in endings3:
                wrong_participles.add(lip.root + ending.string + u'c')
    for l in ndk:
        lips = list(l.lexemeinflectionpattern_set.all())
        for lip in lips:
            pattern = lip.pattern
            endings6p = Ending.objects.filter(
                pattern=pattern, base_form_label__symbol="6'")
            for ending in endings6p:
                wrong_participles.add(lip.root + ending.string + u'szy')

    wrong_participles -= set(LexemeForm.objects.values_list('form', flat=True))
    for p in sorted(wrong_participles):
        uniprint(p)

    transaction.rollback()
    transaction.leave_transaction_management()