def build_E(mode): key_subtask = 'E' rows = data_manager.read_data(key_subtask, mode) ofname = data_manager.fname_gold(key_subtask, mode) indexer = Indexer(['-2', '-1', '0', '1', '2']) topic_label = {} for row in rows: topic = row[1] label = row[2] if topic not in topic_label: topic_label[topic] = np.zeros(indexer.size()) topic_label[topic][indexer.idx(label)] += 1 fobj = open(ofname, 'w') for topic, labels in topic_label.items(): n_sample = np.sum(labels) dist = labels / n_sample fobj.write('%s\t%s\n' % (topic, '\t'.join(map(lambda k: '%.12f' % k, dist)))) fobj.close()
def build_C(mode): key_subtask = 'C' rows = data_manager.read_data(key_subtask, mode) ofname = data_manager.fname_gold(key_subtask, mode) fobj = open(ofname, 'w') for row in rows: fobj.write('%s\t%s\t%s\n' % (row[0], row[1], row[2])) fobj.close()