initialize_free_frames.py 954 Bytes
#! /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.clustering.local_db import FreeFrames, get_db_data

from settings import PROJECT_PATH

import numpy as np

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

    def handle(self, **options):

        session, _ = get_db_data()
        frames = []
        sfs = SemanticFrame.objects.filter(next=None, removed=False)
        for sf in sfs:
            if sf.entry is not None and \
               sf.entry.actual_lemma().status.priority >= 90: # (S) gotowe +
                if len(sf.lexical_units.filter(sense__lt='A')) > 0: # any original wordnet lexical unit connected
                    frames.append(FreeFrames(frame_id=sf.id))

        session.bulk_save_objects(frames)
        session.commit()