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

@ -38,8 +38,10 @@ 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)
uploaderUrl += "&gcube-token=" + gCubeToken;
@ -54,10 +56,8 @@ checkInputLink = function() {
computedLanguage = data.language;
initApplication();
},
error : function(richiesta, stato,
errori) {
alert("Unexpected Error. Status: "
+ richiesta.status);
error : function(richiesta, stato, errori) {
alert("Unexpected Error. Status: " + richiesta.status);
hideProgress();
textAreaEnable(true);
$("#file-info").empty();
@ -66,17 +66,20 @@ checkInputLink = function() {
});
},
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({
$
.ajax({
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
type : "GET",
async : true,
@ -102,7 +105,9 @@ initApplication = function() {
});
disableExecuteButton();
var uploaderUrl = appRoot + "/nlphub-uploader-servlet?dataminer=" + encodeURIComponent(dataMiner);
var uploaderUrl = appRoot
+ "/nlphub-uploader-servlet?dataminer="
+ encodeURIComponent(dataMiner);
if (gCubeToken.length > 0)
uploaderUrl += "&gcube-token=" + gCubeToken;
@ -134,11 +139,17 @@ initApplication = function() {
.append(
"<div id=\"reset-upload\" class=\"centered\">Cancel</div>");
$("#reset-upload").hide();
$("#reset-upload").click(function() {
$("#reset-upload")
.click(
function() {
resetExecuteButton();
$("#file-info").empty();
$("#reset-upload").css(
"display", "none");
$("#file-info")
.empty();
$(
"#reset-upload")
.css(
"display",
"none");
textAreaEnable(true);
});
savedAnnotations = "";
@ -146,7 +157,10 @@ initApplication = function() {
},
onSelect : function(files) {
var fileName = files[0].name;
var extension = "" + fileName.substring(fileName.lastIndexOf("."));
var extension = ""
+ fileName
.substring(fileName
.lastIndexOf("."));
if (extension.toUpperCase() == ".TXT") {
showProgress();
textAreaEnable(false);
@ -182,8 +196,8 @@ initApplication = function() {
alert("Error uploading file.");
}
},
onError : function(files, status, errMsg,
pd) {
onError : function(files, status,
errMsg, pd) {
hideProgress();
textAreaEnable(true);
alert(errMsg);
@ -250,8 +264,11 @@ setEventListeners = function() {
if ($("#input-textarea").val().length > 0) {
// 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)
uploaderUrl += "&gcube-token=" + gCubeToken;
@ -268,8 +285,7 @@ setEventListeners = function() {
}
runAlgorithm();
},
error : function(richiesta, stato,
errori) {
error : function(richiesta, stato, errori) {
alert("Unexpected Error. Status: "
+ richiesta.status);
hideProgress();
@ -307,7 +323,8 @@ enableAjaxFileUpload= function() {
$(".ajax-file-upload").attr("enabled", "true");
$(".ajax-file-upload").css("background", pageGreen);
try {
document.getElementById("ajax-file-upload-id").removeEventListener("click", listenAjaxFileUpload);
document.getElementById("ajax-file-upload-id").removeEventListener(
"click", listenAjaxFileUpload);
} catch (err) {
console.log(err.message);
}
@ -317,10 +334,13 @@ 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);
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").addEventListener(
"click", listenAjaxFileUpload);
}
}
@ -329,7 +349,6 @@ listenAjaxFileUpload = function(event) {
event.preventDefault();
}
backHandler = function() {
if ($("#ner-ui").is(":visible"))
return;
@ -346,7 +365,8 @@ backHandler = function() {
}
/*
* 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')
@ -359,7 +379,9 @@ checkLanguage = function(lang) {
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!\"");
}
/*
@ -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
@ -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];
}
}
}
@ -512,14 +536,12 @@ enableDisableTextArea = function() {
if ($("#input-textarea").val() == "") {
disableExecuteButton();
enableAjaxFileUpload();
}
else {
} else {
enableExecuteButton();
disableAjaxFileUpload();
}
}
/*
* show the in-progress popup
*/
@ -619,9 +641,9 @@ getOutputJson = function(message) {
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 {
alert("Some error occurrend running algorithm " + splitted[0]
+ ". Trying to get other results...");
} else {
tobemap += message[i] + "|";
}
}
@ -721,7 +743,6 @@ buildAnnotationList = function(list) {
}
}
cb += "named='" + annotations[i] + "' value='" + colors[i]
+ "' id='color-" + i + "' class='filled-in'>";
cb += "<label for='color-" + i
@ -759,12 +780,21 @@ buildAlgortihmList = function() {
$("#algorithm-params-div").empty();
for (var i = 0; i < jsonContent.output.result.length; i++) {
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>";
+ 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() {
@ -787,7 +817,6 @@ getAlgInformation = function(alg) {
return;
}
var parameters = "getInfo=on";
parameters += "&dataminer=" + encodeURIComponent(dataMiner);
parameters += "&algId=" + algId;
@ -809,7 +838,6 @@ getAlgInformation = function(alg) {
});
}
showPopupText = function(text) {
$(".popup-text-content").empty();
$(".popup-text-content").append("<p>" + text + "</p>");
@ -849,7 +877,6 @@ countSubstringOccurrencies = function(string, substring) {
return occurrencies;
}
/*
* Utility
*/
@ -860,12 +887,14 @@ enhanceColor = function(color) {
if (hi < 15) {
hi += Math.round((15 - hi) / 1.5);
}
if(hi > 15) hi = 15;
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("#"))
@ -885,7 +914,9 @@ 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) {
var indexedText = "";
@ -918,8 +949,7 @@ 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);
@ -928,21 +958,23 @@ rewriteText = function(color) {
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 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 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);
$($("#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
*/
@ -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>";
+ "\"></input> <label for=\"check-" + i + "\">"
+ annotations[i] + "</label>";
}
$("#" + rowId).append("<td>" + annotationElement + "</td>");
@ -1111,8 +1144,7 @@ buildLanguageList = function() {
var defaultLanguage = null;
for (i in languages) {
languages[i] = languages[i].trim();
languages[i] = languages[i].replace(/\w\S*/g,
function(txt) {
languages[i] = languages[i].replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
if (languages[i] == "English")
@ -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;
}