Refactoring
This commit is contained in:
parent
b4ca1471d6
commit
f48b8c6929
Binary file not shown.
@ -34,19 +34,7 @@ namespace AJ
|
|||||||
|
|
||||||
specialShortForm = lineArr[3];
|
specialShortForm = lineArr[3];
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
FillTranslationUnit(lineArr, 4);
|
||||||
{
|
|
||||||
TranslationUnit translationUnit;
|
|
||||||
|
|
||||||
translationUnit.meaning = lineArr[4 + i * 3];
|
|
||||||
translationUnit.comment = lineArr[4 + i * 3 + 1];
|
|
||||||
translationUnit.example = lineArr[4 + i * 3 + 2];
|
|
||||||
|
|
||||||
if (translationUnit.meaning != L"")
|
|
||||||
{
|
|
||||||
translationUnitArr.push_back(translationUnit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
namespace AJ
|
namespace AJ
|
||||||
{
|
{
|
||||||
|
|
||||||
struct AdjectiveRecord
|
struct AdjectiveRecord : public TranslationUnitSetMix
|
||||||
{
|
{
|
||||||
std::wstring nominativeMaleForm;
|
std::wstring nominativeMaleForm;
|
||||||
|
|
||||||
@ -22,8 +22,6 @@ namespace AJ
|
|||||||
|
|
||||||
std::wstring specialShortForm;
|
std::wstring specialShortForm;
|
||||||
|
|
||||||
std::vector<TranslationUnit> translationUnitArr;
|
|
||||||
|
|
||||||
AdjectiveRecord();
|
AdjectiveRecord();
|
||||||
AdjectiveRecord(std::wstring line);
|
AdjectiveRecord(std::wstring line);
|
||||||
|
|
||||||
|
@ -2,6 +2,44 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NounCount WStringToNounCount(std::wstring str)
|
NounCount WStringToNounCount(std::wstring str)
|
||||||
{
|
{
|
||||||
if (str == L"NC_SINGULAR")
|
if (str == L"NC_SINGULAR")
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
#ifndef GRAMMAR_CASE_H_INCLUDED
|
#ifndef GRAMMAR_CASE_H_INCLUDED
|
||||||
#define GRAMMAR_CASE_H_INCLUDED
|
#define GRAMMAR_CASE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "boost/algorithm/string.hpp"
|
||||||
|
#include "boost/property_tree/ptree.hpp"
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
enum NounGender
|
enum NounGender
|
||||||
{
|
{
|
||||||
@ -47,6 +53,18 @@ struct TranslationUnit
|
|||||||
std::wstring example;
|
std::wstring example;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TranslationUnitSetMix
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::vector<TranslationUnit> translationUnitArr;
|
||||||
|
|
||||||
|
void FillTranslationUnit(const std::vector<std::wstring>& lineArr, int startFrom);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
boost::property_tree::wptree CreateTranslationPropertyTree() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
std::wstring NounCountToWString(NounCount nounCount);
|
std::wstring NounCountToWString(NounCount nounCount);
|
||||||
NounCount WStringToNounCount(std::wstring str);
|
NounCount WStringToNounCount(std::wstring str);
|
||||||
|
@ -179,17 +179,7 @@ namespace http {
|
|||||||
|
|
||||||
nounTree.put(L"noun.nominativeSingularForm", nounStruct.nounRecord.nominativeForm);
|
nounTree.put(L"noun.nominativeSingularForm", nounStruct.nounRecord.nominativeForm);
|
||||||
|
|
||||||
boost::property_tree::wptree allTranslationsTree;
|
boost::property_tree::wptree allTranslationsTree = nounStruct.nounRecord.CreateTranslationPropertyTree();
|
||||||
|
|
||||||
for (auto& translationUnit : nounStruct.nounRecord.translationUnitArr)
|
|
||||||
{
|
|
||||||
boost::property_tree::wptree translationUnitTree;
|
|
||||||
translationUnitTree.put(L"meaning", translationUnit.meaning);
|
|
||||||
translationUnitTree.put(L"comment", translationUnit.comment);
|
|
||||||
translationUnitTree.put(L"example", translationUnit.example);
|
|
||||||
|
|
||||||
allTranslationsTree.push_back(std::make_pair(L"", translationUnitTree));
|
|
||||||
}
|
|
||||||
|
|
||||||
nounTree.put_child(L"translations", allTranslationsTree);
|
nounTree.put_child(L"translations", allTranslationsTree);
|
||||||
|
|
||||||
@ -221,17 +211,7 @@ namespace http {
|
|||||||
|
|
||||||
adjectiveTree.put(L"adjective.nominativeSingularForm", adjectiveStruct.adjectiveRecord.nominativeMaleForm);
|
adjectiveTree.put(L"adjective.nominativeSingularForm", adjectiveStruct.adjectiveRecord.nominativeMaleForm);
|
||||||
|
|
||||||
boost::property_tree::wptree allTranslationsTree;
|
boost::property_tree::wptree allTranslationsTree = adjectiveStruct.adjectiveRecord.CreateTranslationPropertyTree();
|
||||||
|
|
||||||
for (auto& translationUnit : adjectiveStruct.adjectiveRecord.translationUnitArr)
|
|
||||||
{
|
|
||||||
boost::property_tree::wptree translationUnitTree;
|
|
||||||
translationUnitTree.put(L"meaning", translationUnit.meaning);
|
|
||||||
translationUnitTree.put(L"comment", translationUnit.comment);
|
|
||||||
translationUnitTree.put(L"example", translationUnit.example);
|
|
||||||
|
|
||||||
allTranslationsTree.push_back(std::make_pair(L"", translationUnitTree));
|
|
||||||
}
|
|
||||||
|
|
||||||
adjectiveTree.put_child(L"translations", allTranslationsTree);
|
adjectiveTree.put_child(L"translations", allTranslationsTree);
|
||||||
|
|
||||||
@ -264,17 +244,7 @@ namespace http {
|
|||||||
|
|
||||||
verbTree.put(L"verb.verbParams", VB::VerbParamsToWString(verbStruct.verbParams));
|
verbTree.put(L"verb.verbParams", VB::VerbParamsToWString(verbStruct.verbParams));
|
||||||
|
|
||||||
boost::property_tree::wptree allTranslationsTree;
|
boost::property_tree::wptree allTranslationsTree = verbStruct.verbRecord.CreateTranslationPropertyTree();
|
||||||
|
|
||||||
for (auto& translationUnit : verbStruct.verbRecord.translationUnitArr)
|
|
||||||
{
|
|
||||||
boost::property_tree::wptree translationUnitTree;
|
|
||||||
translationUnitTree.put(L"meaning", translationUnit.meaning);
|
|
||||||
translationUnitTree.put(L"comment", translationUnit.comment);
|
|
||||||
translationUnitTree.put(L"example", translationUnit.example);
|
|
||||||
|
|
||||||
allTranslationsTree.push_back(std::make_pair(L"", translationUnitTree));
|
|
||||||
}
|
|
||||||
|
|
||||||
verbTree.put_child(L"translations", allTranslationsTree);
|
verbTree.put_child(L"translations", allTranslationsTree);
|
||||||
|
|
||||||
@ -300,18 +270,8 @@ namespace http {
|
|||||||
otherWordTree.put(L"otherWord.word", otherWordRecord.word);
|
otherWordTree.put(L"otherWord.word", otherWordRecord.word);
|
||||||
otherWordTree.put(L"otherWord.type", otherWordRecord.type);
|
otherWordTree.put(L"otherWord.type", otherWordRecord.type);
|
||||||
|
|
||||||
boost::property_tree::wptree allTranslationsTree;
|
boost::property_tree::wptree allTranslationsTree = otherWordRecord.CreateTranslationPropertyTree();
|
||||||
|
|
||||||
for (auto& translationUnit : otherWordRecord.translationUnitArr)
|
|
||||||
{
|
|
||||||
boost::property_tree::wptree translationUnitTree;
|
|
||||||
translationUnitTree.put(L"meaning", translationUnit.meaning);
|
|
||||||
translationUnitTree.put(L"comment", translationUnit.comment);
|
|
||||||
translationUnitTree.put(L"example", translationUnit.example);
|
|
||||||
|
|
||||||
allTranslationsTree.push_back(std::make_pair(L"", translationUnitTree));
|
|
||||||
}
|
|
||||||
|
|
||||||
otherWordTree.put_child(L"translations", allTranslationsTree);
|
otherWordTree.put_child(L"translations", allTranslationsTree);
|
||||||
|
|
||||||
|
|
||||||
@ -340,17 +300,7 @@ namespace http {
|
|||||||
prepositionTree.put(L"preposition.availableForInstrumental", prepositionStruct.availableForInstrumental);
|
prepositionTree.put(L"preposition.availableForInstrumental", prepositionStruct.availableForInstrumental);
|
||||||
prepositionTree.put(L"preposition.availableForPrepositional", prepositionStruct.availableForPrepositional);
|
prepositionTree.put(L"preposition.availableForPrepositional", prepositionStruct.availableForPrepositional);
|
||||||
|
|
||||||
boost::property_tree::wptree allTranslationsTree;
|
boost::property_tree::wptree allTranslationsTree = prepositionStruct.CreateTranslationPropertyTree();
|
||||||
|
|
||||||
for (auto& translationUnit : prepositionStruct.translationUnitArr)
|
|
||||||
{
|
|
||||||
boost::property_tree::wptree translationUnitTree;
|
|
||||||
translationUnitTree.put(L"meaning", translationUnit.meaning);
|
|
||||||
translationUnitTree.put(L"comment", translationUnit.comment);
|
|
||||||
translationUnitTree.put(L"example", translationUnit.example);
|
|
||||||
|
|
||||||
allTranslationsTree.push_back(std::make_pair(L"", translationUnitTree));
|
|
||||||
}
|
|
||||||
|
|
||||||
prepositionTree.put_child(L"translations", allTranslationsTree);
|
prepositionTree.put_child(L"translations", allTranslationsTree);
|
||||||
|
|
||||||
|
@ -66,19 +66,8 @@ NounRecord::NounRecord(std::wstring line)
|
|||||||
canBeAnimate = lineArr[10] == L"1" ? true : false;
|
canBeAnimate = lineArr[10] == L"1" ? true : false;
|
||||||
canBeInanimate = lineArr[11] == L"1" ? true : false;
|
canBeInanimate = lineArr[11] == L"1" ? true : false;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
FillTranslationUnit(lineArr, 12);
|
||||||
{
|
|
||||||
TranslationUnit translationUnit;
|
|
||||||
|
|
||||||
translationUnit.meaning = lineArr[12 + i * 3];
|
|
||||||
translationUnit.comment = lineArr[12 + i * 3 + 1];
|
|
||||||
translationUnit.example = lineArr[12 + i * 3 + 2];
|
|
||||||
|
|
||||||
if (translationUnit.meaning != L"")
|
|
||||||
{
|
|
||||||
translationUnitArr.push_back(translationUnit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
namespace NN
|
namespace NN
|
||||||
{
|
{
|
||||||
|
|
||||||
struct NounRecord
|
struct NounRecord : public TranslationUnitSetMix
|
||||||
{
|
{
|
||||||
std::wstring nominativeForm;
|
std::wstring nominativeForm;
|
||||||
NounGender gender;
|
NounGender gender;
|
||||||
@ -35,8 +35,6 @@ namespace NN
|
|||||||
|
|
||||||
std::set<std::wstring> precalculatedNominativePluralSet;
|
std::set<std::wstring> precalculatedNominativePluralSet;
|
||||||
|
|
||||||
std::vector<TranslationUnit> translationUnitArr;
|
|
||||||
|
|
||||||
NounRecord();
|
NounRecord();
|
||||||
NounRecord(std::wstring line);
|
NounRecord(std::wstring line);
|
||||||
|
|
||||||
|
@ -26,19 +26,7 @@ namespace OT
|
|||||||
word = lineArr[1];
|
word = lineArr[1];
|
||||||
type = lineArr[2];
|
type = lineArr[2];
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
FillTranslationUnit(lineArr, 3);
|
||||||
{
|
|
||||||
TranslationUnit translationUnit;
|
|
||||||
|
|
||||||
translationUnit.meaning = lineArr[3 + i * 3];
|
|
||||||
translationUnit.comment = lineArr[3 + i * 3 + 1];
|
|
||||||
translationUnit.example = lineArr[3 + i * 3 + 2];
|
|
||||||
|
|
||||||
if (translationUnit.meaning != L"")
|
|
||||||
{
|
|
||||||
translationUnitArr.push_back(translationUnit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,13 +15,11 @@
|
|||||||
namespace OT
|
namespace OT
|
||||||
{
|
{
|
||||||
|
|
||||||
struct OtherWordRecord
|
struct OtherWordRecord : public TranslationUnitSetMix
|
||||||
{
|
{
|
||||||
std::wstring word;
|
std::wstring word;
|
||||||
std::wstring type;
|
std::wstring type;
|
||||||
|
|
||||||
std::vector<TranslationUnit> translationUnitArr;
|
|
||||||
|
|
||||||
OtherWordRecord();
|
OtherWordRecord();
|
||||||
|
|
||||||
OtherWordRecord(std::wstring line);
|
OtherWordRecord(std::wstring line);
|
||||||
|
@ -36,20 +36,8 @@ namespace PP
|
|||||||
availableForInstrumental = lineArr[5] == L"1" ? true : false;
|
availableForInstrumental = lineArr[5] == L"1" ? true : false;
|
||||||
availableForPrepositional = lineArr[6] == L"1" ? true : false;
|
availableForPrepositional = lineArr[6] == L"1" ? true : false;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
FillTranslationUnit(lineArr, 7);
|
||||||
{
|
|
||||||
TranslationUnit translationUnit;
|
|
||||||
|
|
||||||
translationUnit.meaning = lineArr[7 + i * 3];
|
|
||||||
translationUnit.comment = lineArr[7 + i * 3 + 1];
|
|
||||||
translationUnit.example = lineArr[7 + i * 3 + 2];
|
|
||||||
|
|
||||||
if (translationUnit.meaning != L"")
|
|
||||||
{
|
|
||||||
translationUnitArr.push_back(translationUnit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
namespace PP
|
namespace PP
|
||||||
{
|
{
|
||||||
|
|
||||||
struct PrepositionRecord
|
struct PrepositionRecord : public TranslationUnitSetMix
|
||||||
{
|
{
|
||||||
std::wstring word;
|
std::wstring word;
|
||||||
|
|
||||||
@ -25,8 +25,6 @@ namespace PP
|
|||||||
bool availableForInstrumental;
|
bool availableForInstrumental;
|
||||||
bool availableForPrepositional;
|
bool availableForPrepositional;
|
||||||
|
|
||||||
std::vector<TranslationUnit> translationUnitArr;
|
|
||||||
|
|
||||||
PrepositionRecord();
|
PrepositionRecord();
|
||||||
|
|
||||||
PrepositionRecord(std::wstring line);
|
PrepositionRecord(std::wstring line);
|
||||||
|
@ -39,20 +39,8 @@ namespace VB
|
|||||||
canBePerfect = lineArr[4] == L"1" ? true : false;
|
canBePerfect = lineArr[4] == L"1" ? true : false;
|
||||||
canBeImperfect = lineArr[5] == L"1" ? true : false;
|
canBeImperfect = lineArr[5] == L"1" ? true : false;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
FillTranslationUnit(lineArr, 6);
|
||||||
{
|
|
||||||
TranslationUnit translationUnit;
|
|
||||||
|
|
||||||
translationUnit.meaning = lineArr[6 + i * 3];
|
|
||||||
translationUnit.comment = lineArr[6 + i * 3 + 1];
|
|
||||||
translationUnit.example = lineArr[6 + i * 3 + 2];
|
|
||||||
|
|
||||||
if (translationUnit.meaning != L"")
|
|
||||||
{
|
|
||||||
translationUnitArr.push_back(translationUnit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
namespace VB
|
namespace VB
|
||||||
{
|
{
|
||||||
struct VerbRecord
|
struct VerbRecord : public TranslationUnitSetMix
|
||||||
{
|
{
|
||||||
std::wstring infinitive;
|
std::wstring infinitive;
|
||||||
bool canBePrefixed;
|
bool canBePrefixed;
|
||||||
@ -21,8 +21,6 @@ namespace VB
|
|||||||
bool canBePerfect;
|
bool canBePerfect;
|
||||||
bool canBeImperfect;
|
bool canBeImperfect;
|
||||||
|
|
||||||
std::vector<TranslationUnit> translationUnitArr;
|
|
||||||
|
|
||||||
VerbRecord();
|
VerbRecord();
|
||||||
|
|
||||||
VerbRecord(std::wstring line);
|
VerbRecord(std::wstring line);
|
||||||
|
Loading…
Reference in New Issue
Block a user