frame_compare_locate_stop.py 2.1 KB
#! /usr/bin/python
# -*- coding: utf-8 -*-

import sys, os, codecs
from collections import defaultdict
from copy import deepcopy

from django.core.management.base import BaseCommand

from semantics.models import SemanticFrame

from semantics.management.commands.frame_compare_modules.frame import Frame, LexicalUnit, SelectionalPreference
from semantics.management.commands.frame_compare_modules.match_frames import match_frames, match_frames_diagonal
from semantics.management.commands.frame_compare_modules.local_db import get_db_data

from settings import PROJECT_PATH

BUNDLE_SIZE = 50
PROCESSES_NO = 16
PROCESS_ID = 0

class Command(BaseCommand):
    args = 'none'
    help = ''

    def handle(self, **options):
        # SPLIT FRAMES IN BUNLES
        frames = SemanticFrame.objects.filter(next=None, removed=False, entry__isnull=False).order_by('id')
        frame_bundles = []
        frame_bundle = []
        i = 0 # frame_bundle size
        for frame in frames:
            frame_bundle.append(frame)
            i += 1
            if i == BUNDLE_SIZE:
                frame_bundles.append(frame_bundle)
                frame_bundle = []
                i = 0
        if i != 0:
            frame_bundles.append(frame_bundle)

        print len(frames)
            
        # LOCAL DATABASE CONNECTION
        session, TT_dict = get_db_data()
        LexicalUnit._session = session
        SelectionalPreference._session = session
        print TT_dict.keys()
        exit(0)
        TransformationTable = TT_dict['zero']

        c = 0
        for i in range(len(frame_bundles)):
            for j in range(i+1):
                frames1 = []
                frames2 = []
                for frame in frame_bundles[i]:
                    frames1.append(frame.id)
                for frame in frame_bundles[j]:
                    frames2.append(frame.id)
                found = session.query(TransformationTable).filter(TransformationTable.frame1.in_(frames1)).filter(TransformationTable.frame2.in_(frames2)).count()
                if found > 0:
                    print i, j, c % PROCESSES_NO
                c += 1