/*
    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.
*/

#ifndef MATRICES_FEATURE_H
#define MATRICES_FEATURE_H
#include "matrices_headers.h"

namespace Matrices
{
	/**
	 * Class for describing rows and columns of matrix.
	 */
	class MATRICES_API Feature
	{
	public:
		/// Default constructor sets all number to 0 and label to empty string.
		Feature();
		/**
		 * Constructor from all the data.
		 * \param label Label for feature.
		 * \param nz Number of non-zero cells.
         * \param tf Term frequency (sum of a row).
         * \param TF Global term frequency.
         * \param entropy Shannon entropy of this feature.
		 */ 
		Feature(const std::string &label, size_t nz, size_t tf, size_t TF, 
				double entropy);

		/// retrieves number of non-zero cells.
		size_t GetNZ() const;
		/// retrieves term frequency
		size_t GetTermFrequency() const;
		/// retrives global term frequency
		size_t GetGlobalTermFrequency() const;
		/// retrieves entropy
		double GetEntropy() const;
		/// retrieves label
		const std::string & GetLabel() const;

		void SetNZ(size_t nz);
		void SetGlobalTermFrequency(size_t TF);
		void SetTermFrequnecy(size_t tf);
		void SetEntropy(double entropy);
		void SetLabel(const std::string& label);

	private:
		/// Non zero count
		size_t m_stNZ;
		/// Term frequency
		size_t m_stTermFrequency;
		/// Glbal term frequency
		size_t m_stGlobalTermFrequency;
		/// Entropy
		double m_dEntropy;
		/// Label for this term
		std::string m_sLabel;

	};
	/// Shared pointer on features
	typedef boost::shared_ptr<Feature> FeaturePtr;
	/// Vector of features
	typedef std::vector<Feature> FeatureVector;
	/// Shared pointer on vector of features
	typedef boost::shared_ptr<FeatureVector> FeatureVectorPtr;
	/// Index of labels, mapping from std::string to id (e.g., row or column number)
	typedef std::map<std::string, size_t> LabelIndex;

	/**
	 *	Creates index for features.
	 *  \param v Features from which the labels will be extracted
	 *  \param index output index
	 *  \return true if there were no problem in creating index. Problem can arise when, f.e., some features has the
	 *  same label.
	 */
	bool BuildLabelsIndex(const FeatureVector& v, LabelIndex &index);
	/// Helper function that counts how many of non zero features (f->GetNZ()) are 	present in data described by whole vector
	size_t CountNZSum(const FeatureVector& v);

}//namespace Matrices


#endif //MATRICES_FEATURE_H

