%module pycomparator
%{
#include "comparator_all.h"
#include "comparator_utils.h"
#include "compare/CompareFunction.h"
%}

%include "std_set.i"
%include "std_vector.i"
%include "std_string.i"
%include "std_pair.i"
%include "std_string.i"

namespace std {
	%template(intset) set<int>;
	%template(stset) set<size_t>;
	%template(strdpair) pair<std::string, double>;
	%template(strvec) vector<std::string>;
	%template(strdpairvec) vector<std::pair<std::string, double> >;
};

%import "pymatrices.i"

void noise_filter_matrix(Matrices::SuperMatrixPtr pMatrix, size_t mintf, double noisePrec);
void lin_weight_matrix(Matrices::SuperMatrixPtr pMatrix);
void pmi_weight_matrix(Matrices::SuperMatrixPtr pMatrix);
void logent_weight_matrix(Matrices::SuperMatrixPtr pMatrix);
void zscore_weight_matrix(Matrices::SuperMatrixPtr pMatrix);

void rwf_zscore_weight_matrix(Matrices::SuperMatrixPtr pMatrix, double min_rz, const std::string &args);
void rwf_pmi_weight_matrix(Matrices::SuperMatrixPtr pMatrix, double threshold, bool discount, const std::string &args);
void rwf_lin_weight_matrix(Matrices::SuperMatrixPtr pMatrix, double threshold, const std::string &args);

std::vector<std::string> get_kbest(smartcomparator::compare::CompareFunctionPtr pCmp, const std::string &word, int k );
std::vector< std::pair<std::string,double> > get_kbest_val(smartcomparator::compare::CompareFunctionPtr pCmp, const std::string &word, int k );
std::vector< std::pair<std::string, double> > generate_kbest(smartcomparator::compare::CompareFunctionPtr pCmp, const std::string &word, int k );

%pythoncode%{
	def generate_kbest(cmp, word, k):
		data = []
		if type(word) == unicode:
			word = word.encode('utf8')
		kbest = _pycomparator.generate_kbest(cmp, word, k)
		for w,s in kbest:
			data.append( (w,s) )
		return data

	def print_kbest(cmp, word, k):
		kbest = generate_kbest(cmp, word, k)
		for w,s in kbest:
			print ("%s (%.3f)," % (w,s) ),
		print
%}

namespace smartcomparator
{
	namespace weights
	{

		class WeightFeature
		{
		public:
			WeightFeature(Matrices::SuperMatrixPtr m);
			virtual ~WeightFeature(void);

			virtual void Weight(size_t rowindex, Matrices::CompressedVector *v, std::set<size_t> &filteredIndices) = 0;
		};
	}
}

%template(WeigtFeaturePtr) boost::shared_ptr<smartcomparator::weights::WeightFeature>;

namespace smartcomparator
{
	namespace weights
	{
		class SimpleMIWeight : public WeightFeature
		{
		public:
			SimpleMIWeight(Matrices::SuperMatrixPtr m, bool dicount = true);
			virtual ~SimpleMIWeight();
			virtual void Weight(size_t rowindex, Matrices::CompressedVector *v, std::set<size_t> &filteredIndices);
		};

	}

	namespace compare
	{

		class CompareFunction
		{
		public:
			CompareFunction(Matrices::SuperMatrixPtr matrix);
			virtual double Compare(size_t n1, size_t n2);
			virtual double ExternalCompare(size_t n1, Matrices::CompressedVectorPtr pVector);
			virtual double Compare(const std::string %w1, const std::string &w2);
			virtual double ExternalCompare(const std::string %w1, Matrices::CompressedVectorPtr pVector);
			Matrices::SuperMatrixPtr GetMatrix();
			void WeightMatrixCopy();
			void WeightMatrix();
			virtual ~CompareFunction();
		};

		typedef boost::shared_ptr<smartcomparator::compare::CompareFunction> CompareFunctionPtr;
	}
}

%template(CompareFunctionPtr) boost::shared_ptr<smartcomparator::compare::CompareFunction>;

namespace smartcomparator
{
	namespace compare
	{

		class FunctionFactory
		{
		public:
			static CompareFunctionPtr CreateFunction( const std::string &str, Matrices::SuperMatrixPtr pMatrix);
		};

	}
}

