203 lines
3.8 KiB
C++
203 lines
3.8 KiB
C++
#include "grammarCase.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
//std::vector<TranslationUnit> translationUnitArr;
|
|
|
|
void TranslationUnitSetMix::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 TranslationUnitSetMix::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;
|
|
}
|
|
|
|
|
|
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() > 1)
|
|
{
|
|
std::cout << "Error in GetPrevLastChar" << std::endl;
|
|
}
|
|
|
|
return word[word.size() - 2];
|
|
}
|
|
|
|
|
|
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;
|
|
}
|