2015-09-01 09:34:27 +02:00
|
|
|
var concordiaUrl = 'http://localhost';
|
|
|
|
|
2015-08-26 20:13:57 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
$('#searchInput').bind("enterKey",function(e){
|
|
|
|
searchHandle();
|
|
|
|
});
|
|
|
|
$('#searchInput').keyup(function(e){
|
|
|
|
if(e.keyCode == 13) {
|
|
|
|
$(this).trigger("enterKey");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function searchHandle() {
|
|
|
|
var concordiaRequest = {
|
|
|
|
operation: 'concordiaSearch',
|
|
|
|
pattern:$("#searchInput").val()
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
2015-09-01 09:34:27 +02:00
|
|
|
url: concordiaUrl,
|
2015-08-26 20:13:57 +02:00
|
|
|
type: 'post',
|
|
|
|
dataType: 'json',
|
|
|
|
success: function (data) {
|
|
|
|
$('#result').html(renderResult(data));
|
|
|
|
},
|
|
|
|
data: JSON.stringify(concordiaRequest)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderResult(data) {
|
|
|
|
var res = '';
|
|
|
|
|
|
|
|
var score = data['result']['bestOverlayScore']*100;
|
|
|
|
|
|
|
|
res += '<div id="result-score">Concordia score: <b>'+score.toFixed(0)+'%</b></div>';
|
|
|
|
|
|
|
|
var inputSentence = $('#searchInput').val();
|
|
|
|
var markedSentence = '';
|
|
|
|
var fragments = '';
|
|
|
|
lastInsertedEnd = 0;
|
|
|
|
for(var i = 0; i < data['result']['bestOverlay'].length; i++) {
|
|
|
|
var fragment = data['result']['bestOverlay'][i];
|
|
|
|
//previous unmarked fragment
|
|
|
|
markedSentence += inputSentence.slice(lastInsertedEnd, fragment['matchedPatternStart']);
|
|
|
|
|
|
|
|
//the marked fragment
|
2015-08-27 07:29:29 +02:00
|
|
|
markedSentence += '<span onclick="displayDetails(this, '+i+')" class="matchedFragment">'+inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd'])+'</span>';
|
2015-08-26 20:13:57 +02:00
|
|
|
|
|
|
|
lastInsertedEnd = fragment['matchedPatternEnd'];
|
|
|
|
|
|
|
|
fragments += renderFragment(fragment, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
//remaining unmarked fragment
|
|
|
|
markedSentence += inputSentence.slice(lastInsertedEnd);
|
|
|
|
|
|
|
|
res += '<div id="result-sentence">'+markedSentence+'</div>';
|
|
|
|
|
|
|
|
res += '<br/><br/><br/>'+fragments;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderFragment(fragment, number) {
|
|
|
|
var result = '<div style="display:none" id="fragment'+number+'" class="fragmentDetails"><table><tr><td>';
|
|
|
|
|
|
|
|
var sourceSegment = fragment['sourceSegment'];
|
|
|
|
result += sourceSegment.slice(0, fragment['matchedExampleStart']);
|
|
|
|
result += '<span class="matchedFragment">';
|
|
|
|
result += sourceSegment.slice(fragment['matchedExampleStart'], fragment['matchedExampleEnd']);
|
|
|
|
result += '</span>';
|
|
|
|
result += sourceSegment.slice(fragment['matchedExampleEnd']);
|
|
|
|
|
|
|
|
result += '</td></tr><tr><td>'+fragment['targetSegment']+'</td></tr></table></div>';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-08-27 07:29:29 +02:00
|
|
|
function displayDetails(caller, number) {
|
|
|
|
$('#result-sentence .matchedFragmentSelected').attr("class","matchedFragment");
|
|
|
|
caller.className='matchedFragmentSelected';
|
2015-08-26 20:13:57 +02:00
|
|
|
$('.fragmentDetails').css('display', 'none');
|
|
|
|
$('#fragment'+number).css('display', 'block');
|
|
|
|
}
|
2015-09-01 09:34:27 +02:00
|
|
|
|
|
|
|
function searchText(text) {
|
|
|
|
$("#searchInput").val(text);
|
|
|
|
searchHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showHideSuggestions() {
|
|
|
|
$('#suggestions').toggleClass('suggestionsInvisible');
|
|
|
|
}
|