/*
    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 "lex_headers.h"
#include "LexicalUnit.h"

namespace LexicalUnits
{
	size_t LexicalUnit::m_stLastId = 0;
	
	LexicalUnit::LexicalUnit(const std::vector<boost::shared_ptr<Word> > &constituents,
								int baseId, Corpus::TFlexClass fc)
		: m_vConstituents(constituents),
		m_iBaseId(baseId),
		m_Flex(fc)
	{
		m_stId = m_stLastId++;
	}

	LexicalUnit::~LexicalUnit()
	{
		// do nothing
	}

	Corpus::TFlexClass LexicalUnit::GetFlexClass() const
	{
		return m_Flex;
	}

	int LexicalUnit::GetBaseId() const
	{
		return m_iBaseId;
	}

	size_t LexicalUnit::GetId() const
	{
		return m_stId;
	}

	int LexicalUnit::operator < (const LexicalUnit & lu) const
	{
		if( GetId() > lu.GetId() )
			return 1;
		if( GetId() < lu.GetId() )
			return -1;
		
		return 0;
	}

	boost::shared_ptr<Word> LexicalUnit::GetConstituent(int no)
	{
		if(no >= (int) m_vConstituents.size() )
			return boost::shared_ptr<Word>();

		return m_vConstituents[no];
	}
	size_t LexicalUnit::GetConstituentsCount() const
	{
		return m_vConstituents.size();
	}

	void LexicalUnit::GetPotentialBases(std::set<int> &out)
	{
		out.clear();
		for( size_t i = 0; i < m_vConstituents.size() ;i++ )
		{
			out.insert( m_vConstituents[i]->GetBaseIndex() );
		}
	}

}//namespace LexicalUnits

