lexicon search

This commit is contained in:
rjawor 2017-10-10 16:58:20 +02:00
parent 5e1b032ea0
commit 58406809e7
4 changed files with 28 additions and 0 deletions

View File

@ -239,6 +239,10 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
std::string pattern = _getStringParameter(d, PATTERN_PARAM); std::string pattern = _getStringParameter(d, PATTERN_PARAM);
int tmId = _getIntParameter(d, TM_ID_PARAM); int tmId = _getIntParameter(d, TM_ID_PARAM);
_searcherController->simpleSearch(jsonWriter, pattern, tmId); _searcherController->simpleSearch(jsonWriter, pattern, tmId);
} else if (operation == LEXICON_SEARCH_OP) {
std::string pattern = _getStringParameter(d, PATTERN_PARAM);
int tmId = _getIntParameter(d, TM_ID_PARAM);
_searcherController->lexiconSearch(jsonWriter, pattern, tmId);
} else if (operation == CONCORDIA_SEARCH_OP) { } else if (operation == CONCORDIA_SEARCH_OP) {
std::string pattern = _getStringParameter(d, PATTERN_PARAM); std::string pattern = _getStringParameter(d, PATTERN_PARAM);
int tmId = _getIntParameter(d, TM_ID_PARAM); int tmId = _getIntParameter(d, TM_ID_PARAM);

View File

@ -37,6 +37,7 @@
#define GET_LANGUAGES_OP "getLanguages" #define GET_LANGUAGES_OP "getLanguages"
#define REFRESH_INDEX_OP "refreshIndex" #define REFRESH_INDEX_OP "refreshIndex"
#define SIMPLE_SEARCH_OP "simpleSearch" #define SIMPLE_SEARCH_OP "simpleSearch"
#define LEXICON_SEARCH_OP "lexiconSearch"
#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"

View File

@ -40,6 +40,25 @@ void SearcherController::simpleSearch(rapidjson::Writer<rapidjson::StringBuffer>
} }
} }
void SearcherController::lexiconSearch(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter,
std::string & pattern,
const int tmId) {
boost::ptr_map<int,Concordia>::iterator it = _concordiasMap->find(tmId);
if (it != _concordiasMap->end()) {
TokenizedSentence tokenizedPattern = it->second->tokenize(pattern, false, false);
pattern = _lemmatizerFacade->lemmatizeIfNeeded(tokenizedPattern.getTokenizedSentence(), tmId);
SimpleSearchResult result = _unitDAO.getSimpleSearchResult(it->second->lexiconSearch(pattern, true));
jsonWriter.StartObject();
jsonWriter.String("status");
jsonWriter.String("success");
jsonWriter.String("result");
JsonGenerator::writeSimpleSearchResult(jsonWriter, result);
jsonWriter.EndObject();
} else {
JsonGenerator::signalError(jsonWriter, "no such tm!");
}
}
void SearcherController::concordiaPhraseSearch(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter, void SearcherController::concordiaPhraseSearch(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter,
std::string & pattern, std::string & pattern,
const std::vector<Interval> & intervals, const std::vector<Interval> & intervals,

View File

@ -29,6 +29,10 @@ public:
std::string & pattern, std::string & pattern,
const int tmId); const int tmId);
void lexiconSearch(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter,
std::string & pattern,
const int tmId);
void concordiaSearch(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter, void concordiaSearch(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter,
std::string & pattern, std::string & pattern,
const int tmId); const int tmId);