/*
    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 "FrequencySelector.h"

namespace smartcomparator
{
	namespace selectors
	{
		FrequencySelector::FrequencySelector(Matrices::SuperMatrixPtr pMatrix, size_t min_nz, size_t min_tf,
											 size_t min_TF)
				: Selector(pMatrix),
				m_stMinNz(min_nz),
				m_stMinTermFrequency(min_tf),
				m_stMinGlobalTermFrequency(min_TF)
		{
		}

		FrequencySelector::~FrequencySelector()
		{
		}

		void FrequencySelector::SelectBestFeatures(size_t rowIndex,	const std::set<size_t> &filteredIndices,
												   std::set<size_t> &out)
		{
			Matrices::FeatureVectorPtr pRowFeatures = m_pMatrix->GetRowFeatures();
			Matrices::Feature f = pRowFeatures->operator[](rowIndex);

			if( f.GetNZ() < m_stMinNz
				|| f.GetTermFrequency() < m_stMinTermFrequency
				|| f.GetGlobalTermFrequency() < m_stMinGlobalTermFrequency)
				out.clear();
			else
				out = filteredIndices;
		}
	}//namespace smartcomparator
}//namespace selectors
