find_hanging_examples.py 1.2 KB
#-*- coding:utf-8 -*-

from django.core.management.base import BaseCommand

from dictionary.models import Lemma
from semantics.models import LexicalUnitExamples

class Command(BaseCommand):
    args = 'none'
    help = ""

    def handle(self, **options):
        find_hanging_examples()
        
def find_hanging_examples():
    lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name')
    for lemma in lemmas:
        print_hanging_examples(lemma)
    
def print_hanging_examples(lemma):
    lex_units = lemma.entry_obj.lexical_units().all()
    for lu in lex_units:
        lu_examples = LexicalUnitExamples.objects.filter(lexical_unit=lu)
        for lu_ex in lu_examples:
            example = lu_ex.example
            if not lemma.nkjp_examples.filter(id=example.id).exists():
                print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
                print 'lemma: %s\tlu_ex_id: %d\texample: %s\tex_id: %d' % (lemma.entry_obj.name,
                                                                           lu_ex.id,
                                                                           example.sentence,
                                                                           example.id)