double_roles.py 1.06 KB
#! /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())