clusterer.py
3.69 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /usr/bin/python
# -*- coding: utf-8 -*-
from local_db import get_db_data
from frame import LexicalUnit, SelectionalPreference
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
session, TT_dict = get_db_data()
LexicalUnit._session = session
SelectionalPreference._session = session
keys1 = np.matrix([[u'55841', u''], [u'64330', u''], [u'94702', u''],
[u'94130', u''], [u'94068', u''], [u'94709', u''],
[u'17561', u''], [u'94777', u''], [u'53406', u'']])
keys2 = np.matrix([[u'102918', u'Factor,0'],
[u'152460', u'Stimulus,1'],
[u'41616', u'Stimulus,1'],
[u'67156', u'Stimulus,0'],
[u'104086', u'Factor,0'],
[u'90008', u'Stimulus,0'],
[u'88730', u'Stimulus,0'],
[u'97820', u'Factor,0'],
[u'133150', u'Factor,0'],
[u'35105', u'Stimulus,1'],
[u'119586', u'Stimulus,1'],
[u'65187', u'Stimulus,0'],
[u'137252', u'Stimulus,1'],
[u'75815', u'Stimulus,0'],
[u'98473', u'Factor,0'],
[u'103211', u'Factor,0'],
[u'62127', u'Stimulus,0'],
[u'70961', u'Stimulus,1'],
[u'159284', u'Stimulus,0'],
[u'97205', u'Stimulus,0'],
[u'6070', u'Stimulus,1'],
[u'61625', u'Stimulus,0'],
[u'144187', u'Stimulus,0'],
[u'79166', u'Stimulus,0'],
[u'155967', u'Stimulus,0'],
[u'55362', u'Factor,0'],
[u'154294', u'Factor,0'],
[u'89746', u'Stimulus,0'],
[u'133167', u'Factor,0'],
[u'125130', u'Factor,0'],
[u'59470', u'Stimulus,0'],
[u'94929', u'Stimulus,1'],
[u'104146', u'Factor,0'],
[u'22868', u'Factor,0'],
[u'59479', u'Stimulus,0'],
[u'152666', u'Stimulus,0'],
[u'141019', u'Stimulus,1'],
[u'103772', u'Factor,0'],
[u'154205', u'Stimulus,1'],
[u'41822', u'Stimulus,0'],
[u'124895', u'Factor,0'],
[u'150266', u'Stimulus,0'],
[u'103777', u'Factor,0'],
[u'90082', u'Factor,0'],
[u'152675', u'Stimulus,0'],
[u'133354', u'Factor,0'],
[u'72815', u'Stimulus,0'],
[u'92018', u'Stimulus,0'],
[u'107561', u'Factor,0'],
[u'52088', u'Stimulus,1'],
[u'55289', u'Factor,0'],
[u'141090', u'Stimulus,1'],
[u'126335', u'Stimulus,0'],
[u'71167', u'Stimulus,0']])
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)
# keys, transformation = keys1, 'zero'
# keys, transformation = keys2, 'fs'
frames = []
for i in list(keys2):
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)