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

namespace LexicalUnits
{
	Word::Word(const Corpus::CTag &tag, int base_index)
		: m_cTag(tag),
		m_iBaseIndex(base_index)
	{
	}
	
	Word::Word(int base_index)
		: m_cTag(Corpus::mask_All),
		m_iBaseIndex(base_index)
	{
		m_cTag.FlexClass = Corpus::mask_All;
		m_cTag.Categories = Corpus::mask_All;
	}

	Word::Word(const Word &w)
		: m_cTag(w.m_cTag),
		m_iBaseIndex(w.m_iBaseIndex)
	{
	}

	Word::~Word()
	{
	}

	Word& Word::operator =(const Word& w)
	{
		this->m_iBaseIndex = w.m_iBaseIndex;
		this->m_cTag = w.m_cTag;
		return *this;
	}

	Word::Word(const std::string &text)
	{
		throw std::string("Word::Word(const::string&) Not implemeted!");
		//TODO Word::Word(const std::string &text)
	}

	Word::Word(const Corpus::CLexem &lexem)
	{
		this->m_cTag = lexem.GetTag();
		this->m_iBaseIndex = lexem.GetBaseIdx();
	}
		
	bool Word::operator ==(const Word& w) const
	{
		if( (this->m_cTag.Categories & w.m_cTag.Categories) == 0)
			return false;

		if( (this->m_cTag.FlexClass & w.m_cTag.FlexClass) == 0)
			return false;

		return m_iBaseIndex == w.m_iBaseIndex;
	}

	bool Word::operator !=(const Word& w) const
	{
		return ! (*this == w );
	}
	
	bool Word::operator ==(const Corpus::CLexem& lexem) const
	{
		if( m_cTag.FlexClass && (m_cTag.FlexClass & lexem.GetTag().FlexClass )== 0)
			return false;

		if((lexem.GetTag().FlexClass & (Corpus::cf_conj | Corpus::cf_qub | Corpus::cf_ign) ) == 0 //tokens with no category f.e. conjunctives
				&& m_cTag.Categories //tokens with category not set
				&& (m_cTag.Categories & lexem.GetTag().Categories) == 0) //other
			return false;
		return m_iBaseIndex == lexem.GetBaseIdx();

	}

	bool Word::operator !=(const Corpus::CLexem& lexem) const
	{
		return !(*this == lexem);
	}

	int Word::GetBaseIndex() const
	{
		return m_iBaseIndex;
	}

	Corpus::CTag Word::GetTag() const
	{
		return m_cTag;
	}
}//namespace LexicalUnits

