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