clusterer.py
984 Bytes
#! /usr/bin/python
# -*- coding: utf-8 -*-
from local_db import get_db_data
from frame import LexicalUnit, SelectionalPreference, Frame
from group_frames import join_frames
from generate_xml import create_xml
from import_cluster import find_cluster
from semantics.models import SemanticFrame
import numpy as np
def generate_xml(cluster_heart, xml_file):
# prepare database
session, TT_dict = get_db_data()
LexicalUnit._session = session
SelectionalPreference._session = session
keys, transformation = find_cluster(cluster_heart, session, TT_dict)
frames = []
for i in list(keys):
frame_id = int(i[0,0])
frame = SemanticFrame.objects.get(id=frame_id)
transformation_id = i[0,1]
frames.append((frame, transformation_id))
unified_frame, matching = join_frames(frames, transformation)
create_xml(xml_file, unified_frame, matching)
def generate_empty_xml(xml_file):
create_xml(xml_file, Frame(), {})