/*
    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 "matrices_headers.h"
#include "Feature.h"

namespace Matrices
{
	Feature::Feature()
	{
		m_stGlobalTermFrequency = 0;
		m_stTermFrequency = 0;
		m_stNZ = 0;
		m_dEntropy = 0;
		m_sLabel = "";
	}
	Feature::Feature(const std::string &label, size_t nz, size_t tf, size_t TF, 
				double entropy) 
		: m_stNZ(nz),
		m_stTermFrequency(tf),
		m_stGlobalTermFrequency(TF),
		m_dEntropy(entropy),
		m_sLabel(label)
	{
	}
	size_t Feature::GetNZ() const
	{
		return m_stNZ;
	}
	size_t Feature::GetTermFrequency() const
	{
		return m_stTermFrequency;
	}
	size_t Feature::GetGlobalTermFrequency() const
	{
		return m_stGlobalTermFrequency;
	}
	double Feature::GetEntropy() const
	{
		return m_dEntropy;
	}

	const std::string & Feature::GetLabel() const
	{
		return m_sLabel;
	}
	void Feature::SetNZ(size_t nz)
	{
		m_stNZ = nz;
	}
	void Feature::SetGlobalTermFrequency(size_t TF)
	{
		m_stGlobalTermFrequency = TF;
	}
	void Feature::SetTermFrequnecy(size_t tf)
	{
		m_stTermFrequency = tf;
	}
	void Feature::SetEntropy(double entropy)
	{
		m_dEntropy = entropy;
	}
	void Feature::SetLabel(const std::string& label)
	{
		m_sLabel = label;
	}


	bool BuildLabelsIndex(const FeatureVector& v, LabelIndex &index)
	{
		index.clear();

		for(size_t i = 0; i < v.size(); i++)
			index[v[i].GetLabel()] = i;

		return index.size() == v.size();
	}

	size_t CountNZSum(const FeatureVector& v)
	{
		size_t sum = 0;
		for(FeatureVector::iterator f; f != v.end(); f++)
			sum += f->GetNZ();
		return sum;
	}

}//namespace Matrices

