Blame view

dictionary/management/commands/get_frames_without_ex.py 1.09 KB
Bartłomiej Nitoń authored
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
#-*- 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()