");
$(".popup-text").show();
}
hidePopupText = function() {
$(".popup-text-content").empty();
$(".popup-text").hide();
}
/*
* Utility function
*/
findNameByAlgorithmId = function(id) {
for (i in algorithms) {
if (algorithms[i].id.substr(algorithms[i].id.lastIndexOf(".") + 1) == id)
return algorithms[i].name;
}
return id;
}
/*
* Utility function
*/
countSubstringOccurrencies = function(string, substring) {
var occurrencies = 0;
var index = 0;
var s = string;
while (index >= 0) {
index = s.indexOf(substring);
if (index >= 0) {
occurrencies++;
s = s.substring(index + 1);
}
}
return occurrencies;
}
/*
* Utility
*/
enhanceColor = function(color) {
var c = eval("0x" + color);
var hi = Math.round(c / 16);
if (hi < 15) {
hi += Math.round((15 - hi) / 1.5);
}
if (hi > 15)
hi = 15;
return '' + hexLetters[hi] + hexLetters[c % 16];
}
/*
* Write the html paragraph
containing the text highlighted on annotation
* value
*/
rewriteText = function(color) {
if (color.startsWith("#"))
color = color.substring(1);
$("#result-text-div").empty();
var complemetar = 0xFFFFFF - eval("0x" + color);
var complement = complemetar.toString(16);
var R = enhanceColor(complement.substring(0, 2));
var G = enhanceColor(complement.substring(2, 4));
var B = enhanceColor(complement.substring(4));
complement = "#" + R + G + B;
showProgress();
$(".hidden-div").show();
window.setTimeout(function() {
var indices = getIndices();
$(".hidden-div").hide();
$("#result-header-right").empty();
$("#result-header-right").append(
"" + checkedAnnotation
+ " occurs " + indices.length + " times.");
if (indices.length != 0) {
var indexedText = "";
if ((typeof (indices) == 'undefined') || (indices.length == 0)) {
indexedText = resultText;
indexedText = indexedText.replace(/\n/g, " ");
indexedText = indexedText.replace(//g, ">");
$("#result-text-div").append("
" + indexedText + "
");
return;
}
var t = 0;
var offset = 0;
for (var i = 0; i < indices.length; i++) {
var index = indices[i];
var start = index[0];
var end = index[1];
indexedText += resultText.substring(t, start);
var colored = ""
+ resultText.substring(start, end) + "";
indexedText += colored;
t = end;
}
if (t < resultText.length)
indexedText += resultText.substring(t);
indexedText = indexedText.replace(/\n/g, " ");
$("#result-text-div").append("
" + indexedText + "
");
} else {
$("#result-text-div").append("
" + resultText + "
");
}
}, 50);
}
filterAlgorithmsByAnnotation = function() {
if ($("#result-params-div input[type=radio]:checked").length < 1)
return;
var annotation = $("#result-params-div input[type=radio]:checked")[0]
.getAttribute("named");
var algs = $("#algorithm-params-div input[type=checkbox]");
for (var i = 0; i < algs.length; i++) {
var named = $("#algorithm-params-div input[type=checkbox]")[i]
.getAttribute("named");
var annList = algIndexedArray[named].annotations;
if (annList.indexOf(annotation) >= 0) {
$($("#algorithm-params-div input[type=checkbox]")[i]).prop(
"checked", true);
} else {
$($("#algorithm-params-div input[type=checkbox]")[i]).prop(
"checked", false);
}
}
}
/*
* Find if the annotation is present in the json
*/
checkAnnotation = function(annotation) {
for (var i = 0; i < jsonContent.output.result.length; i++) {
if (typeof jsonContent.output.result[i] === 'undefined'
|| jsonContent.output.result[i] == null) {
console.log("No result for " + i);
} else {
var entities = jsonContent.output.result[i].entities;
for (var j = 0; j < entities.length; j++) {
a = entities[j][annotation];
if (typeof a != 'undefined') {
if (a.length > 0)
return true;
}
}
}
}
return false;
}
/*
* Retrieve the annotation indices from the json
*/
getIndices = function() {
var checkedAlgs = $("#algorithm-params-div input[type=checkbox]:checked");
var indices = [];
// get indices
for (var i = 0; i < jsonContent.output.result.length; i++) {
if (typeof jsonContent.output.result[i] === 'undefined'
|| jsonContent.output.result[i] == null) {
console.log("No result for " + i);
} else {
// filter on algorithm
var found = false;
for (var j = 0; j < checkedAlgs.length; j++) {
if (checkedAlgs[j].getAttribute("named") == jsonContent.output.result[i].algorithm) {
found = true;
break;
}
}
if (!found)
continue;
var entities = jsonContent.output.result[i].entities;
for (var j = 0; j < entities.length; j++) {
// filter on annotation
a = entities[j][checkedAnnotation];
if (typeof a != 'undefined') {
indices[i] = [];
for (var k = 0; k < a.length; k++) {
var index = a[k].indices;
indices[i][k] = index;
}
}
}
}
}
if (indices.length == 0)
return indices;
var indices2 = [];
for (var i = 0; i < indices.length; i++) {
if (typeof (indices[i]) != 'undefined')
indices2[indices2.length] = indices[i];
}
return mergeIndices(indices2);
}
/*
* Merge the indices
*/
mergeIndices = function(indices) {
var newIndices = [];
newIndices = mergeAll(indices);
return newIndices;
}
/*
* Utility function
*/
resetExecuteButton = function() {
publicLink = null;
disableExecuteButton();
}
/*
* Resize the annotation table based on the screen geometry
*/
resizeTable = function() {
// resize the annotation table
$("#annotations-table").empty();
var rowId = "";
var ratio = window.innerWidth / window.innerHeight;
if (ratio <= 0.35) {
tableRawSize = 1;
} else if ((ratio > 0.35) && (ratio <= 0.75)) {
tableRawSize = 2;
} else if ((ratio > 0.75) && (ratio <= 1)) {
tableRawSize = 3;
} else if ((ratio > 1) && (ratio <= 1.5)) {
tableRawSize = 4;
} else {
tableRawSize = 5;
}
for (var i = 0; i < annotations.length; i++) {
if (i % tableRawSize == 0) {
rowId = "row-" + i;
$("#annotations-table").append("
");
}
}
/*
* Resize the page logo image based on the screen geometry
*/
resizeLogo = function() {
if (window.innerWidth < 200)
$("#logo-image").width(window.innerWidth - 10);
}
/*
* Build the annotation list for the service invocation
*/
buildInputAnnotationList = function() {
var list = [];
for (var i = 0; i < annotations.length; i++) {
if ($("#check-" + i).is(":Checked"))
list[list.length] = $("#check-" + i).val();
}
return list;
}
/*
* Handler for the window resize event
*/
window.onresize = function(event) {
resizeTable();
resizeLogo();
};
/*
* Handler for the file upload control
*/
$(".ajax-file-upload-abort").on("DOMAttrModified", function(event) {
$(".ajax-file-upload-abort").css("display", "none");
if (event.attributeName == "display") { // which attribute you want to watch
// for changes
$(".ajax-file-upload-abort").css("display", "none");
}
});
/*
* Build the option list of supported language
*/
buildLanguageList = function() {
// build the language selection input control
var defaultLanguage = null;
for (i in languages) {
languages[i] = languages[i].trim();
languages[i] = languages[i].replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
if (languages[i] == "English")
defaultLanguage = languages[i];
var opt = "";
if (i > 1)
opt = "";
$("#language-select").append(opt);
}
if (defaultLanguage != null)
$("#language-select").val(defaultLanguage);
$("#language-select").on("change", function() {
selectAnnotationsByLanguage();
});
}
/*
* Utility
*/
selectAnnotationsByLanguage = function() {
buildAnnotations();
resizeTable();
}
/*
* Enable/disable the input text area
*/
textAreaEnable = function(enable) {
if (enable == true)
$("#input-textarea").prop('disabled', false);
else
$("#input-textarea").prop('disabled', true);
}
/*
* Get a random RGB color
*/
randomRGB = function() {
var color = '';
var couple = '';
for (var i = 0; i < 3; i++) {
couple = '' + hexLetters[Math.floor(Math.random() * 10)]
+ hexLetters[Math.floor(Math.random() * 16)];
color += couple;
}
return color;
}