frame_compare_9.py
2.55 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /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
print "splitting frames in bundles..."
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:
if frame.entry.actual_lemma().status.priority >= 90: # (S)ready / (S)validated
lus = frame.lexical_units.all()
if len(lus) > 0 and\
max([lu.luid for lu in lus]) >=0:
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 " ...done"
# LOCAL DATABASE CONNECTION
session, TT_dict = get_db_data()
LexicalUnit._session = session
SelectionalPreference._session = session
c = 0
for i in range(len(frame_bundles)):
for j in range(i+1):
if c % PROCESSES_NO == PROCESS_ID:
print i, j
frames1 = []
for frame in frame_bundles[i]:
f = Frame.from_slowal(frame)
frames1.append(f)
if i == j:
match_frames_diagonal(frames1, session, TT_dict)# , verbose=True, fake=True)
else:
frames2 = []
for frame in frame_bundles[j]:
f = Frame.from_slowal(frame)
frames2.append(f)
match_frames(frames1, frames2, session, TT_dict)# , verbose=True, fake=True)
c += 1