working simple search
This commit is contained in:
parent
10641ecb6c
commit
63c44d55ea
@ -99,6 +99,10 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
|
|||||||
jsonWriter.String(tm.getSourceLanguageCode().c_str());
|
jsonWriter.String(tm.getSourceLanguageCode().c_str());
|
||||||
jsonWriter.String("targetLanguageCode");
|
jsonWriter.String("targetLanguageCode");
|
||||||
jsonWriter.String(tm.getTargetLanguageCode().c_str());
|
jsonWriter.String(tm.getTargetLanguageCode().c_str());
|
||||||
|
jsonWriter.String("lemmatized");
|
||||||
|
jsonWriter.Bool(tm.isLemmatized());
|
||||||
|
jsonWriter.String("pairedTmId");
|
||||||
|
jsonWriter.Int(tm.getPairedTmId());
|
||||||
jsonWriter.EndObject();
|
jsonWriter.EndObject();
|
||||||
}
|
}
|
||||||
jsonWriter.EndArray();
|
jsonWriter.EndArray();
|
||||||
@ -250,6 +254,26 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
|
|||||||
jsonWriter.String("newTmId");
|
jsonWriter.String("newTmId");
|
||||||
jsonWriter.Int(newId);
|
jsonWriter.Int(newId);
|
||||||
jsonWriter.EndObject();
|
jsonWriter.EndObject();
|
||||||
|
} else if (operation == ADD_PAIRED_TMS_OP) {
|
||||||
|
int sourceLangId = _getIntParameter(d, SOURCE_LANG_PARAM);
|
||||||
|
int targetLangId = _getIntParameter(d, TARGET_LANG_PARAM);
|
||||||
|
std::string name = _getStringParameter(d, NAME_PARAM);
|
||||||
|
std::string nameLemmatized = name;
|
||||||
|
nameLemmatized.append("_lemmatized");
|
||||||
|
|
||||||
|
int lemmatizedTmId = _tmDAO.addTm(sourceLangId, targetLangId, name, true);
|
||||||
|
_addTm(lemmatizedTmId);
|
||||||
|
int nonLemmatizedTmId = _tmDAO.addTm(sourceLangId, targetLangId, name, false, lemmatizedTmId);
|
||||||
|
_addTm(nonLemmatizedTmId);
|
||||||
|
|
||||||
|
jsonWriter.StartObject();
|
||||||
|
jsonWriter.String("status");
|
||||||
|
jsonWriter.String("success");
|
||||||
|
jsonWriter.String("lemmatizedTmId");
|
||||||
|
jsonWriter.Int(lemmatizedTmId);
|
||||||
|
jsonWriter.String("nonLemmatizedTmId");
|
||||||
|
jsonWriter.Int(nonLemmatizedTmId);
|
||||||
|
jsonWriter.EndObject();
|
||||||
} else if (operation == ADD_SOURCE_OP) {
|
} else if (operation == ADD_SOURCE_OP) {
|
||||||
int externalId = _getIntParameter(d, EXTERNAL_ID_PARAM);
|
int externalId = _getIntParameter(d, EXTERNAL_ID_PARAM);
|
||||||
std::string name = _getStringParameter(d, NAME_PARAM);
|
std::string name = _getStringParameter(d, NAME_PARAM);
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#define CONCORDIA_SEARCH_OP "concordiaSearch"
|
#define CONCORDIA_SEARCH_OP "concordiaSearch"
|
||||||
#define CONCORDIA_PHRASE_SEARCH_OP "concordiaPhraseSearch"
|
#define CONCORDIA_PHRASE_SEARCH_OP "concordiaPhraseSearch"
|
||||||
#define ADD_TM_OP "addTm"
|
#define ADD_TM_OP "addTm"
|
||||||
|
#define ADD_PAIRED_TMS_OP "addPairedTms"
|
||||||
#define ADD_SOURCE_OP "addSource"
|
#define ADD_SOURCE_OP "addSource"
|
||||||
#define ADD_SOURCES_OP "addSources"
|
#define ADD_SOURCES_OP "addSources"
|
||||||
|
|
||||||
|
@ -28,21 +28,30 @@ void SearcherController::simpleSearch(rapidjson::Writer<rapidjson::StringBuffer>
|
|||||||
// tmId should point to non-lemmatized memory
|
// tmId should point to non-lemmatized memory
|
||||||
boost::ptr_map<int,Concordia>::iterator it = _concordiasMap->find(tmId);
|
boost::ptr_map<int,Concordia>::iterator it = _concordiasMap->find(tmId);
|
||||||
if (it != _concordiasMap->end()) {
|
if (it != _concordiasMap->end()) {
|
||||||
|
Logger::logString("simple search for pattern", pattern);
|
||||||
TokenizedSentence tokenizedPattern = it->second->tokenize(pattern, false, false);
|
TokenizedSentence tokenizedPattern = it->second->tokenize(pattern, false, false);
|
||||||
|
Logger::logInt("queried tm", tmId);
|
||||||
Tm tm = _tmDAO.getTm(tmId);
|
Tm tm = _tmDAO.getTm(tmId);
|
||||||
|
Logger::logInt("paired tm", tm.getPairedTmId());
|
||||||
LemmatizerResult lemmatizerResult = _lemmatizerFacade->lemmatizeSentence(
|
LemmatizerResult lemmatizerResult = _lemmatizerFacade->lemmatizeSentence(
|
||||||
tm.getSourceLanguageCode(), tokenizedPattern.getTokenizedSentence());
|
tm.getSourceLanguageCode(), tokenizedPattern.getTokenizedSentence());
|
||||||
|
std::string pattern = tokenizedPattern.getTokenizedSentence();
|
||||||
|
Logger::logString("tokenized pattern", tokenizedPattern.getTokenizedSentence());
|
||||||
|
Logger::logString("lemmatized pattern", lemmatizerResult.getLemmatizedSentence());
|
||||||
if (lemmatizerResult.isFirstLemmatized()) {
|
if (lemmatizerResult.isFirstLemmatized()) {
|
||||||
|
Logger::log("searching in paired memory");
|
||||||
// search in lemmatized memory
|
// search in lemmatized memory
|
||||||
it = _concordiasMap->find(tm.getPairedTmId());
|
it = _concordiasMap->find(tm.getPairedTmId());
|
||||||
|
pattern = lemmatizerResult.getLemmatizedSentence();
|
||||||
|
Logger::logString("Changing pattern to lemmatized", pattern);
|
||||||
if (it == _concordiasMap->end()) {
|
if (it == _concordiasMap->end()) {
|
||||||
JsonGenerator::signalError(jsonWriter, "paired tm not found!");
|
JsonGenerator::signalError(jsonWriter, "paired tm not found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Logger::logString("Final pattern", pattern);
|
||||||
SimpleSearchResult result = _unitDAO.getSimpleSearchResult(
|
SimpleSearchResult result = _unitDAO.getSimpleSearchResult(
|
||||||
it->second->simpleSearch(lemmatizerResult.getLemmatizedSentence(), true));
|
it->second->simpleSearch(pattern, true));
|
||||||
jsonWriter.StartObject();
|
jsonWriter.StartObject();
|
||||||
jsonWriter.String("status");
|
jsonWriter.String("status");
|
||||||
jsonWriter.String("success");
|
jsonWriter.String("success");
|
||||||
|
@ -4,10 +4,12 @@ Tm::Tm(const int id,
|
|||||||
const std::string & name,
|
const std::string & name,
|
||||||
const std::string & sourceLanguageCode,
|
const std::string & sourceLanguageCode,
|
||||||
const std::string & targetLanguageCode,
|
const std::string & targetLanguageCode,
|
||||||
|
const bool lemmatized,
|
||||||
const int pairedTmId) :
|
const int pairedTmId) :
|
||||||
_id(id),_name(name),
|
_id(id),_name(name),
|
||||||
_sourceLanguageCode(sourceLanguageCode),
|
_sourceLanguageCode(sourceLanguageCode),
|
||||||
_targetLanguageCode(targetLanguageCode),
|
_targetLanguageCode(targetLanguageCode),
|
||||||
|
_lemmatized(lemmatized),
|
||||||
_pairedTmId(pairedTmId) {
|
_pairedTmId(pairedTmId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ public:
|
|||||||
const std::string & name,
|
const std::string & name,
|
||||||
const std::string & sourceLanguageCode,
|
const std::string & sourceLanguageCode,
|
||||||
const std::string & targetLanguageCode,
|
const std::string & targetLanguageCode,
|
||||||
|
const bool lemmatized,
|
||||||
const int pairedTmId);
|
const int pairedTmId);
|
||||||
|
|
||||||
/*! Destructor.
|
/*! Destructor.
|
||||||
@ -34,6 +35,10 @@ public:
|
|||||||
return _targetLanguageCode;
|
return _targetLanguageCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isLemmatized() const {
|
||||||
|
return _lemmatized;
|
||||||
|
}
|
||||||
|
|
||||||
int getPairedTmId() const {
|
int getPairedTmId() const {
|
||||||
return _pairedTmId;
|
return _pairedTmId;
|
||||||
}
|
}
|
||||||
@ -47,6 +52,8 @@ private:
|
|||||||
|
|
||||||
std::string _targetLanguageCode;
|
std::string _targetLanguageCode;
|
||||||
|
|
||||||
|
bool _lemmatized;
|
||||||
|
|
||||||
int _pairedTmId;
|
int _pairedTmId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "int_param.hpp"
|
#include "int_param.hpp"
|
||||||
#include "bool_param.hpp"
|
#include "bool_param.hpp"
|
||||||
#include "int_array_param.hpp"
|
#include "int_array_param.hpp"
|
||||||
#include "logger.hpp"
|
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
@ -36,15 +35,16 @@ std::vector<Tm> TmDAO::getTms() {
|
|||||||
std::vector<Tm> result;
|
std::vector<Tm> result;
|
||||||
DBconnection connection;
|
DBconnection connection;
|
||||||
connection.startTransaction();
|
connection.startTransaction();
|
||||||
std::string query = "select tm.id, tm.name, src_lang.code as src_code, trg_lang.code as trg_code, paired_tm_id from tm inner join language as src_lang on src_lang.id = tm.source_lang_id inner join language as trg_lang on trg_lang.id = tm.target_lang_id;";
|
std::string query = "select tm.id, tm.name, src_lang.code as src_code, trg_lang.code as trg_code, lemmatized, paired_tm_id from tm inner join language as src_lang on src_lang.id = tm.source_lang_id inner join language as trg_lang on trg_lang.id = tm.target_lang_id;";
|
||||||
PGresult * dbResult = connection.execute(query);
|
PGresult * dbResult = connection.execute(query);
|
||||||
for (int i=0;i<connection.getRowCount(dbResult);i++) {
|
for (int i=0;i<connection.getRowCount(dbResult);i++) {
|
||||||
int id = connection.getIntValue(dbResult, i, 0);
|
int id = connection.getIntValue(dbResult, i, 0);
|
||||||
std::string name = connection.getStringValue(dbResult, i, 1);
|
std::string name = connection.getStringValue(dbResult, i, 1);
|
||||||
std::string sourceLanguageCode = connection.getStringValue(dbResult, i, 2);
|
std::string sourceLanguageCode = connection.getStringValue(dbResult, i, 2);
|
||||||
std::string targetLanguageCode = connection.getStringValue(dbResult, i, 3);
|
std::string targetLanguageCode = connection.getStringValue(dbResult, i, 3);
|
||||||
int pairedTmId = connection.getIntValue(dbResult, i, 4);
|
bool lemmatized = connection.getBoolValue(dbResult, i, 4);
|
||||||
result.push_back(Tm(id, name, sourceLanguageCode, targetLanguageCode, pairedTmId));
|
int pairedTmId = connection.getIntValue(dbResult, i, 5);
|
||||||
|
result.push_back(Tm(id, name, sourceLanguageCode, targetLanguageCode, lemmatized, pairedTmId));
|
||||||
}
|
}
|
||||||
connection.clearResult(dbResult);
|
connection.clearResult(dbResult);
|
||||||
connection.endTransaction();
|
connection.endTransaction();
|
||||||
@ -58,11 +58,11 @@ std::vector<Tm> TmDAO::getTms() {
|
|||||||
|
|
||||||
|
|
||||||
int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name) {
|
int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name) {
|
||||||
addTm(sourceLangId, targetLangId, name, false, -1);
|
return addTm(sourceLangId, targetLangId, name, false, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized) {
|
int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized) {
|
||||||
addTm(sourceLangId, targetLangId, name, lemmatized, -1);
|
return addTm(sourceLangId, targetLangId, name, lemmatized, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized, int pairedTmId) {
|
int TmDAO::addTm(const int sourceLangId, const int targetLangId, const std::string name, bool lemmatized, int pairedTmId) {
|
||||||
@ -105,6 +105,6 @@ Tm TmDAO::getTm(int tmId) {
|
|||||||
connection.clearResult(dbResult);
|
connection.clearResult(dbResult);
|
||||||
connection.endTransaction();
|
connection.endTransaction();
|
||||||
|
|
||||||
return Tm(id, name, sourceLanguageCode, targetLanguageCode, pairedTmId);
|
return Tm(id, name, sourceLanguageCode, targetLanguageCode, lemmatized, pairedTmId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user