find_hanging_examples.py
3 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#-*- 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.meanings.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 '!!!!!!!!!!!!!! hanging example !!!!!!!!!!!!!!!!!'
print '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 '!!!!!!!!!!!!!! multiple pointers !!!!!!!!!!!!!!!!!'
print '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
for example in lemma.nkjp_examples.all():
same_lu_examples = LexicalUnitExamples.objects.filter(example=example, lexical_unit__in=lex_units)
if same_lu_examples.count() > 1:
print '!!!!!!!!!!!! two lus pinned to same example !!!!!!!!!!!!!!!!!!!'
for lu_ex in same_lu_examples:
print 'lemma: %s\tlu_ex_id: %d\texample: %s\tex_id: %d' % (lemma.entry_obj.name,
lu_ex.id,
example.sentence,
example.id)
if not lemma.frames.filter(pk=example.frame.pk).exists():
print '!!!!!!!!!!!! example without schema !!!!!!!!!!!!!!!!!!!'
print 'lemma: %s\tschema: %d\texample: %s\tex_id: %d' % (lemma.entry_obj.name,
example.frame.id,
example.sentence,
example.id)