diff --git a/concordia-server/lemmatizer_facade.cpp b/concordia-server/lemmatizer_facade.cpp index 1cfdd13..df7bc27 100644 --- a/concordia-server/lemmatizer_facade.cpp +++ b/concordia-server/lemmatizer_facade.cpp @@ -37,26 +37,3 @@ std::vector LemmatizerFacade::lemmatizeSentences(std::string langua return result; } - -std::string LemmatizerFacade::lemmatizeIfNeeded(std::string pattern, int tmId) { - std::pair tmInfo = _tmDAO.getTmInfo(tmId); - if (tmInfo.first) { - return lemmatizeSentence(tmInfo.second, pattern); - } else { - return pattern; - } -} - -std::vector LemmatizerFacade::lemmatizeSentencesIfNeeded(std::vector patterns, int tmId) { - std::pair tmInfo = _tmDAO.getTmInfo(tmId); - if (tmInfo.first) { - std::vector result; - BOOST_FOREACH(std::string & pattern, patterns) { - result.push_back(lemmatizeSentence(tmInfo.second, pattern)); - } - return result; - } else { - return patterns; - } - -} diff --git a/concordia-server/lemmatizer_facade.hpp b/concordia-server/lemmatizer_facade.hpp index 0039568..0d8d8aa 100644 --- a/concordia-server/lemmatizer_facade.hpp +++ b/concordia-server/lemmatizer_facade.hpp @@ -23,14 +23,8 @@ public: std::vector lemmatizeSentences(std::string languageCode, std::vector sentences); - std::string lemmatizeIfNeeded(std::string pattern, int tmId); - - std::vector lemmatizeSentencesIfNeeded(std::vector patterns, int tmId); - private: boost::ptr_map _lemmatizersMap; - - TmDAO _tmDAO; }; #endif diff --git a/concordia-server/tm.cpp b/concordia-server/tm.cpp index 4b2158e..b481846 100644 --- a/concordia-server/tm.cpp +++ b/concordia-server/tm.cpp @@ -3,10 +3,12 @@ Tm::Tm(const int id, const std::string & name, const std::string & sourceLanguageCode, - const std::string & targetLanguageCode) : - _id(id),_name(name), - _sourceLanguageCode(sourceLanguageCode), - _targetLanguageCode(targetLanguageCode) { + const std::string & targetLanguageCode, + const in pairedTmId) : + _id(id),_name(name), + _sourceLanguageCode(sourceLanguageCode), + _targetLanguageCode(targetLanguageCode), + _pairedTmId(pairedTmId) { } Tm::~Tm() { diff --git a/concordia-server/tm.hpp b/concordia-server/tm.hpp index e895a45..8a07943 100644 --- a/concordia-server/tm.hpp +++ b/concordia-server/tm.hpp @@ -11,7 +11,9 @@ public: Tm(const int id, const std::string & name, const std::string & sourceLanguageCode, - const std::string & targetLanguageCode); + const std::string & targetLanguageCode, + const int pairedTmId); + /*! Destructor. */ virtual ~Tm(); @@ -32,6 +34,9 @@ public: return _targetLanguageCode; } + int getPairedTmId() const { + return _pairedTmId; + } private: int _id; @@ -41,6 +46,8 @@ private: std::string _sourceLanguageCode; std::string _targetLanguageCode; + + int _pairedTmId; }; #endif diff --git a/concordia-server/tm_dao.cpp b/concordia-server/tm_dao.cpp index 711aa86..0a997e5 100644 --- a/concordia-server/tm_dao.cpp +++ b/concordia-server/tm_dao.cpp @@ -57,19 +57,24 @@ std::vector TmDAO::getTms() { int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name) { - addTm(sourceLangId, targetLangId, name, false); + addTm(sourceLangId, targetLangId, name, false, -1); } int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized) { + addTm(sourceLangId, targetLangId, name, lemmatized, -1); +} + +int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized, int pairedTmId) { DBconnection connection; connection.startTransaction(); - std::string query = "INSERT INTO tm(source_lang_id, target_lang_id, name, lemmatized) values($1::integer,$2::integer,$3::text,$4::bool) RETURNING id"; + std::string query = "INSERT INTO tm(source_lang_id, target_lang_id, name, lemmatized, paired_tm_id) values($1::integer,$2::integer,$3::text,$4::bool,$5::integer) RETURNING id"; std::vector params; params.push_back(new IntParam(sourceLangId)); params.push_back(new IntParam(targetLangId)); params.push_back(new StringParam(name)); params.push_back(new BoolParam(lemmatized)); + params.push_back(new IntParam(pairedTmId)); PGresult * result = connection.execute(query, params); int newId = connection.getIntValue(result, 0, 0); @@ -83,18 +88,22 @@ int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::stri } -std::pair TmDAO::getTmInfo(int tmId) { +Tm TmDAO::getTmInfo(int tmId) { DBconnection connection; connection.startTransaction(); - std::string query = "select tm.id, tm.lemmatized, language.code from tm inner join language on language.id = tm.source_lang_id where tm.id = $1::integer;"; + std::string query = "select tm.id, tm.name, tm.lemmatized, tm.paired_tm_id, source_language.code, target_language.code from tm inner join language as source_language on source_language.id = tm.source_lang_id inner join language as target_language on target_language.id = tm.target_lang_id where tm.id = $1::integer;"; std::vector params; params.push_back(new IntParam(tmId)); PGresult * dbResult = connection.execute(query, params); - bool lemmatized = connection.getBoolValue(dbResult, 0, 1); - std::string languageCode = connection.getStringValue(dbResult, 0, 2); + int id = connection.getIntValue(dbResult, 0, 0); + std::string name = connection.getStringValue(dbResult, 0, 1); + bool lemmatized = connection.getBoolValue(dbResult, 0, 2); + int pairedTmId = connection.getIntValue(dbResult, 0, 3); + std::string sourceLanguageCode = connection.getStringValue(dbResult, 0, 4); + std::string targetLanguageCode = connection.getStringValue(dbResult, 0, 5); connection.clearResult(dbResult); connection.endTransaction(); - return std::pair(lemmatized, languageCode); + return Tm(id, name, sourceLanguageCode, targetLanguageCode, pairedTmId); } diff --git a/concordia-server/tm_dao.hpp b/concordia-server/tm_dao.hpp index b5fbe8e..1bd7227 100644 --- a/concordia-server/tm_dao.hpp +++ b/concordia-server/tm_dao.hpp @@ -22,6 +22,8 @@ public: int addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized); + int addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized, int pairedTmId); + std::vector getTmIds(); std::vector getTms();