From 43a834505dcf57ee89b8a64c581e12e1fc2b0c27 Mon Sep 17 00:00:00 2001 From: Erik Perrone Date: Mon, 19 Mar 2018 15:31:23 +0000 Subject: [PATCH] Algorithm selection git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@165247 82a268e6-3cf1-43bd-a215-b396298e98cf --- src/main/java/org/gcube/nlphub/NLPHub.java | 1 + src/main/java/org/gcube/nlphub/NLPMapper.java | 23 +- .../org/gcube/nlphub/legacy/Constants.java | 3 + .../nlphub/nlp/NLpLanguageRecognizer.java | 3 +- .../gcube/nlphub/nlp/NlpAsyncNerRunner.java | 5 +- src/main/webapp/css/custom.css | 28 +- src/main/webapp/index.jsp | 15 +- src/main/webapp/js/main.js | 267 ++++++++++++++---- src/main/webapp/js/merge.js | 2 +- 9 files changed, 267 insertions(+), 80 deletions(-) diff --git a/src/main/java/org/gcube/nlphub/NLPHub.java b/src/main/java/org/gcube/nlphub/NLPHub.java index eeb026e..8a98874 100644 --- a/src/main/java/org/gcube/nlphub/NLPHub.java +++ b/src/main/java/org/gcube/nlphub/NLPHub.java @@ -65,6 +65,7 @@ public class NLPHub extends HttpServlet { RunnerCommander commander = new RunnerCommander(algs, request.getParameter("plink"), request.getParameter("annotations"), token, response); commander.setSleepTime(100); + commander.setMaxWaitingTime(90*1000); commander.startProcess(); /* if (algs.length >= 1) { diff --git a/src/main/java/org/gcube/nlphub/NLPMapper.java b/src/main/java/org/gcube/nlphub/NLPMapper.java index 4f560e5..e9e523d 100644 --- a/src/main/java/org/gcube/nlphub/NLPMapper.java +++ b/src/main/java/org/gcube/nlphub/NLPMapper.java @@ -79,26 +79,15 @@ public class NLPMapper extends HttpServlet { } String annotations = request.getParameter("annotations"); - //System.out.println("annotations\n: " + annotations); String language = request.getParameter("lang"); PrintWriter writer = response.getWriter(); - //System.out.println("language\n: " + language); - - //System.out.println("tokens length: " + tokens.length); -// for(int u=0; u
-
Upload text file
@@ -101,7 +99,18 @@
-
+
+
    +
  • +
    Annotations
    +
    +
  • +
  • +
    Algorithms
    +
    +
  • +
+
back
diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js index f4054f4..7557cf6 100644 --- a/src/main/webapp/js/main.js +++ b/src/main/webapp/js/main.js @@ -11,6 +11,8 @@ var named = null; var resultText = ""; var hexLetters = '0123456789ABCDEF'; var txtFlag = true; +var checkedAnnotation = ""; +var checkedAlgs = []; // ------------------------------------------------------------------------------------------------------ // Starting point: get the csv file with algorithm parameters and set the page @@ -19,6 +21,7 @@ var txtFlag = true; $(document).ready(function() { disableExecuteButton(); + $('.collapsible').collapsible(); $.ajax({ url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0", type : "GET", @@ -33,13 +36,14 @@ $(document).ready(function() { buildAnnotations(); resizeTable(); resizeLogo(); + enableAjaxFileUpload(); + $("#logo-image").click(function() { + backHandler(); + }); + $("#back-ner-ui-button").click(function() { - $("#ner-result-container").hide(); - $("#ner-ui").show(); - $("#input-textarea").val(""); - publicLink = null; - jsonContent = null; + backHandler(); }); disableExecuteButton(); @@ -72,8 +76,7 @@ $(document).ready(function() { .append( "
Cancel
"); $("#reset-upload").hide(); - $("#reset-upload").click( - function() { + $("#reset-upload").click(function() { resetExecuteButton(); $("#file-info").empty(); $("#reset-upload").css( @@ -94,6 +97,9 @@ $(document).ready(function() { txtFlag = false; alert("The application supports text file only (.TXT)"); } + publicLink = null; + textAreaEnable(false); + $("#input-textarea").val(""); }, onSubmit: function(files) { var submitFlag = txtFlag; @@ -107,7 +113,6 @@ $(document).ready(function() { selectAnnotationsByLanguage(); $("#reset-upload").css("display", "inline"); - //console.log("files: " + files); $("#file-info").empty(); $("#file-info") .append( @@ -134,6 +139,42 @@ $(document).ready(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) { + console.log(err.message); + } +} + +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); + } + +} + +listenAjaxFileUpload = function(event) { + event.preventDefault(); +} + + +backHandler = function() { + if($("#ner-ui").is(":visible")) + return; + $("#ner-result-container").hide(); + $("#ner-ui").show(); + if(publicLink != null) { + enableExecuteButton(); + } +} /* * Utility function processing the language indication returned by the language recognition service @@ -286,16 +327,22 @@ isEnabled = function() { } enableDisableTextArea = function() { - if ($("#input-textarea").val() == "") + if ($("#input-textarea").val() == "") { disableExecuteButton(); - else + enableAjaxFileUpload(); + } + else { enableExecuteButton(); + disableAjaxFileUpload(); + } } /* * 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(); }); @@ -303,7 +350,7 @@ setEventListeners = function() { $("#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(); @@ -421,6 +468,7 @@ launchAlgorithm = function() { } if (algList.length == 0) { alert("Warning. No algorithm matching with selected language."); + hideProgress(); return; } algList = algList.substring(0, algList.length - 1); @@ -436,8 +484,6 @@ launchAlgorithm = function() { async : true, success : function(data, stato) { textAreaEnable(true); - $("#file-info").empty(); - $("#reset-upload").css("display", "none"); if (typeof (data.response) != 'undefined') { var jsonOut = getOutputJson(data.message); } else if (typeof (data.error) != 'undefined') { @@ -447,13 +493,13 @@ launchAlgorithm = function() { hideProgress(); alert("Unexpected response"); } - resetExecuteButton(); + //resetExecuteButton(); }, error : function(richiesta, stato, errori) { hideProgress(); textAreaEnable(true); alert("Unexpected Error. Status: " + richiesta.status); - resetExecuteButton(); + //resetExecuteButton(); } }); } @@ -464,7 +510,13 @@ launchAlgorithm = function() { getOutputJson = function(message) { var tobemap = ""; for (var i = 0; i < message.length; i++) { - tobemap += message[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 { + tobemap += message[i] + "|"; + } } tobemap = tobemap.substring(0, tobemap.length - 1); @@ -486,9 +538,7 @@ getOutputJson = function(message) { && (data.response.trim().toUpperCase() == "ERROR")) { alert("ERROR\n" + data.message); } else { - $("#reset-upload").hide(); savedAnnotations = ""; - publicLink = null; showResult(data); } }, @@ -496,7 +546,7 @@ getOutputJson = function(message) { hideProgress(); $("#reset-upload").hide(); savedAnnotations = ""; - publicLink = null; + //publicLink = null; alert("Unexpected Error. Status: " + richiesta.status); } }); @@ -526,10 +576,14 @@ showResult = function(data) { $("#result-text-div").empty(); $("#result-text-div").append("

" + localText + "

"); - showAnnotationList(jsonContent.output.annotations); + buildAlgortihmList(); + buildAnnotationList(jsonContent.output.annotations); } -showAnnotationList = function(list) { +/* + * Build the list of radio-button controls with the annotations + */ +buildAnnotationList = function(list) { var colorDisabled = "CCCCCC"; var color; var colors = []; @@ -542,24 +596,93 @@ showAnnotationList = function(list) { } $("#result-params-div").append("
"); + + var firstRadio = true; for (var i = 0; i < annotations.length; i++) { - var cb = ""; cb += "
"; $("#colored-annotations").append(cb); + } + $("#colored-annotations :radio").change(function() { if (this.checked) { - rewriteText(this.getAttribute("named"), "#" + this.value); + checkedAnnotation = this.getAttribute("named"); + rewriteText("#" + this.value); } }); + + showAnnotationsList(); + + $("#colored-annotations :radio").change(); +} +/* + * Utility + */ +showAnnotationsList = function() { + $('.collapsible').collapsible('open', 0); +} + +/* + * build the list of check-box controls for algorithms + */ +buildAlgortihmList = function() { + $("#algorithm-params-div").empty(); + + for (var i = 0; i < jsonContent.output.result.length; i++) { + var cb = "

"; + cb += "

"; + $("#algorithm-params-div").append(cb); + + } + + 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 + */ +findNameByAlgorithmId = function(id) { + for(i in algorithms) { + if(algorithms[i].id.substr(algorithms[i].id.lastIndexOf(".")+1) == id) + return algorithms[i].name; + } + return id; } /* @@ -597,7 +720,7 @@ enhanceColor = function(color) { /* * Write the html paragraph

containing the text highlighted on annotation value */ -rewriteText = function(annotation, color) { +rewriteText = function(color) { $("#result-text-div").empty(); var complemetar = 0xFFFFFF - eval("0x" + color.substring(1)); @@ -609,42 +732,47 @@ rewriteText = function(annotation, color) { showProgress(); $(".hidden-div").show(); window.setTimeout(function() { - var indices = getIndices(annotation); + var indices = getIndices(); $(".hidden-div").hide(); $("#result-header-right").empty(); - $("#result-header-right").append("" + annotation + " occurs " + indices.length + " times."); - var indexedText = ""; + $("#result-header-right").append("" + checkedAnnotation + " occurs " + indices.length + " times."); - if ((typeof (indices) == 'undefined') || (indices.length == 0)) { - indexedText = resultText; + 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, "
"); - 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; + else { + $("#result-text-div").append("

" + resultText + "

"); } - if (t < resultText.length) - indexedText += resultText.substring(t); - - indexedText = indexedText.replace(/\n/g, "
"); - $("#result-text-div").append("

" + indexedText + "

"); - }, 50); } @@ -668,13 +796,25 @@ checkAnnotation = function(annotation) { /* * Retrieve the annotation indices from the json */ -getIndices = function(annotation) { +getIndices = function() { var indices = []; // get indices for (var i = 0; i < jsonContent.output.result.length; i++) { + // filter on algorithm + var found = false; + for(var j=0; j" + languages[i] + ""; if (i > 1) @@ -809,9 +960,15 @@ buildLanguageList = function() { + ""; $("#language-select").append(opt); } + + if(defaultLanguage != null) + $("#language-select").val(defaultLanguage); + $("#language-select").on("change", function() { selectAnnotationsByLanguage(); }); + + $("#language-select").change(); } /* diff --git a/src/main/webapp/js/merge.js b/src/main/webapp/js/merge.js index cf52ceb..b737b63 100644 --- a/src/main/webapp/js/merge.js +++ b/src/main/webapp/js/merge.js @@ -73,7 +73,7 @@ mergeAll = function(indices) { // [1] 'compareSegment'. // when two segment are equals or included compareSegment returns 0 // when two segment are intersecting compareSegment returns -1 - // when two segment have are external (no intersection) compareSegment returns 1 + // when two segment are external (no intersection) compareSegment returns 1 // // [2] 'mergeSegment' // returns the "union" of two segments