double_roles.py
1.06 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
#! /usr/bin/python
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
from settings import PROJECT_PATH
from semantics.models import SemanticRole, Complement, SemanticRolesDisplay, SemanticFrame
#==========================================================#
class Command(BaseCommand):
args = 'none'
help = ''
def handle(self, **options):
double_roles()
def double_roles():
frames = SemanticFrame.objects.filter(next=None)
for frame in frames:
complements = frame.complements.all()
rs = []
for complement in complements:
realizations = complement.realizations.all()
for realization in realizations:
rs.append((realization.id, frame, complement))
rs.sort()
for i in range(1, len(rs)):
rid1, frame1, comp1 = rs[i-1]
rid2, frame2, comp2 = rs[i]
if rid1 == rid2:
print str(frame.lexical_units.all()) + ': ' + str(comp1.roles.all()) + ', ' + str(comp2.roles.all())