lemmatized tms
This commit is contained in:
parent
fb6440eba6
commit
84d8102f58
@ -37,26 +37,3 @@ std::vector<std::string> LemmatizerFacade::lemmatizeSentences(std::string langua
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
std::string LemmatizerFacade::lemmatizeIfNeeded(std::string pattern, int tmId) {
|
||||
std::pair<bool, std::string> tmInfo = _tmDAO.getTmInfo(tmId);
|
||||
if (tmInfo.first) {
|
||||
return lemmatizeSentence(tmInfo.second, pattern);
|
||||
} else {
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> LemmatizerFacade::lemmatizeSentencesIfNeeded(std::vector<std::string> patterns, int tmId) {
|
||||
std::pair<bool, std::string> tmInfo = _tmDAO.getTmInfo(tmId);
|
||||
if (tmInfo.first) {
|
||||
std::vector<std::string> result;
|
||||
BOOST_FOREACH(std::string & pattern, patterns) {
|
||||
result.push_back(lemmatizeSentence(tmInfo.second, pattern));
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,14 +23,8 @@ public:
|
||||
|
||||
std::vector<std::string> lemmatizeSentences(std::string languageCode, std::vector<std::string> sentences);
|
||||
|
||||
std::string lemmatizeIfNeeded(std::string pattern, int tmId);
|
||||
|
||||
std::vector<std::string> lemmatizeSentencesIfNeeded(std::vector<std::string> patterns, int tmId);
|
||||
|
||||
private:
|
||||
boost::ptr_map<std::string,JsonLemmatizer> _lemmatizersMap;
|
||||
|
||||
TmDAO _tmDAO;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -57,19 +57,24 @@ std::vector<Tm> 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<QueryParam*> 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<bool, std::string> 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<QueryParam*> 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<bool, std::string>(lemmatized, languageCode);
|
||||
return Tm(id, name, sourceLanguageCode, targetLanguageCode, pairedTmId);
|
||||
|
||||
}
|
||||
|
@ -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<int> getTmIds();
|
||||
|
||||
std::vector<Tm> getTms();
|
||||
|
Loading…
Reference in New Issue
Block a user