diff --git a/rudict/rudict/adjective.cpp b/rudict/rudict/adjective.cpp index b16fc49..b5709c6 100644 --- a/rudict/rudict/adjective.cpp +++ b/rudict/rudict/adjective.cpp @@ -149,12 +149,12 @@ namespace AJ { } - WordModificatorInterface& AdjectivePair::wordModificator() + const WordModificatorInterface& AdjectivePair::wordModificator() const { return modificator; } - WordHolder& AdjectivePair::word() + const WordHolder& AdjectivePair::word() const { return wordRecord; } diff --git a/rudict/rudict/adjective.h b/rudict/rudict/adjective.h index 2b8bb72..f586563 100644 --- a/rudict/rudict/adjective.h +++ b/rudict/rudict/adjective.h @@ -62,9 +62,9 @@ namespace AJ AdjectivePair(AdjectiveStruct iModificator, AdjectiveRecord iWordRecord); - virtual WordModificatorInterface& wordModificator(); + virtual const WordModificatorInterface& wordModificator() const; - virtual WordHolder& word(); + virtual const WordHolder& word() const; virtual std::wstring getType(); }; diff --git a/rudict/rudict/grammarCase.h b/rudict/rudict/grammarCase.h index 380cc85..24a0364 100644 --- a/rudict/rudict/grammarCase.h +++ b/rudict/rudict/grammarCase.h @@ -83,6 +83,11 @@ public: boost::property_tree::wptree CreateTranslationPropertyTree() const; + bool operator==(const WordHolder& other) const + { + return word == other.word; + } + }; class WordModificatorInterface @@ -99,13 +104,18 @@ public: { return modificatorTree; } + + bool operator==(const WordModificatorInterface& other) const + { + return modificatorTree == other.modificatorTree; + } }; struct WordPairInterface { - virtual WordModificatorInterface& wordModificator() = 0; + virtual const WordModificatorInterface& wordModificator() const = 0; - virtual WordHolder& word() = 0; + virtual const WordHolder& word() const = 0; virtual std::wstring getType() = 0; @@ -113,6 +123,16 @@ struct WordPairInterface { } + + bool operator==(const WordPairInterface& other) const + { + return wordModificator() == other.wordModificator() && word() == other.word(); + } + + bool operator!=(const WordPairInterface& other) const + { + return !operator==(other); + } }; std::wstring NounGenderToWString(NounGender g); diff --git a/rudict/rudict/http/request_handler.cpp b/rudict/rudict/http/request_handler.cpp index 3e3f773..5d13ca5 100644 --- a/rudict/rudict/http/request_handler.cpp +++ b/rudict/rudict/http/request_handler.cpp @@ -137,6 +137,29 @@ namespace http { return true; } + void RemoveDuplicates(std::vector>& wordPairSet) + { + size_t i = 0; + + while (i < wordPairSet.size()) + { + size_t j = i + 1; + + while (j < wordPairSet.size()) + { + if (*wordPairSet[i] == *wordPairSet[j]) + { + wordPairSet.erase(wordPairSet.begin() + j); + j--; + } + + j++; + } + + i++; + } + } + boost::property_tree::wptree PrepareReport(std::wstring request) { @@ -158,6 +181,8 @@ namespace http { VB::RecognizeVerb(request, wordPairSet); OT::RecognizeWord(request, wordPairSet); PP::RecognizeWord(request, wordPairSet); + + RemoveDuplicates(wordPairSet); boost::property_tree::wptree wordArr; diff --git a/rudict/rudict/noun.cpp b/rudict/rudict/noun.cpp index 8ce8225..d51c3ca 100644 --- a/rudict/rudict/noun.cpp +++ b/rudict/rudict/noun.cpp @@ -154,12 +154,12 @@ NounPair::NounPair(NounStruct iNounModificator, NounRecord iNoun) { } -WordModificatorInterface& NounPair::wordModificator() +const WordModificatorInterface& NounPair::wordModificator() const { return nounModificator; } -WordHolder& NounPair::word() +const WordHolder& NounPair::word() const { return noun; } diff --git a/rudict/rudict/noun.h b/rudict/rudict/noun.h index 4af06e2..8cd61d1 100644 --- a/rudict/rudict/noun.h +++ b/rudict/rudict/noun.h @@ -151,9 +151,9 @@ namespace NN NounPair(NounStruct iNounModificator, NounRecord iNoun); - virtual WordModificatorInterface& wordModificator(); + virtual const WordModificatorInterface& wordModificator() const; - virtual WordHolder& word(); + virtual const WordHolder& word() const; virtual std::wstring getType(); }; diff --git a/rudict/rudict/other.cpp b/rudict/rudict/other.cpp index 2afea06..edbca12 100644 --- a/rudict/rudict/other.cpp +++ b/rudict/rudict/other.cpp @@ -64,12 +64,12 @@ namespace OT { } - WordModificatorInterface& OtherWordPair::wordModificator() + const WordModificatorInterface& OtherWordPair::wordModificator() const { return modificator; } - WordHolder& OtherWordPair::word() + const WordHolder& OtherWordPair::word() const { return wordRecord; } diff --git a/rudict/rudict/other.h b/rudict/rudict/other.h index 74227c6..9f1f659 100644 --- a/rudict/rudict/other.h +++ b/rudict/rudict/other.h @@ -49,9 +49,9 @@ namespace OT OtherWordPair(OtherWordModificator iModificator, OtherWordRecord iWordRecord); - virtual WordModificatorInterface& wordModificator(); + virtual const WordModificatorInterface& wordModificator() const; - virtual WordHolder& word(); + virtual const WordHolder& word() const; virtual std::wstring getType(); }; diff --git a/rudict/rudict/preposition.cpp b/rudict/rudict/preposition.cpp index f86c7aa..e9c984e 100644 --- a/rudict/rudict/preposition.cpp +++ b/rudict/rudict/preposition.cpp @@ -93,12 +93,12 @@ namespace PP { } - WordModificatorInterface& PrepositionPair::wordModificator() + const WordModificatorInterface& PrepositionPair::wordModificator() const { return modificator; } - WordHolder& PrepositionPair::word() + const WordHolder& PrepositionPair::word() const { return wordRecord; } @@ -108,11 +108,11 @@ namespace PP return L"preposition"; } - - void RecognizeWord(std::wstring word, std::vector>& wordPair) { + std::vector> result; + for (auto& wordRecord : PrepositionRecordArr) { if (wordRecord.GetWord() == word) diff --git a/rudict/rudict/preposition.h b/rudict/rudict/preposition.h index 75327ff..55e5170 100644 --- a/rudict/rudict/preposition.h +++ b/rudict/rudict/preposition.h @@ -51,9 +51,9 @@ namespace PP PrepositionPair(PrepositionModificator iModificator, PrepositionRecord iWordRecord); - virtual WordModificatorInterface& wordModificator(); + virtual const WordModificatorInterface& wordModificator() const; - virtual WordHolder& word(); + virtual const WordHolder& word() const; virtual std::wstring getType(); }; diff --git a/rudict/rudict/verb.cpp b/rudict/rudict/verb.cpp index 1131efb..d16ab2b 100644 --- a/rudict/rudict/verb.cpp +++ b/rudict/rudict/verb.cpp @@ -117,12 +117,12 @@ namespace VB { } - WordModificatorInterface& VerbPair::wordModificator() + const WordModificatorInterface& VerbPair::wordModificator() const { return modificator; } - WordHolder& VerbPair::word() + const WordHolder& VerbPair::word() const { return wordRecord; } diff --git a/rudict/rudict/verb.h b/rudict/rudict/verb.h index 76cf953..9c5fb2f 100644 --- a/rudict/rudict/verb.h +++ b/rudict/rudict/verb.h @@ -79,9 +79,9 @@ namespace VB VerbPair(VerbStruct iModificator, VerbRecord iWordRecord); - virtual WordModificatorInterface& wordModificator(); + virtual const WordModificatorInterface& wordModificator() const; - virtual WordHolder& word(); + virtual const WordHolder& word() const; virtual std::wstring getType(); };