get_frames_without_ex.py 1.09 KB
#-*- coding:utf-8 -*-

import codecs

from django.core.management.base import BaseCommand
from django.db.models import Q

from dictionary.models import Lemma

OUTPATH = 'data/no_examples_20140224.txt'

class Command(BaseCommand):
    args = 'none'
    help = 'Get lemmas with frames without examples.'

    def handle(self, **options):
        get_frames_without_ex()

def get_frames_without_ex():
    """Get lemmas with frames without examples and
    write them to file"""
    try:
        outfile = codecs.open(OUTPATH, 'wt', 'utf-8')
        for lemma in Lemma.objects.filter(old=False).filter(Q(status__status=u'sprawdzone') |
                                                            Q(status__status=u'tymczasowy') |
                                                            Q(status__status=u'gotowe')).order_by('entry').all():
            print lemma
            for frame in lemma.frames.all():
                if not lemma.nkjp_examples.filter(frame=frame).exists():
                    outfile.write(lemma.entry + '\n')
                    break                
    finally:
        outfile.close()