/*
    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 "read_utils.h"
#include <boost/algorithm/string.hpp>

namespace Corpus2
{
	std::string orthwriter(Corpus2::Sentence::Ptr sentence,Corpus2::Tagset tagset)
	{
		std::string orth_sentence;
		std::vector<Token*> &tokens = sentence->tokens();
		for(int i = 0; i < (int)tokens.size(); i++)
		{
			std::string tmp = tokens[i]->orth_utf8();
			boost::algorithm::trim(tmp);
			orth_sentence += tmp + " ";
			Lexeme lex=tokens[i]->get_preferred_lexeme(tagset);
			tmp = lex.lemma_utf8();
			boost::algorithm::trim(tmp);
			orth_sentence += tmp + " ";
			orth_sentence += tagset.tag_to_string(lex.tag()) + "  ";
		}
		orth_sentence.erase(orth_sentence.size()-2, 2);
		return orth_sentence;
	}
	int get_head(Corpus2::Sentence::Ptr sentence,std::vector<int> all,Corpus2::Tagset tagset)
	{
		sort(all.begin(),all.end());
		std::vector<Token*> &tokens = sentence->tokens();
		int head=*(all.begin());
		BOOST_FOREACH (const int &position, all)
		{
			Token* tok = tokens[position];
			Lexeme lex=tok->get_preferred_lexeme(tagset);
			std::string pos = tagset.get_pos_name(lex.tag().get_pos());
			if(pos.compare("subst")==0)
			{
				head=position;
				break;
			}
		}
		return head;
	}
}

