Gestione parametro link file esterno.

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@165329 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Erik Perrone 2018-03-22 12:10:09 +00:00
parent d5cf7f42d8
commit c7f90167ee
4 changed files with 166 additions and 108 deletions

View File

@ -86,7 +86,16 @@ public class NLPUploader extends HttpServlet {
return;
}
String link = ws.getPublicLink(fileName, token);
writer.println(new JsonManager().getSuccessJsonResponse("" + link));
if(request.getParameter("getlang") != null) {
String sentence = NlpUtils.getLanguageRecognizerDigest(new String(content));
logger.info(sentence);
try {
NLpLanguageRecognizer.run(sentence, token, link, response);
} catch (NlpHubException ex) {
writer.println(new JsonManager().getSuccessJsonResponse(Constants.UNAVAILABLE, link));
}
}
else writer.println(new JsonManager().getSuccessJsonResponse("" + link));
} catch (Exception x) {
x.printStackTrace();
logger.error(x.getClass().getName() + ": " + x.getLocalizedMessage());
@ -138,11 +147,6 @@ public class NLPUploader extends HttpServlet {
String link = ws.getPublicLink(fileName, token);
String sentence = NlpUtils.getLanguageRecognizerDigest(stringContent);
logger.info(sentence);
// System.out.println(sentence);
// NLpLanguageRecognizer recognizer = new
// NLpLanguageRecognizer(NLPHub.service, token, sentence, link,
// response);
// recognizer.run();
try {
NLpLanguageRecognizer.run(sentence, token, link, response);
} catch (NlpHubException ex) {

View File

@ -12,7 +12,7 @@ public class Constants {
public static String CONTENT_TYPE = "Content-Type";
public static String UNAVAILABLE = "unavailable";
public static String ERROR_ID = "ERROR";
public static String INPUT_FILE_PARAMETER = "input-file";
public static String INPUT_FILE_PARAMETER = "input";
public static String getToken(HttpServletRequest request, boolean devMode) {
String token = request.getParameter(TOKEN_PARAMETER);

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>External Test</title>
<script type="text/javascript">
externalTest = function() {
var link = "http://data.d4science.org/SCs1TC9zdDYzYm1LSWsrWUNQdHk3MXo3YzBtWStMUEJHbWJQNStIS0N6Yz0";
link = "http://www.dropbox.com/s/cnyzf1bc3b5onj3/italian-text-4.txt?dl=0";
location.href="index.jsp?input=" + encodeURIComponent(link);
}
</script>
</head>
<body onload="externalTest()">
</body>
</html>

View File

@ -12,8 +12,8 @@ var resultText = "";
var hexLetters = '0123456789ABCDEF';
var txtFlag = true;
var checkedAnnotation = "";
//var checkedAlgs = [];
var algIndexedArray = [];
var computedLanguage = "";
// ------------------------------------------------------------------------------------------------------
// Starting point: get the csv file with algorithm parameters and set the page
@ -23,7 +23,57 @@ var algIndexedArray = [];
$(document).ready(function() {
disableExecuteButton();
showAnnotationsList();
checkInputLink();
});
checkInputLink = function() {
if(inputFile != "") {
showProgress();
$.ajax({
url : inputFile,
type : "GET",
async : true,
success : function(data, stato) {
$("#input-textarea").val(data);
freeText = $("#input-textarea").val();
$.ajax({
url : "/nlphub/nlphub-uploader-servlet?getlang=on&freetext="
+ encodeURIComponent(freeText),
type : "POST",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
//publicLink = data.message;
//if (publicLink == null) {
// alert("Error uploading file.");
//}
hideProgress();
computedLanguage = data.language;
//textAreaEnable(false);
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 + "\nClick OK to start application.");
hideProgress();
initApplication();
}
});
}
else initApplication();
}
initApplication = function() {
$.ajax({
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
type : "GET",
@ -40,7 +90,7 @@ $(document).ready(function() {
resizeLogo();
enableAjaxFileUpload();
collapsibleHandler();
$("#logo-image").click(function() {
backHandler();
});
@ -134,13 +184,96 @@ $(document).ready(function() {
alert(errMsg);
}
});
if($("#input-textarea").val() != "") {
disableAjaxFileUpload();
if(computedLanguage != "") {
checkLanguage(computedLanguage);
selectAnnotationsByLanguage();
computedLanguage = "";
}
enableExecuteButton();
}
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error. Status: " + richiesta.status);
}
});
});
}
/*
* Set the listeners on the text area and the execute button
*/
setEventListeners = function() {
$(".ajax-file-upload").attr("id", "ajax-file-upload-id");
$("#input-textarea").on("keyup", function() {
enableDisableTextArea();
});
$("#input-textarea").change(function() {
enableDisableTextArea();
});
window.addEventListener('contextmenu', function(e) {
//alert("You've tried to open context menu"); //here you draw your own menu
//e.preventDefault();
enableDisableTextArea();
}, false);
$("#execute-button")
.click(
function() {
if(!isEnabled())
return;
if ((publicLink == null)
&& ($("#input-textarea").val() == "")) {
alert("You must upload a file or write some text in the text area before submit a request.");
return;
}
disableExecuteButton();
showProgress();
// if some text has been written in the text area, then
// a corresponding text file
// must be written in the workspace and the public link
// is set.
if ($("#input-textarea").val().length > 0) {
if(publicLink == null) {
freeText = $("#input-textarea").val();
$.ajax({
url : "/nlphub/nlphub-uploader-servlet?freetext="
+ encodeURIComponent(freeText),
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 runAlgorithm();
}
else {
runAlgorithm();
}
});
}
collapsibleHandler = function() {
// $('.collapsible').collapsible();
@ -360,91 +493,11 @@ enableDisableTextArea = function() {
}
}
/*
* Set the listeners on the text area and the execute button
*/
setEventListeners = function() {
$(".ajax-file-upload").attr("id", "ajax-file-upload-id");
$("#input-textarea").on("keyup", function() {
enableDisableTextArea();
});
$("#input-textarea").change(function() {
enableDisableTextArea();
});
window.addEventListener('contextmenu', function(e) {
//alert("You've tried to open context menu"); //here you draw your own menu
//e.preventDefault();
enableDisableTextArea();
}, false);
$("#execute-button")
.click(
function() {
if(!isEnabled())
return;
if ((publicLink == null)
&& ($("#input-textarea").val() == "")) {
alert("You must upload a file or write some text in the text area before submit a request.");
return;
}
disableExecuteButton();
showProgress();
// if some text has been written in the text area, then
// a corresponding text file
// must be written in the workspace and the public link
// is set.
if ($("#input-textarea").val().length > 0) {
freeText = $("#input-textarea").val();
console.log("/nlphub/nlphub-uploader-servlet?freetext="
+ encodeURIComponent(freeText));
$
.ajax({
url : "/nlphub/nlphub-uploader-servlet?freetext="
+ encodeURIComponent(freeText),
type : "POST",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
publicLink = data.message;
if (publicLink == null) {
alert("Error uploading file.");
}
launchAlgorithm();
},
error : function(richiesta, stato,
errori) {
alert("Unexpected Error. Status: "
+ richiesta.status);
hideProgress();
textAreaEnable(true);
$("#file-info").empty();
}
});
}
else {
launchAlgorithm();
}
});
}
/*
* show the in-progress popup
*/
showProgress = function() {
// var width = $(".progress-circular-div").width();
// var height = $(".progress-circular-div").height();
// var left = parseInt((window.innerWidth - width) / 2);
// var top = parseInt((window.innerHeight - height) / 2);
// $(".progress-circular-div").css("left", left);
// $(".progress-circular-div").css("top", top);
$(".hidden-div").css("display", "block");
$(".hidden-div").show();
}
@ -460,7 +513,7 @@ hideProgress = function() {
/*
* run the algorithms selected by the chosen language
*/
launchAlgorithm = function() {
runAlgorithm = function() {
if (publicLink == null) {
alert("No input text available for the service.");
return;
@ -519,13 +572,11 @@ launchAlgorithm = function() {
hideProgress();
alert("Unexpected response");
}
//resetExecuteButton();
},
error : function(richiesta, stato, errori) {
hideProgress();
textAreaEnable(true);
alert("Unexpected Error. Status: " + richiesta.status);
//resetExecuteButton();
}
});
}
@ -683,26 +734,12 @@ buildAlgortihmList = function() {
}
//buildCheckedAlgs();
$("#algorithm-params-div :checkbox").change(function () {
//buildCheckedAlgs();
rewriteText($("#colored-annotations :checked")[0].value);
});
}
/*
* build the internal global variable checkedAlgs used to filter results
*/
//buildCheckedAlgs = function() {
// checkedAlgs = [];
// for (var i = 0; i < jsonContent.output.result.length; i++) {
// if($("#algorithm" + i).is(":checked")) {
// checkedAlgs.push($("#algorithm" + i).attr("named"));
// }
// }
//}
/*
* Utility function
*/