/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#include "../comparator_stdheaders.h"
#include "RWFZScoreRankComparision.h"
#include "../simfunctions/CosineFunction.h"
#include "../weights/RWFZScore.h"
#include "../filters/NoiseFilter.h"
#include "../selectors/FrequencySelector.h"

namespace smartcomparator
{
	namespace compare
	{

		RWFZScoreRankComparision::RWFZScoreRankComparision(Matrices::SuperMatrixPtr matrix, weights::RankBuilderPtr pRankBulilder,
				double noiseFilterPercent, int col_mintf, double rz, size_t row_min_nz, size_t row_min_tf, size_t  row_min_TF)
			: CompareFunction(matrix)
		{
			// filtering
			size_t cNoise = (size_t) (matrix->NumberOfColumns()*noiseFilterPercent);
			m_pFilter = filters::FilterFeaturePtr(
					new filters::NoiseKTFFilter(matrix->GetColumnFeatures(), cNoise, col_mintf) );
			// selector
			m_pSelector = selectors::SelectorPtr(
					new selectors::FrequencySelector(matrix, row_min_nz, row_min_tf, row_min_TF)
					);
			// weighting
			m_pWeight = weights::WeightFeaturePtr( new weights::RWFZScore(matrix, pRankBulilder, rz) );
			// sim functions
			simfunctions::CosineFunction *fun = new  simfunctions::CosineFunction(matrix);
			m_pSimfun = simfunctions::SimilarityFunctionPtr( fun );
		}

		RWFZScoreRankComparision::~RWFZScoreRankComparision(void)
		{
		}

		//////////////////////////////////////

		RWFZScoreInMatrixComparision::RWFZScoreInMatrixComparision(Matrices::SuperMatrixPtr matrix, weights::RankBuilderPtr pRankBulilder,
			 double noiseFilterPercent, int col_mintf,	double min_rz, size_t row_min_nz, size_t row_min_tf, size_t  row_min_TF)
			: CompareFunction(matrix)
		{
			// filtering
			size_t cNoise = (size_t) (matrix->NumberOfColumns()*noiseFilterPercent);
			m_pFilter = filters::FilterFeaturePtr(
					new filters::NoiseKTFFilter(matrix->GetColumnFeatures(), cNoise, col_mintf) );
			// selector
			m_pSelector = selectors::SelectorPtr(
					new selectors::FrequencySelector(matrix, row_min_nz, row_min_tf, row_min_TF)
					);
			// weighting
			m_pWeight = weights::WeightFeaturePtr(
					new weights::RWFZScoreInMatrixWeight(matrix, pRankBulilder, min_rz ));
			// sim function
			simfunctions::CosineFunction *fun = new  simfunctions::CosineFunction(matrix);
			m_pSimfun = simfunctions::SimilarityFunctionPtr( fun );
		}

		RWFZScoreInMatrixComparision::~RWFZScoreInMatrixComparision(void)
		{
		}

		/////////////////////////////////

		RWFLocalZScoreComparision::RWFLocalZScoreComparision(Matrices::SuperMatrixPtr matrix,weights::RankBuilderPtr pRankBulilder,
				double noiseFilterPercent, int col_mintf, double min_rz, size_t row_min_nz, size_t row_min_tf, size_t  row_min_TF)
			: CompareFunction(matrix)
		{
			// filtering
			size_t cNoise = (size_t) (matrix->NumberOfColumns()*noiseFilterPercent);
			m_pFilter = filters::FilterFeaturePtr(
					new filters::NoiseKTFFilter(matrix->GetColumnFeatures(), cNoise, col_mintf));
			// selector
			m_pSelector = selectors::SelectorPtr(
					new selectors::FrequencySelector(matrix, row_min_nz, row_min_tf, row_min_TF)
					);
			// weighting
			m_pWeight = weights::WeightFeaturePtr(
					new weights::RWFLocalZScoreWeight(matrix, pRankBulilder, min_rz ));
			// sim function
			simfunctions::CosineFunction *fun = new  simfunctions::CosineFunction(matrix);
			m_pSimfun = simfunctions::SimilarityFunctionPtr( fun );
		}

		RWFLocalZScoreComparision::~RWFLocalZScoreComparision(void)
		{
		}
	}//namespace compare
}//namespace smartcomparator

