find_hanging_connections.py
1.48 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
#-*- coding:utf-8 -*-
import datetime
from django.core.management.base import BaseCommand
from dictionary.models import Lemma
class Command(BaseCommand):
args = 'none'
help = ""
def handle(self, **options):
find_hanging_connections()
def find_hanging_connections():
lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name')
for lemma in lemmas:
frames = lemma.entry_obj.actual_frames()
for frame in frames:
for compl in frame.complements.all():
for real in compl.realizations.all():
match = False
matching_schemata = lemma.frames.filter(id=real.frame.id).all()
for schema in matching_schemata:
matching_poss = schema.positions.filter(id=real.position.id,
arguments=real.argument)
if matching_poss.exists():
match = True
break
if not match:
compl_ref = 'frame_%d_comp_%d_' % (frame.id, compl.id)
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print 'lemma: %s\tcomplement: %s\trealization: %s' % (lemma.entry_obj.name,
compl_ref,
unicode(real))