diff --git a/rudict/frequent_nouns_2000.xlsx b/rudict/frequent_nouns_2000.xlsx index f6794d1..1623a66 100644 Binary files a/rudict/frequent_nouns_2000.xlsx and b/rudict/frequent_nouns_2000.xlsx differ diff --git a/rudict/rudict/adjective.cpp b/rudict/rudict/adjective.cpp index 017c887..20714ae 100644 --- a/rudict/rudict/adjective.cpp +++ b/rudict/rudict/adjective.cpp @@ -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); } diff --git a/rudict/rudict/adjective.h b/rudict/rudict/adjective.h index 5b93fa9..58e79f4 100644 --- a/rudict/rudict/adjective.h +++ b/rudict/rudict/adjective.h @@ -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 translationUnitArr; - AdjectiveRecord(); AdjectiveRecord(std::wstring line); diff --git a/rudict/rudict/grammarCase.cpp b/rudict/rudict/grammarCase.cpp index fcb8ecd..15e6a94 100644 --- a/rudict/rudict/grammarCase.cpp +++ b/rudict/rudict/grammarCase.cpp @@ -2,6 +2,44 @@ #include + + //std::vector translationUnitArr; + +void TranslationUnitSetMix::FillTranslationUnit(const std::vector& 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") diff --git a/rudict/rudict/grammarCase.h b/rudict/rudict/grammarCase.h index bcf8f3d..dbbf1b2 100644 --- a/rudict/rudict/grammarCase.h +++ b/rudict/rudict/grammarCase.h @@ -1,9 +1,15 @@ #ifndef GRAMMAR_CASE_H_INCLUDED #define GRAMMAR_CASE_H_INCLUDED +#include +#include +#include +#include +#include + +#include "boost/algorithm/string.hpp" +#include "boost/property_tree/ptree.hpp" -#include -#include enum NounGender { @@ -47,6 +53,18 @@ struct TranslationUnit std::wstring example; }; +class TranslationUnitSetMix +{ +protected: + std::vector translationUnitArr; + + void FillTranslationUnit(const std::vector& lineArr, int startFrom); + +public: + + boost::property_tree::wptree CreateTranslationPropertyTree() const; +}; + std::wstring NounCountToWString(NounCount nounCount); NounCount WStringToNounCount(std::wstring str); diff --git a/rudict/rudict/http/request_handler.cpp b/rudict/rudict/http/request_handler.cpp index 1a4a761..6074bdc 100644 --- a/rudict/rudict/http/request_handler.cpp +++ b/rudict/rudict/http/request_handler.cpp @@ -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); diff --git a/rudict/rudict/noun.cpp b/rudict/rudict/noun.cpp index 8788b02..3a79919 100644 --- a/rudict/rudict/noun.cpp +++ b/rudict/rudict/noun.cpp @@ -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); + } diff --git a/rudict/rudict/noun.h b/rudict/rudict/noun.h index eb88299..36a0ef1 100644 --- a/rudict/rudict/noun.h +++ b/rudict/rudict/noun.h @@ -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 precalculatedNominativePluralSet; - std::vector translationUnitArr; - NounRecord(); NounRecord(std::wstring line); diff --git a/rudict/rudict/other.cpp b/rudict/rudict/other.cpp index 471e68d..093a684 100644 --- a/rudict/rudict/other.cpp +++ b/rudict/rudict/other.cpp @@ -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); } diff --git a/rudict/rudict/other.h b/rudict/rudict/other.h index a748a69..89f43dc 100644 --- a/rudict/rudict/other.h +++ b/rudict/rudict/other.h @@ -15,13 +15,11 @@ namespace OT { - struct OtherWordRecord + struct OtherWordRecord : public TranslationUnitSetMix { std::wstring word; std::wstring type; - std::vector translationUnitArr; - OtherWordRecord(); OtherWordRecord(std::wstring line); diff --git a/rudict/rudict/preposition.cpp b/rudict/rudict/preposition.cpp index dc254a3..4ffb7bf 100644 --- a/rudict/rudict/preposition.cpp +++ b/rudict/rudict/preposition.cpp @@ -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); + } diff --git a/rudict/rudict/preposition.h b/rudict/rudict/preposition.h index 5bfcf72..b0296b6 100644 --- a/rudict/rudict/preposition.h +++ b/rudict/rudict/preposition.h @@ -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 translationUnitArr; - PrepositionRecord(); PrepositionRecord(std::wstring line); diff --git a/rudict/rudict/verb.cpp b/rudict/rudict/verb.cpp index 204ffae..03ce242 100644 --- a/rudict/rudict/verb.cpp +++ b/rudict/rudict/verb.cpp @@ -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); + } diff --git a/rudict/rudict/verb.h b/rudict/rudict/verb.h index 85654bf..cb7347b 100644 --- a/rudict/rudict/verb.h +++ b/rudict/rudict/verb.h @@ -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 translationUnitArr; - VerbRecord(); VerbRecord(std::wstring line);