#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import pymatrices, pycomparator

def write_row(row, indices, out):
	for ind in indices:
		out.write('(%d, %f) ' % (ind, row.GetElement(ind) ) )
	out.write('\n')

def main():
	mdir = '/home/boban/macierze/ang/2009/bnc/subst/minipar_morpha/frequencies/'
	mname = 'bnc_subj_summed'
	outfile = 'test.txt'
	row_no = 0
	w1 = 'lin()'
	w2 = 'mi_quant_cos()'

	print "Loading matrices"
	m1 = pymatrices.LoadSuperMatrix(mdir, mname, False, True)
	m2 = pymatrices.LoadSuperMatrix(mdir, mname, False, True)
	with open(outfile, 'w') as f:
		row = m1.GetRow(row_no)
		indices = sorted( row.GetValues().keys() )
		print "Writing original row"
		write_row(row, indices, f)
		c1 = pycomparator.FunctionFactory.CreateFunction(w1, m1)
		print "Transforming matrix with", w1
		c1.TransformMatrix(False)
		row = m1.GetRow(row_no)
		write_row(row, indices, f)
		c2 = pycomparator.FunctionFactory.CreateFunction(w2, m2)
		print "Transforming matrix with", w2
		c2.TransformMatrix(False)
		row = m2.GetRow(row_no)
		write_row(row, indices, f)
	print "All done"




if __name__ == '__main__':
	main()

