#include "grammarCase.h"

#include <iostream>


	//std::vector<TranslationUnit> translationUnitArr;
	
void WordHolder::FillTranslationUnit(const std::vector<std::wstring>& lineArr, int startFrom)
{
	for (int i = 0; i < 3; i++)
	{
		TranslationUnit translationUnit;

		translationUnit.meaning = lineArr[startFrom + i * 3];
		translationUnit.comment = lineArr[startFrom + i * 3 + 1];
		translationUnit.example = lineArr[startFrom + i * 3 + 2];

		if (translationUnit.meaning != L"")
		{
			translationUnitArr.push_back(translationUnit);
		}
	}
}

boost::property_tree::wptree WordHolder::CreateTranslationPropertyTree() const
{
	boost::property_tree::wptree ptree;

	for (auto& translationUnit : translationUnitArr)
	{
		boost::property_tree::wptree translationUnitTree;
		translationUnitTree.put(L"meaning", translationUnit.meaning);
		translationUnitTree.put(L"comment", translationUnit.comment);
		translationUnitTree.put(L"example", translationUnit.example);

		ptree.push_back(std::make_pair(L"", translationUnitTree));
	}

	return ptree;
}

bool WordHolder::operator<(const WordHolder& other) const
{
	return word < other.word;
}

boost::property_tree::wptree WordHolder::GetProperties() const
{
	return properties;
}

void WordHolder::SetWord(const std::wstring& w)
{
	word = w;
}

std::wstring WordHolder::GetWord() const
{
	return word;
}

wchar_t WordHolder::GetLastChar() const
{
	if (word.size() == 0)
	{
		std::cout << "Error in GetLastChar" << std::endl;
	}

	return word[word.size() - 1];
}

wchar_t WordHolder::GetPrevLastChar() const
{
	if (word.size() < 2)
	{
		std::cout << "Error in GetPrevLastChar" << std::endl;
	}

	return word[word.size() - 2];
}

wchar_t WordHolder::GetPrevPrevLastChar() const
{
	if (word.size() < 3)
	{
		std::cout << "Error in GetPrevPrevLastChar" << std::endl;
	}

	return word[word.size() - 3];
}

std::wstring NounGenderToWString(NounGender g)
{
	if (g == NG_MALE)
	{
		return L"NG_MALE";
	}
	else if (g == NG_FEMALE)
	{
		return L"NG_FEMALE";
	}
	else if (g == NG_NEUTRAL)
	{
		return L"NG_NEUTRAL";
	}

	std::cout << "Error in NounGenderToWString" << std::endl;

	return L"";
}

std::wstring NormalizeNounGenderString(std::wstring str)
{
	if (str == L"м")
	{
		return L"NG_MALE";
	}
	else if (str == L"ж")
	{
		return L"NG_FEMALE";
	}
	else if (str == L"с")
	{
		return L"NG_NEUTRAL";
	}

	std::cout << "Error in NormalizeNounGenderString" << std::endl;

	return L"NG_MALE";
}

NounGender WStringToNounGender(std::wstring str)
{
	if (str == L"NG_MALE")
	{
		return NG_MALE;
	}
	else if (str == L"NG_FEMALE")
	{
		return NG_FEMALE;
	}
	else if (str == L"NG_NEUTRAL")
	{
		return NG_NEUTRAL;
	}

	std::cout << "Warning - passing old variables to WStringToNounGender" << std::endl;

	if (str == L"м")
	{
		return NG_MALE;
	}
	else if (str == L"ж")
	{
		return NG_FEMALE;
	}
	else if (str == L"с")
	{
		return NG_NEUTRAL;
	}

	std::cout << "Error in NounGenderToWString" << std::endl;

	return NG_MALE;
}


NounCount WStringToNounCount(std::wstring str)
{
	if (str == L"NC_SINGULAR")
	{
		return NC_SINGULAR;
	}
	if (str == L"NC_PLURAL")
	{
		return NC_PLURAL;
	}

	std::cout << "Error in WStringToNounCount!" << std::endl;
	return NC_SINGULAR;
}

std::wstring NounCountToWString(NounCount nounCount)
{
	if (nounCount == NC_SINGULAR)
	{
		return L"NC_SINGULAR";
	}
	if (nounCount == NC_PLURAL)
	{
		return L"NC_PLURAL";
	}

	std::cout << "Error in NounCountToWString!" << std::endl;
	return L"";
}


std::wstring NounGrammaticalCaseToWString(NounGrammaticalCase nounGrammaticalCase)
{
	switch (nounGrammaticalCase)
	{
	case NGC_P1_NOMINATIVE: return L"NGC_P1_NOMINATIVE";
	case NGC_P2_GENITIVE: return L"NGC_P2_GENITIVE";
	case NGC_P3_DATIVE: return L"NGC_P3_DATIVE";
	case NGC_P4_ACCUSATIVE: return L"NGC_P4_ACCUSATIVE";
	case NGC_P5_INSTRUMENTAL: return L"NGC_P5_INSTRUMENTAL";
	case NGC_P6_PREPOSITIONAL: return L"NGC_P6_PREPOSITIONAL";
	}

	return L"";
}

NounGrammaticalCase WStringToNounGrammaticalCase(std::wstring str)
{

	if (str == L"NGC_P1_NOMINATIVE")
	{
		return NGC_P1_NOMINATIVE;
	}
	if (str == L"NGC_P2_GENITIVE")
	{
		return NGC_P2_GENITIVE;
	}
	if (str == L"NGC_P3_DATIVE")
	{
		return NGC_P3_DATIVE;
	}
	if (str == L"NGC_P4_ACCUSATIVE")
	{
		return NGC_P4_ACCUSATIVE;
	}
	if (str == L"NGC_P5_INSTRUMENTAL")
	{
		return NGC_P5_INSTRUMENTAL;
	}
	if (str == L"NGC_P6_PREPOSITIONAL")
	{
		return NGC_P6_PREPOSITIONAL;
	}

	std::cout << "Error in WStringToNounGrammaticalCase!" << std::endl;
	return NGC_P1_NOMINATIVE;
}




bool charIsConsolant(wchar_t c) //except й
{
	std::wstring consolants = L"цкнгшщзхфвпрлджчсмтб";

	for (wchar_t ic : consolants)
	{
		if (c == ic)
		{
			return true;
		}
	}

	return false;
}

bool charIsVowel(wchar_t c)
{
	std::wstring vovels = L"аоуыэяёюие";

	for (wchar_t ic : vovels)
	{
		if (c == ic)
		{
			return true;
		}
	}

	return false;
}


std::wstring i_form_consolants = L"гхкжшчщ";
std::wstring u_form_consolants = L"бпдтвфзснмлрц";

bool charIsIFormConsolant(wchar_t c)
{
	return i_form_consolants.find(c) != i_form_consolants.npos;
}

bool charIsUFormConsolant(wchar_t c)
{
	return u_form_consolants.find(c) != i_form_consolants.npos;
}
