ref 11746: NLP Hub with empty output

https://support.d4science.org/issues/11746

Fixed error when algorithm result is undefined

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@167382 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-05-09 15:44:19 +00:00
parent 276a128b0c
commit c0e071095e
1 changed files with 368 additions and 335 deletions

View File

@ -30,7 +30,7 @@ $(document).ready(function() {
});
checkInputLink = function() {
if(inputFile != "") {
if (inputFile != "") {
showProgress();
$.ajax({
url : inputFile,
@ -38,172 +38,186 @@ checkInputLink = function() {
async : true,
success : function(data, stato) {
freeText = data;
var uploaderUrl = appRoot + "/nlphub-uploader-servlet?getlang=on&freetext="
+ encodeURIComponent(freeText) + "&dataminer=" + encodeURIComponent(dataMiner);
var uploaderUrl = appRoot
+ "/nlphub-uploader-servlet?getlang=on&freetext="
+ encodeURIComponent(freeText) + "&dataminer="
+ encodeURIComponent(dataMiner);
if(gCubeToken.length > 0)
if (gCubeToken.length > 0)
uploaderUrl += "&gcube-token=" + gCubeToken;
$.ajax({
url : uploaderUrl,
type : "POST",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
hideProgress();
$("#input-textarea").val(freeText);
computedLanguage = data.language;
initApplication();
},
error : function(richiesta, stato,
errori) {
alert("Unexpected Error. Status: "
+ richiesta.status);
hideProgress();
textAreaEnable(true);
$("#file-info").empty();
initApplication();
}
});
url : uploaderUrl,
type : "POST",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
hideProgress();
$("#input-textarea").val(freeText);
computedLanguage = data.language;
initApplication();
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error. Status: " + richiesta.status);
hideProgress();
textAreaEnable(true);
$("#file-info").empty();
initApplication();
}
});
},
error : function(richiesta, stato, errori) {
alert("Unexpected error reading from link: '" + inputFile + "'.\nStatus: " + richiesta.status + " Error: " + errori + "\nClick OK to start application.");
alert("Unexpected error reading from link: '" + inputFile
+ "'.\nStatus: " + richiesta.status + " Error: "
+ errori + "\nClick OK to start application.");
hideProgress();
initApplication();
}
});
}
else initApplication();
} else
initApplication();
}
initApplication = function() {
$.ajax({
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
type : "GET",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
$("#ner-result-container").hide();
var lineTokens = manageCsvData(data);
getAlgorithms(lineTokens);
buildLanguageSelection();
buildLanguageList();
buildAnnotations();
resizeTable();
resizeLogo();
enableAjaxFileUpload();
collapsibleHandler();
$
.ajax({
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
type : "GET",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
$("#ner-result-container").hide();
var lineTokens = manageCsvData(data);
getAlgorithms(lineTokens);
buildLanguageSelection();
buildLanguageList();
buildAnnotations();
resizeTable();
resizeLogo();
enableAjaxFileUpload();
collapsibleHandler();
$("#logo-image").click(function() {
backHandler();
});
$("#logo-image").click(function() {
backHandler();
});
$("#back-ner-ui-button").click(function() {
backHandler();
});
$("#back-ner-ui-button").click(function() {
backHandler();
});
disableExecuteButton();
var uploaderUrl = appRoot + "/nlphub-uploader-servlet?dataminer=" + encodeURIComponent(dataMiner);
if(gCubeToken.length > 0)
uploaderUrl += "&gcube-token=" + gCubeToken;
disableExecuteButton();
var uploaderUrl = appRoot
+ "/nlphub-uploader-servlet?dataminer="
+ encodeURIComponent(dataMiner);
if (gCubeToken.length > 0)
uploaderUrl += "&gcube-token=" + gCubeToken;
$("#upload-button")
.uploadFile(
{
url : uploaderUrl,
fileName : "mytxtfile",
maxFileCount : 100,
multiple : false,
maxFileSize : 1024 * 1000 * 1,
showFileCounter : false,
showCancel : true,
//allowedTypes: "txt,.txt",
dragDropStr : "<img class='img-prompt' src='img/upload.png' width='60px' height='60px' style='display:block; margin:auto; padding: 10px'>",
extErrorStr : "Error. Text file only",
sizeErrorStr : "Error. Max size: 6 Mb",
onLoad : function(obj) {
txtFlag = true;
$("#file-info").remove();
$("#reset-upload").remove();
$("#fu-container")
.append(
"<div id=\"right-child\" class=\"float-right-div\"></div>");
$("#right-child")
.append(
"<div id=\"file-info\" class=\"centered\"></div>");
$("#right-child")
.append(
"<div id=\"reset-upload\" class=\"centered\">Cancel</div>");
$("#reset-upload").hide();
$("#reset-upload").click(function() {
resetExecuteButton();
$("#file-info").empty();
$("#reset-upload").css(
"display", "none");
textAreaEnable(true);
});
savedAnnotations = "";
setEventListeners();
},
onSelect : function(files) {
var fileName = files[0].name;
var extension = "" + fileName.substring(fileName.lastIndexOf("."));
if(extension.toUpperCase() == ".TXT") {
showProgress();
textAreaEnable(false);
$("#input-textarea").val("");
} else {
txtFlag = false;
alert("The application supports text file only (.TXT)");
}
publicLink = null;
textAreaEnable(false);
$("#input-textarea").val("");
},
onSubmit: function(files) {
var submitFlag = txtFlag;
txtFlag = true;
return submitFlag;
},
onSuccess : function(files, data, xhr) {
hideProgress();
checkLanguage(data.language);
selectAnnotationsByLanguage();
$("#reset-upload").css("display",
"inline");
$("#file-info").empty();
$("#file-info")
.append(
"Uploaded: <span style=\"color:#4CAF50; letter-spacing: 1px; font-weight: bold;\">"
+ files
+ "</span>");
publicLink = data.message;
enableExecuteButton();
if (publicLink == null) {
alert("Error uploading file.");
}
},
onError : function(files, status, errMsg,
pd) {
hideProgress();
textAreaEnable(true);
alert(errMsg);
}
});
$("#upload-button")
.uploadFile(
{
url : uploaderUrl,
fileName : "mytxtfile",
maxFileCount : 100,
multiple : false,
maxFileSize : 1024 * 1000 * 1,
showFileCounter : false,
showCancel : true,
// allowedTypes: "txt,.txt",
dragDropStr : "<img class='img-prompt' src='img/upload.png' width='60px' height='60px' style='display:block; margin:auto; padding: 10px'>",
extErrorStr : "Error. Text file only",
sizeErrorStr : "Error. Max size: 6 Mb",
onLoad : function(obj) {
txtFlag = true;
$("#file-info").remove();
$("#reset-upload").remove();
$("#fu-container")
.append(
"<div id=\"right-child\" class=\"float-right-div\"></div>");
$("#right-child")
.append(
"<div id=\"file-info\" class=\"centered\"></div>");
$("#right-child")
.append(
"<div id=\"reset-upload\" class=\"centered\">Cancel</div>");
$("#reset-upload").hide();
$("#reset-upload")
.click(
function() {
resetExecuteButton();
$("#file-info")
.empty();
$(
"#reset-upload")
.css(
"display",
"none");
textAreaEnable(true);
});
savedAnnotations = "";
setEventListeners();
},
onSelect : function(files) {
var fileName = files[0].name;
var extension = ""
+ fileName
.substring(fileName
.lastIndexOf("."));
if (extension.toUpperCase() == ".TXT") {
showProgress();
textAreaEnable(false);
$("#input-textarea").val("");
} else {
txtFlag = false;
alert("The application supports text file only (.TXT)");
}
publicLink = null;
textAreaEnable(false);
$("#input-textarea").val("");
},
onSubmit : function(files) {
var submitFlag = txtFlag;
txtFlag = true;
return submitFlag;
},
onSuccess : function(files, data, xhr) {
hideProgress();
checkLanguage(data.language);
selectAnnotationsByLanguage();
$("#reset-upload").css("display",
"inline");
$("#file-info").empty();
$("#file-info")
.append(
"Uploaded: <span style=\"color:#4CAF50; letter-spacing: 1px; font-weight: bold;\">"
+ files
+ "</span>");
publicLink = data.message;
enableExecuteButton();
if (publicLink == null) {
alert("Error uploading file.");
}
},
onError : function(files, status,
errMsg, pd) {
hideProgress();
textAreaEnable(true);
alert(errMsg);
}
});
if($("#input-textarea").val() != "") {
disableAjaxFileUpload();
if(computedLanguage != "") {
checkLanguage(computedLanguage);
selectAnnotationsByLanguage();
computedLanguage = "";
if ($("#input-textarea").val() != "") {
disableAjaxFileUpload();
if (computedLanguage != "") {
checkLanguage(computedLanguage);
selectAnnotationsByLanguage();
computedLanguage = "";
}
enableExecuteButton();
}
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error. Status: " + richiesta.status);
}
enableExecuteButton();
}
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error. Status: " + richiesta.status);
}
});
});
}
/*
@ -222,7 +236,7 @@ setEventListeners = function() {
window.addEventListener('contextmenu', function(e) {
enableDisableTextArea();
}, false);
}, false);
$(".popup-text").click(function(e) {
hidePopupText();
@ -231,7 +245,7 @@ setEventListeners = function() {
$("#execute-button")
.click(
function() {
if(!isEnabled())
if (!isEnabled())
return;
if ((publicLink == null)
@ -248,35 +262,37 @@ setEventListeners = function() {
// must be written in the workspace and the public link
// is set.
if ($("#input-textarea").val().length > 0) {
//if(publicLink == null) {
// if(publicLink == null) {
freeText = $("#input-textarea").val();
var uploaderUrl = appRoot + "/nlphub-uploader-servlet?freetext="
+ encodeURIComponent(freeText) + "&dataminer=" + encodeURIComponent(dataMiner);
var uploaderUrl = appRoot
+ "/nlphub-uploader-servlet?freetext="
+ encodeURIComponent(freeText)
+ "&dataminer="
+ encodeURIComponent(dataMiner);
if(gCubeToken.length > 0)
if (gCubeToken.length > 0)
uploaderUrl += "&gcube-token=" + gCubeToken;
$.ajax({
url : uploaderUrl,
type : "POST",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
publicLink = data.message;
if (publicLink == null) {
alert("Error uploading file.");
}
runAlgorithm();
},
error : function(richiesta, stato,
errori) {
alert("Unexpected Error. Status: "
+ richiesta.status);
hideProgress();
textAreaEnable(true);
$("#file-info").empty();
url : uploaderUrl,
type : "POST",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
publicLink = data.message;
if (publicLink == null) {
alert("Error uploading file.");
}
});
runAlgorithm();
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error. Status: "
+ richiesta.status);
hideProgress();
textAreaEnable(true);
$("#file-info").empty();
}
});
}
else {
@ -286,41 +302,45 @@ setEventListeners = function() {
}
collapsibleHandler = function() {
// $('.collapsible').collapsible();
//$('.collapsible').collapsible({
// onOpen: function(el) {
// if(el.index() == 0)
// $('.collapsible').collapsible('close', 1);
// else
// $('.collapsible').collapsible('close', 0);
// },
// onClose: function(el) {
// if(el.index() == 0)
// $('.collapsible').collapsible('open', 1);
// else
// $('.collapsible').collapsible('open', 0);
// }
// });
// $('.collapsible').collapsible();
// $('.collapsible').collapsible({
// onOpen: function(el) {
// if(el.index() == 0)
// $('.collapsible').collapsible('close', 1);
// else
// $('.collapsible').collapsible('close', 0);
// },
// onClose: function(el) {
// if(el.index() == 0)
// $('.collapsible').collapsible('open', 1);
// else
// $('.collapsible').collapsible('open', 0);
// }
// });
}
enableAjaxFileUpload= function() {
enableAjaxFileUpload = function() {
$(".ajax-file-upload").attr("enabled", "true");
$(".ajax-file-upload").css("background", pageGreen);
try {
document.getElementById("ajax-file-upload-id").removeEventListener("click", listenAjaxFileUpload);
}catch(err) {
document.getElementById("ajax-file-upload-id").removeEventListener(
"click", listenAjaxFileUpload);
} catch (err) {
console.log(err.message);
}
}
disableAjaxFileUpload= function() {
disableAjaxFileUpload = function() {
$(".ajax-file-upload").attr("enabled", "false");
$(".ajax-file-upload").css("background", pageGray);
try {
document.getElementById("ajax-file-upload-id").removeEventListener("click", listenAjaxFileUpload);
document.getElementById("ajax-file-upload-id").addEventListener("click", listenAjaxFileUpload);
}catch(err) {
document.getElementById("ajax-file-upload-id").addEventListener("click", listenAjaxFileUpload);
document.getElementById("ajax-file-upload-id").removeEventListener(
"click", listenAjaxFileUpload);
document.getElementById("ajax-file-upload-id").addEventListener(
"click", listenAjaxFileUpload);
} catch (err) {
document.getElementById("ajax-file-upload-id").addEventListener(
"click", listenAjaxFileUpload);
}
}
@ -329,37 +349,39 @@ listenAjaxFileUpload = function(event) {
event.preventDefault();
}
backHandler = function() {
if($("#ner-ui").is(":visible"))
if ($("#ner-ui").is(":visible"))
return;
$("#ner-result-container").hide();
$(".popup-text").hide();
$("#ner-ui").show();
if(publicLink != null) {
if (publicLink != null) {
enableExecuteButton();
if(document.getElementById("reset-upload") != null) {
if($("#reset-upload").is(":visible"))
if (document.getElementById("reset-upload") != null) {
if ($("#reset-upload").is(":visible"))
textAreaEnable(false);
}
}
}
/*
* Utility function processing the language indication returned by the language recognition service
* Utility function processing the language indication returned by the language
* recognition service
*/
checkLanguage = function(lang) {
if(lang == 'unavailable')
if (lang == 'unavailable')
return;
var options = $("#language-select option");
for(var i=0; i<options.length; i++) {
if(options[i].innerText.toLowerCase() == lang.toLowerCase()) {
for (var i = 0; i < options.length; i++) {
if (options[i].innerText.toLowerCase() == lang.toLowerCase()) {
$("#language-select").val(options[i].innerText);
buildAnnotations();
return;
}
}
alert("The uploaded file seems to be in " + lang + ", but this language is not currently supported. Please, be aware of this, should you decide to continue and use the tools of another language... \"Praemonitus praemunitus!\"");
alert("The uploaded file seems to be in "
+ lang
+ ", but this language is not currently supported. Please, be aware of this, should you decide to continue and use the tools of another language... \"Praemonitus praemunitus!\"");
}
/*
@ -397,12 +419,12 @@ manageCsvData = function(data) {
// get the new token and push it in the array
tokens.push(line.substring(tokenStart + 1));
if(tokens.length != tokensPerLine)
if (tokens.length != tokensPerLine)
continue; // skip...
lineTokens.push(tokens);
var description = tokens[1].toUpperCase().trim();
if(description == "CLOUD COMPUTING")
if (description == "CLOUD COMPUTING")
dataMiner = tokens[2];
tokens = [];
}
@ -411,7 +433,8 @@ manageCsvData = function(data) {
}
/*
* Map the supported algorithms (from CSV) in the internal global algorithm array
* Map the supported algorithms (from CSV) in the internal global algorithm
* array
*/
getAlgorithms = function(lineTokens) {
// build the list of supported algorithms
@ -427,7 +450,7 @@ getAlgorithms = function(lineTokens) {
var annotationList = lineTokens[i][3].replace(/"/g, " ").trim();
var language = lineTokens[i][4].replace(/"/g, " ").trim();
algorithms.push ( {
algorithms.push({
"name" : algName,
"description" : algDescription,
"id" : algId,
@ -435,7 +458,8 @@ getAlgorithms = function(lineTokens) {
"annotations" : annotationList
});
algIndexedArray[algorithms[algorithms.length-1].id.substr(algorithms[0].id.lastIndexOf(".")+1)] = algorithms[algorithms.length-1];
algIndexedArray[algorithms[algorithms.length - 1].id
.substr(algorithms[0].id.lastIndexOf(".") + 1)] = algorithms[algorithms.length - 1];
}
}
}
@ -503,7 +527,7 @@ disableExecuteButton = function() {
}
isEnabled = function() {
if($("#execute-button").attr("enable") == "true")
if ($("#execute-button").attr("enable") == "true")
return true;
return false;
}
@ -512,14 +536,12 @@ enableDisableTextArea = function() {
if ($("#input-textarea").val() == "") {
disableExecuteButton();
enableAjaxFileUpload();
}
else {
} else {
enableExecuteButton();
disableAjaxFileUpload();
}
}
/*
* show the in-progress popup
*/
@ -561,9 +583,9 @@ runAlgorithm = function() {
if (algorithms[j].lang.toLowerCase().indexOf(
$("#language-select").val().toLowerCase()) >= 0) {
var algAnnotations = algorithms[j].annotations.toLowerCase();
for(k in list) {
for (k in list) {
var a = list[k].toLowerCase();
if(algAnnotations.indexOf(a) > -1) {
if (algAnnotations.indexOf(a) > -1) {
algList += encodeURI(algorithms[j].id) + ",";
break;
}
@ -585,7 +607,7 @@ runAlgorithm = function() {
parameters += "&algs=" + algList;
var nlphubUrl = appRoot + "/nlphub-servlet?" + parameters;
if(gCubeToken.length > 0)
if (gCubeToken.length > 0)
nlphubUrl += "&gcube-token=" + gCubeToken;
$.ajax({
url : nlphubUrl,
@ -618,10 +640,10 @@ getOutputJson = function(message) {
var tobemap = "";
for (var i = 0; i < message.length; i++) {
var splitted = message[i].split(":::");
if(splitted[1].toLowerCase().trim() == "error") {
alert("Some error occurrend running algorithm " + splitted[0] + ". Trying to get other results...");
}
else {
if (splitted[1].toLowerCase().trim() == "error") {
alert("Some error occurrend running algorithm " + splitted[0]
+ ". Trying to get other results...");
} else {
tobemap += message[i] + "|";
}
}
@ -634,7 +656,7 @@ getOutputJson = function(message) {
parameters += "&tobemap=" + encodeURI(tobemap);
var mapperUrl = appRoot + "/nlphub-mapper-servlet?" + parameters;
if(gCubeToken.length > 0)
if (gCubeToken.length > 0)
mapperUrl += "&gcube-token=" + gCubeToken;
$.ajax({
@ -655,7 +677,7 @@ getOutputJson = function(message) {
hideProgress();
$("#reset-upload").hide();
savedAnnotations = "";
//publicLink = null;
// publicLink = null;
alert("Unexpected Error. Status: " + richiesta.status);
}
});
@ -714,14 +736,13 @@ buildAnnotationList = function(list) {
colors[i] = colorDisabled;
}
if(firstRadio) {
if(cb.indexOf("disabled") < 0) {
if (firstRadio) {
if (cb.indexOf("disabled") < 0) {
firstRadio = false;
cb += "checked ";
}
}
cb += "named='" + annotations[i] + "' value='" + colors[i]
+ "' id='color-" + i + "' class='filled-in'>";
cb += "<label for='color-" + i
@ -759,48 +780,56 @@ buildAlgortihmList = function() {
$("#algorithm-params-div").empty();
for (var i = 0; i < jsonContent.output.result.length; i++) {
var cb = "<div class='alg-info-p'><input type='checkbox' name='foo-ner-algs' checked named='"
+ jsonContent.output.result[i].algorithm + "' id='algorithm" + i + "'>";
cb += "<label class='label-alg-info' for='algorithm" + i + "'></label></div>";
cb += "<div class='alg-info-p' onclick='getAlgInformation(\"" + jsonContent.output.result[i].algorithm + "\")'>" +findNameByAlgorithmId(jsonContent.output.result[i].algorithm) + "</div><div class='clearfix'></div>";
$("#algorithm-params-div").append(cb);
if (jsonContent.output.result[i] === undefined) {
console.log("No result for " + i);
} else {
var cb = "<div class='alg-info-p'><input type='checkbox' name='foo-ner-algs' checked named='"
+ jsonContent.output.result[i].algorithm
+ "' id='algorithm" + i + "'>";
cb += "<label class='label-alg-info' for='algorithm" + i
+ "'></label></div>";
cb += "<div class='alg-info-p' onclick='getAlgInformation(\""
+ jsonContent.output.result[i].algorithm
+ "\")'>"
+ findNameByAlgorithmId(jsonContent.output.result[i].algorithm)
+ "</div><div class='clearfix'></div>";
$("#algorithm-params-div").append(cb);
}
}
$("#algorithm-params-div :checkbox").change(function () {
//buildCheckedAlgs();
$("#algorithm-params-div :checkbox").change(function() {
// buildCheckedAlgs();
rewriteText($("#colored-annotations :checked")[0].value);
});
}
getAlgInformation = function(alg) {
var algId = "";
for(var i in algorithms) {
if(algorithms[i].id.indexOf(alg) > 0) {
for ( var i in algorithms) {
if (algorithms[i].id.indexOf(alg) > 0) {
algId = algorithms[i].id;
break;
}
}
if(algId == "") {
if (algId == "") {
alert("Invalid algorithm identifier.");
return;
}
var parameters = "getInfo=on";
parameters += "&dataminer=" + encodeURIComponent(dataMiner);
parameters += "&algId=" + algId;
var nlphubUrl = appRoot + "/nlphub-servlet?" + parameters;
if(gCubeToken.length > 0)
if (gCubeToken.length > 0)
nlphubUrl += "&gcube-token=" + gCubeToken;
$.ajax({
url : nlphubUrl,
type : "GET",
async : true,
success : function(data, stato) {
//alert(data.message);
// alert(data.message);
showPopupText(data.message);
},
error : function(richiesta, stato, errori) {
@ -809,7 +838,6 @@ getAlgInformation = function(alg) {
});
}
showPopupText = function(text) {
$(".popup-text-content").empty();
$(".popup-text-content").append("<p>" + text + "</p>");
@ -825,8 +853,8 @@ hidePopupText = function() {
* Utility function
*/
findNameByAlgorithmId = function(id) {
for(i in algorithms) {
if(algorithms[i].id.substr(algorithms[i].id.lastIndexOf(".")+1) == id)
for (i in algorithms) {
if (algorithms[i].id.substr(algorithms[i].id.lastIndexOf(".") + 1) == id)
return algorithms[i].name;
}
return id;
@ -849,7 +877,6 @@ countSubstringOccurrencies = function(string, substring) {
return occurrencies;
}
/*
* Utility
*/
@ -857,25 +884,27 @@ countSubstringOccurrencies = function(string, substring) {
enhanceColor = function(color) {
var c = eval("0x" + color);
var hi = Math.round(c / 16);
if(hi < 15) {
if (hi < 15) {
hi += Math.round((15 - hi) / 1.5);
}
if(hi > 15) hi = 15;
return '' + hexLetters[hi] + hexLetters[c%16];
if (hi > 15)
hi = 15;
return '' + hexLetters[hi] + hexLetters[c % 16];
}
/*
* Write the html paragraph <p> containing the text highlighted on annotation value
* Write the html paragraph <p> containing the text highlighted on annotation
* value
*/
rewriteText = function(color) {
if(color.startsWith("#"))
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 R = enhanceColor(complement.substring(0, 2));
var G = enhanceColor(complement.substring(2, 4));
var B = enhanceColor(complement.substring(4));
complement = "#" + R + G + B;
showProgress();
@ -885,9 +914,11 @@ rewriteText = function(color) {
$(".hidden-div").hide();
$("#result-header-right").empty();
$("#result-header-right").append("<span style='color:" + color + ";'>" + checkedAnnotation + "</span> occurs " + indices.length + " times.");
$("#result-header-right").append(
"<span style='color:" + color + ";'>" + checkedAnnotation
+ "</span> occurs " + indices.length + " times.");
if(indices.length != 0) {
if (indices.length != 0) {
var indexedText = "";
if ((typeof (indices) == 'undefined') || (indices.length == 0)) {
@ -918,31 +949,32 @@ rewriteText = function(color) {
indexedText = indexedText.replace(/\n/g, "<br>");
$("#result-text-div").append("<p>" + indexedText + "</p>");
}
else {
} else {
$("#result-text-div").append("<p>" + resultText + "</p>");
}
}, 50);
}
filterAlgorithmsByAnnotation = function() {
if($("#result-params-div input[type=radio]:checked").length < 1)
if ($("#result-params-div input[type=radio]:checked").length < 1)
return;
var annotation = $("#result-params-div input[type=radio]:checked")[0].getAttribute("named");
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);
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
*/
@ -952,7 +984,7 @@ checkAnnotation = function(annotation) {
for (var j = 0; j < entities.length; j++) {
a = entities[j][annotation];
if (typeof a != 'undefined') {
if(a.length > 0)
if (a.length > 0)
return true;
}
}
@ -970,13 +1002,13 @@ getIndices = function() {
for (var i = 0; i < jsonContent.output.result.length; i++) {
// filter on algorithm
var found = false;
for(var j=0; j<checkedAlgs.length; j++) {
if(checkedAlgs[j].getAttribute("named") == jsonContent.output.result[i].algorithm) {
for (var j = 0; j < checkedAlgs.length; j++) {
if (checkedAlgs[j].getAttribute("named") == jsonContent.output.result[i].algorithm) {
found = true;
break;
}
}
if(!found)
if (!found)
continue;
var entities = jsonContent.output.result[i].entities;
@ -993,7 +1025,7 @@ getIndices = function() {
}
}
if(indices.length == 0)
if (indices.length == 0)
return indices;
var indices2 = [];
@ -1053,11 +1085,12 @@ resizeTable = function() {
+ "\" value=\"" + annotations[i]
+ "\" checked=\"checked\"></input> <label for=\"check-" + i
+ "\">" + annotations[i] + "</label>";
if((annotations[i].toLowerCase() == "keyword") || (annotations[i].toLowerCase() == "event")) {
if ((annotations[i].toLowerCase() == "keyword")
|| (annotations[i].toLowerCase() == "event")) {
annotationElement = "<input type=\"checkbox\" id=\"check-" + i
+ "\" value=\"" + annotations[i]
+ "\"></input> <label for=\"check-" + i
+ "\">" + annotations[i] + "</label>";
+ "\" value=\"" + annotations[i]
+ "\"></input> <label for=\"check-" + i + "\">"
+ annotations[i] + "</label>";
}
$("#" + rowId).append("<td>" + annotationElement + "</td>");
@ -1098,7 +1131,7 @@ window.onresize = function(event) {
$(".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
// for changes
$(".ajax-file-upload-abort").css("display", "none");
}
});
@ -1111,11 +1144,10 @@ buildLanguageList = function() {
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")
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 = "<option value=\"" + languages[i]
@ -1126,7 +1158,7 @@ buildLanguageList = function() {
$("#language-select").append(opt);
}
if(defaultLanguage != null)
if (defaultLanguage != null)
$("#language-select").val(defaultLanguage);
$("#language-select").on("change", function() {
@ -1160,7 +1192,8 @@ 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)];
couple = '' + hexLetters[Math.floor(Math.random() * 10)]
+ hexLetters[Math.floor(Math.random() * 16)];
color += couple;
}