
#ifndef SYNSET_H_
#define SYNSET_H_

#include <map>
#include <list>
#include <set>

#include "LexicalUnit.h"


namespace smartcomparator
{
	namespace simfunctions
	{


typedef std::pair<size_t,size_t> 				SynsetRelation;
typedef std::set<SynsetRelation> 				SynsetRelationSet;
typedef boost::shared_ptr<SynsetRelationSet>	SynsetRelationSetPtrS;

class Synset;

typedef boost::shared_ptr<Synset> SynsetPtrS;

typedef std::map<size_t, SynsetPtrS> 		SynsetByIdMap;
typedef boost::shared_ptr<SynsetByIdMap> 	SynsetByIdMapPtrS;


class Synset {
public:
	static void createSynsetTrees(
		SynsetRelationSetPtrS& 	pRelationSet,
		SynsetByIdMapPtrS& 		pSynsetsMap );

	static void cutSingleTree(
		SynsetPtrS& pTree,
		SynsetPtrS&	pOutCuttedTree,
		SynsetPtrS&	pOutNewTree,
		size_t		pDesiredNewTreeSize,
		float		pMinSizeSimilarity );

private:
	// internal, recursive
	// it HAS to be long int coz negative values
	static void cutSingleTreeIR(
		SynsetPtrS& pTree,
		SynsetPtrS& pOutCuttedTree,
		SynsetPtrS& pOutNewTree,
		long int	pNodesCountLB,
		long int	pNodesCountUB );

private:
	size_t				mId;
	size_t				mClass;
	LexicalUnitByIdMap 	mLemmas;
	SynsetByIdMap		mChilds;

	size_t				mNodesCount;
	size_t				mLemmasCount;

public:
	Synset(
		size_t pId,
		size_t pClass );
	virtual ~Synset();

	LexicalUnitByIdMap&	getLemmasEditable();
	SynsetByIdMap&		getChildsEditable();
	size_t&				getClassEditable();
	size_t&				getNodesCountEditable();
	size_t&				getLemmasCountEditable();

	size_t getSynsetId() 	const;
	size_t getChildsCount() const;
	size_t getNodesCount()	const;
	size_t getLemmasCount()	const;

	void recomputeSizes();


	void 		print() 				const;
	std::string	dumb( size_t pDeep )	const;
};


class SynsetComparator {
public:
	bool operator()( SynsetPtrS const& lhs, SynsetPtrS const& rhs ) const {
		return ( lhs->getNodesCount() < rhs->getNodesCount() );
	}
};


class SynsetComparatorR {
public:
	bool operator()( SynsetPtrS const& lhs, SynsetPtrS const& rhs ) const {
		return ( lhs->getNodesCount() > rhs->getNodesCount() );
	}
};


	}
}

#endif /* SYNSET_H_ */
