get_pred_prepnp_jako_str2check.py 1.74 KB
from django.core.management.base import BaseCommand

from dictionary.models import Lemma


class Command(BaseCommand):

    def handle(self, **options):
        self.get_lemmas2check()

    def get_lemmas2check(self):
        for lemma in Lemma.objects.filter(old=False).order_by('entry_obj__name'):
            pred_prepnp_jako_str_exists = False
            other_pred_exists = False
            for schema in lemma.frames.all():
                for pos in schema.positions.filter(categories__category='pred_controllee'):
                    for phrase_type in pos.arguments.all():
                        if self.phrase_type_is_prepnp_jako_str(phrase_type):
                            pred_prepnp_jako_str_exists = True
                        elif self.phrase_type_is_prepadjp_jako_str(phrase_type):
                            pred_prepnp_jako_str_exists = True
                        else:
                            other_pred_exists = True
                if pred_prepnp_jako_str_exists and other_pred_exists:
                    print lemma
                    break

    def phrase_type_is_prepnp_jako_str(self, phrase_type):
        if (phrase_type.text_rep == 'prepnp(jako,str)'):
            return True
        if (phrase_type.type == 'lex' and
                phrase_type.atributes.get(type='TYP FRAZY').values.all()[0].argument.text_rep == 'prepnp(jako,str)'):
            return True
        return False

    def phrase_type_is_prepadjp_jako_str(self, phrase_type):
        if (phrase_type.text_rep == 'prepadjp(jako,str)'):
            return True
        if (phrase_type.type == 'lex' and
                phrase_type.atributes.get(type='TYP FRAZY').values.all()[0].argument.text_rep == 'prepadjp(jako,str)'):
            return True
        return False