truncated concordia response
This commit is contained in:
parent
44905f3a61
commit
b446c15faa
@ -97,7 +97,8 @@ function renderResult(data) {
|
|||||||
markedSentence += htmlEncode(inputSentence.slice(lastInsertedEnd, fragment['matchedPatternStart']));
|
markedSentence += htmlEncode(inputSentence.slice(lastInsertedEnd, fragment['matchedPatternStart']));
|
||||||
|
|
||||||
//the marked fragment
|
//the marked fragment
|
||||||
markedSentence += '<span onclick="displayDetails(this, '+i+')" class="matchedFragment">'+htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd']))+'</span>';
|
var textFragment = htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd']));
|
||||||
|
markedSentence += '<span onclick="secondStepSearch(this)" class="matchedFragment">'+textFragment+'</span>';
|
||||||
|
|
||||||
lastInsertedEnd = fragment['matchedPatternEnd'];
|
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) {
|
function searchText(text, tmid) {
|
||||||
$("#search-input").val(text);
|
$("#search-input").val(text);
|
||||||
searchHandle(tmid);
|
searchHandle(tmid);
|
||||||
|
@ -69,7 +69,7 @@ std::vector<SUFFIX_MARKER_TYPE> UnitDAO::addAlignedSentences(
|
|||||||
SimpleSearchResult UnitDAO::getSimpleSearchResult(const MatchedPatternFragment & fragment) {
|
SimpleSearchResult UnitDAO::getSimpleSearchResult(const MatchedPatternFragment & fragment) {
|
||||||
SimpleSearchResult result(fragment.getStart(), fragment.getEnd());
|
SimpleSearchResult result(fragment.getStart(), fragment.getEnd());
|
||||||
TokenizedSentence ts("");
|
TokenizedSentence ts("");
|
||||||
return _getResultFromFragment(fragment, ts);
|
return _getResultFromFragment(fragment, ts, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompleteConcordiaSearchResult UnitDAO::getConcordiaResult(boost::shared_ptr<ConcordiaSearchResult> rawConcordiaResult) {
|
CompleteConcordiaSearchResult UnitDAO::getConcordiaResult(boost::shared_ptr<ConcordiaSearchResult> rawConcordiaResult) {
|
||||||
@ -91,8 +91,14 @@ CompleteConcordiaSearchResult UnitDAO::getConcordiaResult(boost::shared_ptr<Conc
|
|||||||
SimpleSearchResult UnitDAO::_getResultFromFragment(
|
SimpleSearchResult UnitDAO::_getResultFromFragment(
|
||||||
const MatchedPatternFragment & fragment,
|
const MatchedPatternFragment & fragment,
|
||||||
const TokenizedSentence & tokenizedPattern) {
|
const TokenizedSentence & tokenizedPattern) {
|
||||||
|
return _getResultFromFragment(fragment, tokenizedPattern, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleSearchResult UnitDAO::_getResultFromFragment(
|
||||||
|
const MatchedPatternFragment & fragment,
|
||||||
|
const TokenizedSentence & tokenizedPattern,
|
||||||
|
bool getOccurences) {
|
||||||
|
|
||||||
Logger::log("_getResultFromFragment");
|
|
||||||
DBconnection connection;
|
DBconnection connection;
|
||||||
connection.startTransaction();
|
connection.startTransaction();
|
||||||
|
|
||||||
@ -106,68 +112,69 @@ SimpleSearchResult UnitDAO::_getResultFromFragment(
|
|||||||
|
|
||||||
SimpleSearchResult ssResult(matchedPatternStart, matchedPatternEnd);
|
SimpleSearchResult ssResult(matchedPatternStart, matchedPatternEnd);
|
||||||
|
|
||||||
BOOST_FOREACH(SubstringOccurence sOccurence, fragment.getOccurences()) {
|
if (getOccurences) {
|
||||||
std::string query = "SELECT id, source_segment, target_segment, source_tokens[$1::integer], source_tokens[$2::integer] FROM unit WHERE id = $3::integer;";
|
BOOST_FOREACH(SubstringOccurence sOccurence, fragment.getOccurences()) {
|
||||||
std::vector<QueryParam*> params;
|
std::string query = "SELECT id, source_segment, target_segment, source_tokens[$1::integer], source_tokens[$2::integer] FROM unit WHERE id = $3::integer;";
|
||||||
params.push_back(new IntParam(2*sOccurence.getOffset()+1));
|
std::vector<QueryParam*> params;
|
||||||
params.push_back(new IntParam(2*(sOccurence.getOffset()+fragment.getMatchedLength())));
|
params.push_back(new IntParam(2*sOccurence.getOffset()+1));
|
||||||
params.push_back(new IntParam(sOccurence.getId()));
|
params.push_back(new IntParam(2*(sOccurence.getOffset()+fragment.getMatchedLength())));
|
||||||
PGresult * result = connection.execute(query, params);
|
params.push_back(new IntParam(sOccurence.getId()));
|
||||||
Logger::log("got examples");
|
PGresult * result = connection.execute(query, params);
|
||||||
ExampleOccurence occurence(connection.getIntValue(result,0,0), // example id
|
Logger::log("got examples");
|
||||||
connection.getIntValue(result,0,3), // matched example start
|
ExampleOccurence occurence(connection.getIntValue(result,0,0), // example id
|
||||||
connection.getIntValue(result,0,4), // matched example end
|
connection.getIntValue(result,0,3), // matched example start
|
||||||
connection.getStringValue(result,0,1), // source segment
|
connection.getIntValue(result,0,4), // matched example end
|
||||||
connection.getStringValue(result,0,2)); // target segment
|
connection.getStringValue(result,0,1), // source segment
|
||||||
connection.clearResult(result);
|
connection.getStringValue(result,0,2)); // target segment
|
||||||
BOOST_FOREACH (QueryParam * param, params) {
|
connection.clearResult(result);
|
||||||
delete param;
|
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<QueryParam*> 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<connection.getRowCount(targetResult);i++) {
|
|
||||||
int targetPos = connection.getIntValue(targetResult, i, 0);
|
|
||||||
int targetStart = connection.getIntValue(targetResult, i, 1);
|
|
||||||
int targetEnd = connection.getIntValue(targetResult, i, 2);
|
|
||||||
|
|
||||||
if (prevPos < targetPos - 1) { // beginning of detached fragment
|
|
||||||
// check if there is a fragment to end
|
|
||||||
if (currStart >= 0) {
|
|
||||||
occurence.addMatchedTargetFragment(std::pair<int,int>(currStart,currEnd));
|
|
||||||
}
|
|
||||||
currStart = targetStart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
currEnd = targetEnd;
|
// now add all target fragments matched with this fragment
|
||||||
prevPos = targetPos;
|
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<QueryParam*> 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<connection.getRowCount(targetResult);i++) {
|
||||||
|
int targetPos = connection.getIntValue(targetResult, i, 0);
|
||||||
|
int targetStart = connection.getIntValue(targetResult, i, 1);
|
||||||
|
int targetEnd = connection.getIntValue(targetResult, i, 2);
|
||||||
|
|
||||||
|
if (prevPos < targetPos - 1) { // beginning of detached fragment
|
||||||
|
// check if there is a fragment to end
|
||||||
|
if (currStart >= 0) {
|
||||||
|
occurence.addMatchedTargetFragment(std::pair<int,int>(currStart,currEnd));
|
||||||
|
}
|
||||||
|
currStart = targetStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
currEnd = targetEnd;
|
||||||
|
prevPos = targetPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if there are remaining fragments
|
||||||
|
if (currStart >= 0) {
|
||||||
|
occurence.addMatchedTargetFragment(std::pair<int,int>(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<int,int>(currStart,currEnd));
|
|
||||||
}
|
|
||||||
|
|
||||||
connection.clearResult(targetResult);
|
|
||||||
BOOST_FOREACH (QueryParam * param, targetParams) {
|
|
||||||
delete param;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssResult.addOccurence(occurence);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.endTransaction();
|
connection.endTransaction();
|
||||||
|
|
||||||
return ssResult;
|
return ssResult;
|
||||||
|
@ -52,6 +52,11 @@ private:
|
|||||||
const MatchedPatternFragment & fragment,
|
const MatchedPatternFragment & fragment,
|
||||||
const TokenizedSentence & tokenizedPattern);
|
const TokenizedSentence & tokenizedPattern);
|
||||||
|
|
||||||
|
SimpleSearchResult _getResultFromFragment(
|
||||||
|
const MatchedPatternFragment & fragment,
|
||||||
|
const TokenizedSentence & tokenizedPattern,
|
||||||
|
bool getOccurences);
|
||||||
|
|
||||||
std::vector<int> _getTokenPositions(const TokenizedSentence & ts);
|
std::vector<int> _getTokenPositions(const TokenizedSentence & ts);
|
||||||
|
|
||||||
int _addSingleSentence(
|
int _addSingleSentence(
|
||||||
|
Loading…
Reference in New Issue
Block a user