/*
    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 <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>

#include "../nerreader.h"
#include "../read_utils.h"
#include "../liner.h"
#include <libcorpus2/tagsetmanager.h>
#include <libcorpus2/io/xcesreader.h>


BOOST_AUTO_TEST_SUITE( ner_functional );

struct Fixture{
	Fixture()
	{
		fill_sentences();

	}
	virtual void fill_sentences()
	{

	#ifdef NER_READER_TEST_DATA_DIR
		data_dir = boost::filesystem::path(NER_READER_TEST_DATA_DIR);
		data_dir /= "data";

	#else
		boost::filesystem::path data_dir("data");
	#endif
		test_corpus = data_dir / "test1.kipi.xml";

	}
	boost::filesystem::path test_corpus, data_dir;
};

BOOST_FIXTURE_TEST_CASE(liner_output, Fixture)
{
	std::string liner_out = "[2,4,PERSON_NAM][1,3,PERSON_NAM][2,2,PERSON_FIRST_NAM][1,3,CITY_NAM][3,4,PERSON_NAM][5,6,PERSON_NAM][4,7,PERSON_NAM]";
	std::vector<Corpus2::Liner::linerTuple> out;
	Corpus2::Liner liner("","","","");
	out = liner.process_liner_output(liner_out);
	BOOST_CHECK(out.size()==2);
	BOOST_CHECK(out[0].first.first==1);
	BOOST_CHECK(out[0].first.second==3);
	BOOST_CHECK(out[1].first.first==4);
	BOOST_CHECK(out[1].first.second==7);
}

BOOST_FIXTURE_TEST_CASE(get_head, Fixture)
{
	const Corpus2::Tagset& tagset = Corpus2::get_named_tagset("kipi");
	Corpus2::XcesReader xr(tagset, test_corpus.string());
	Corpus2::Sentence::Ptr s1 = xr.get_next_sentence();
	std::vector<int> positions;
	positions.push_back(0);
	positions.push_back(1);
	positions.push_back(2);
	int head = Corpus2::get_head(s1,positions,tagset);
	BOOST_CHECK(head==0);
	positions[0]=5;
	positions[1]=4;
	positions[2]=3;
	head = Corpus2::get_head(s1,positions,tagset);
	BOOST_CHECK(head==3);
}


BOOST_FIXTURE_TEST_CASE(clone_sentence, Fixture)
{
	const Corpus2::Tagset& tagset = Corpus2::get_named_tagset("kipi");
	Corpus2::XcesReader xr(tagset, test_corpus.string());
	Corpus2::Sentence::Ptr s1 = xr.get_next_sentence();
	std::vector<int> positions;
	positions.push_back(1);
	positions.push_back(2);
	positions.push_back(3);
	int head=2;
	int size_before=s1->tokens().size();
	Corpus2::Sentence::Ptr s2 = Corpus2::clone_sentence(s1,head,positions,"widzi","widzieć");

	int size_after=s2->tokens().size();
	BOOST_CHECK(size_after==size_before-2);
	Corpus2::Token* tok = s2->operator[](1);
	BOOST_CHECK(tok->orth_utf8()=="widzi");
}

/*BOOST_FIXTURE_TEST_CASE(liner, Fixture)
{
	const Corpus2::Tagset& tset = Corpus2::get_named_tagset("kipi");
	Corpus2::NERReader ner(tset, test_corpus.string());
	ner.set_option("nerinner:xces");
	ner.set_option("model:/home/dominik/liner2/model-bootstrap1/bootstrap1.ini");
	ner.set_option("nerd:/home/dominik/nerd");

	ner.validate();
	Corpus2::Sentence::Ptr s1 = ner.get_next_sentence();
	Corpus2::Token* tok = s1->operator[](0);
	BOOST_CHECK(tok->orth_utf8()=="PERSON_LAST_NAM:Chrostowski");
}*/

BOOST_AUTO_TEST_SUITE_END()
