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

def extract_vectors(matrix_path, out_name, wordsfile):
	cmd = 'vector_extractor --matrix %s --out-name %s --words %s' % (matrix_path, out_name, wordsfile)
	os.system(cmd)


def process_dir(dirname, out_prefix, wordsfile):
	for entry in os.listdir(dirname):
		mdir = os.path.join(dirname,entry)
		if os.path.isdir(mdir) :
			print "Extracting vectors from", entry
			extract_vectors(mdir, out_prefix + entry + '.csv', wordsfile)


if __name__ == '__main__':
	print "Tool for extracting rows from multiple matrices"
	wordsfile = 'words.txt'
	out_prefix = 'bnc_words_'
	dirname = '/mnt/data/workdir/supermatrix2/bnc/weighted/'
	process_dir(dirname, out_prefix, wordsfile)
