From b446c15faa4fc90b4c4b6d245a75aa2607705613 Mon Sep 17 00:00:00 2001 From: rjawor Date: Wed, 29 Aug 2018 15:00:48 +0200 Subject: [PATCH] truncated concordia response --- cat/js/cat.js | 22 +++++- concordia-server/unit_dao.cpp | 127 ++++++++++++++++++---------------- concordia-server/unit_dao.hpp | 5 ++ 3 files changed, 93 insertions(+), 61 deletions(-) diff --git a/cat/js/cat.js b/cat/js/cat.js index 93bf02b..610edb7 100644 --- a/cat/js/cat.js +++ b/cat/js/cat.js @@ -97,7 +97,8 @@ function renderResult(data) { markedSentence += htmlEncode(inputSentence.slice(lastInsertedEnd, fragment['matchedPatternStart'])); //the marked fragment - markedSentence += ''+htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd']))+''; + var textFragment = htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd'])); + markedSentence += ''+textFragment+''; lastInsertedEnd = fragment['matchedPatternEnd']; @@ -170,6 +171,25 @@ function displayDetails(caller, number) { } } +function secondStepSearch(caller) { + var concordiaRequest = { + operation: 'simpleSearch', + tmId: currentTmId, + pattern:caller.innerHTML + } + + $.ajax({ + url: '/cat/concordia_gate.php', + type: 'post', + dataType: 'json', + success: function (data) { + console.log(data); + }, + data: concordiaRequest + }); + +} + function searchText(text, tmid) { $("#search-input").val(text); searchHandle(tmid); diff --git a/concordia-server/unit_dao.cpp b/concordia-server/unit_dao.cpp index 85370b3..a3c4709 100644 --- a/concordia-server/unit_dao.cpp +++ b/concordia-server/unit_dao.cpp @@ -69,7 +69,7 @@ std::vector UnitDAO::addAlignedSentences( SimpleSearchResult UnitDAO::getSimpleSearchResult(const MatchedPatternFragment & fragment) { SimpleSearchResult result(fragment.getStart(), fragment.getEnd()); TokenizedSentence ts(""); - return _getResultFromFragment(fragment, ts); + return _getResultFromFragment(fragment, ts, true); } CompleteConcordiaSearchResult UnitDAO::getConcordiaResult(boost::shared_ptr rawConcordiaResult) { @@ -91,8 +91,14 @@ CompleteConcordiaSearchResult UnitDAO::getConcordiaResult(boost::shared_ptr params; - params.push_back(new IntParam(2*sOccurence.getOffset()+1)); - params.push_back(new IntParam(2*(sOccurence.getOffset()+fragment.getMatchedLength()))); - params.push_back(new IntParam(sOccurence.getId())); - PGresult * result = connection.execute(query, params); - Logger::log("got examples"); - ExampleOccurence occurence(connection.getIntValue(result,0,0), // example id - connection.getIntValue(result,0,3), // matched example start - connection.getIntValue(result,0,4), // matched example end - connection.getStringValue(result,0,1), // source segment - connection.getStringValue(result,0,2)); // target segment - connection.clearResult(result); - BOOST_FOREACH (QueryParam * param, params) { - delete param; - } - - // now add all target fragments matched with this fragment - std::string targetQuery = "SELECT target_token_pos, target_tokens[2*target_token_pos+1], target_tokens[2*target_token_pos+2] FROM unit INNER JOIN alignment ON alignment.unit_id = unit.id AND unit.id = $1::integer AND source_token_pos between $2::integer and $3::integer ORDER BY target_token_pos"; - std::vector targetParams; - targetParams.push_back(new IntParam(sOccurence.getId())); - targetParams.push_back(new IntParam(sOccurence.getOffset())); - targetParams.push_back(new IntParam(sOccurence.getOffset() + fragment.getMatchedLength() - 1)); - PGresult * targetResult = connection.execute(targetQuery, targetParams); - Logger::log("got target fragments"); - - int prevPos = -2; - int currStart = -1; - int currEnd = -1; - - for (int i=0;i= 0) { - occurence.addMatchedTargetFragment(std::pair(currStart,currEnd)); - } - currStart = targetStart; + if (getOccurences) { + BOOST_FOREACH(SubstringOccurence sOccurence, fragment.getOccurences()) { + std::string query = "SELECT id, source_segment, target_segment, source_tokens[$1::integer], source_tokens[$2::integer] FROM unit WHERE id = $3::integer;"; + std::vector params; + params.push_back(new IntParam(2*sOccurence.getOffset()+1)); + params.push_back(new IntParam(2*(sOccurence.getOffset()+fragment.getMatchedLength()))); + params.push_back(new IntParam(sOccurence.getId())); + PGresult * result = connection.execute(query, params); + Logger::log("got examples"); + ExampleOccurence occurence(connection.getIntValue(result,0,0), // example id + connection.getIntValue(result,0,3), // matched example start + connection.getIntValue(result,0,4), // matched example end + connection.getStringValue(result,0,1), // source segment + connection.getStringValue(result,0,2)); // target segment + connection.clearResult(result); + BOOST_FOREACH (QueryParam * param, params) { + delete param; } - currEnd = targetEnd; - prevPos = targetPos; + // now add all target fragments matched with this fragment + std::string targetQuery = "SELECT target_token_pos, target_tokens[2*target_token_pos+1], target_tokens[2*target_token_pos+2] FROM unit INNER JOIN alignment ON alignment.unit_id = unit.id AND unit.id = $1::integer AND source_token_pos between $2::integer and $3::integer ORDER BY target_token_pos"; + std::vector targetParams; + targetParams.push_back(new IntParam(sOccurence.getId())); + targetParams.push_back(new IntParam(sOccurence.getOffset())); + targetParams.push_back(new IntParam(sOccurence.getOffset() + fragment.getMatchedLength() - 1)); + PGresult * targetResult = connection.execute(targetQuery, targetParams); + Logger::log("got target fragments"); + + int prevPos = -2; + int currStart = -1; + int currEnd = -1; + + for (int i=0;i= 0) { + occurence.addMatchedTargetFragment(std::pair(currStart,currEnd)); + } + currStart = targetStart; + } + + currEnd = targetEnd; + prevPos = targetPos; + } + + // check if there are remaining fragments + if (currStart >= 0) { + occurence.addMatchedTargetFragment(std::pair(currStart,currEnd)); + } + + connection.clearResult(targetResult); + BOOST_FOREACH (QueryParam * param, targetParams) { + delete param; + } + + ssResult.addOccurence(occurence); + } - - // check if there are remaining fragments - if (currStart >= 0) { - occurence.addMatchedTargetFragment(std::pair(currStart,currEnd)); - } - - connection.clearResult(targetResult); - BOOST_FOREACH (QueryParam * param, targetParams) { - delete param; - } - - ssResult.addOccurence(occurence); - } - connection.endTransaction(); return ssResult; diff --git a/concordia-server/unit_dao.hpp b/concordia-server/unit_dao.hpp index edf87ee..174ecc0 100644 --- a/concordia-server/unit_dao.hpp +++ b/concordia-server/unit_dao.hpp @@ -52,6 +52,11 @@ private: const MatchedPatternFragment & fragment, const TokenizedSentence & tokenizedPattern); + SimpleSearchResult _getResultFromFragment( + const MatchedPatternFragment & fragment, + const TokenizedSentence & tokenizedPattern, + bool getOccurences); + std::vector _getTokenPositions(const TokenizedSentence & ts); int _addSingleSentence(