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