find_hanging_examples.py
2.03 KB
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
35
36
37
38
39
40
41
42
#-*- 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 'hanging example --> lemma: %s\tlu_ex_id: %d\texample: %s\tex_id: %d' % (lemma.entry_obj.name,
lu_ex.id,
example.sentence,
example.id)
same_lu_examples = LexicalUnitExamples.objects.filter(lexical_unit=lu, example=example)
if same_lu_examples.count() > 1:
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print 'multiple pointers --> lemma: %s\tlu_ex_id: %d\texample: %s\tex_id: %d' % (lemma.entry_obj.name,
lu_ex.id,
example.sentence,
example.id)
for ex in same_lu_examples.all():
print 'lu_ex_id: %d' % ex.id