Some improvement and error fix.

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@165269 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Erik Perrone 2018-03-20 13:45:49 +00:00
parent 43a834505d
commit 7286d1d251
5 changed files with 56 additions and 22 deletions

View File

@ -61,6 +61,7 @@ public class AsyncHttpRequest extends Thread {
} catch (Exception x) { } catch (Exception x) {
logger.error(x.getLocalizedMessage()); logger.error(x.getLocalizedMessage());
asyncHttpRequestCallback();
} finally { } finally {
try { try {
if (r != null) if (r != null)

View File

@ -24,8 +24,9 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
public final static String WPS_DESCRIBE_PROCESS_URL = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=DescribeProcess&service=WPS&Version=1.0.0"; public final static String WPS_DESCRIBE_PROCESS_URL = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=DescribeProcess&service=WPS&Version=1.0.0";
private String identifier, token, httpMethod, annotations, publicLink, language; private String identifier, token, httpMethod, annotations, publicLink, language;
private Logger logger = Logger.getLogger(NlpAsyncNerRunner.class.getSimpleName()); private Logger logger = Logger.getLogger(NlpAsyncNerRunner.class.getSimpleName());
private RunnerCommander commander;
public NlpAsyncNerRunner(String identifier, String token, String publicLink, String annotations, String language) { public NlpAsyncNerRunner(String identifier, String token, String publicLink, String annotations, String language, RunnerCommander commander) {
super(); super();
this.identifier = identifier; this.identifier = identifier;
this.token = token; this.token = token;
@ -33,6 +34,7 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
this.annotations = annotations; this.annotations = annotations;
this.publicLink = publicLink; this.publicLink = publicLink;
this.language = language; // not used for the moment... this.language = language; // not used for the moment...
this.commander = commander;
ArrayList<NlpParameter> params = buildParameterString(); ArrayList<NlpParameter> params = buildParameterString();
String serviceUrl = WPS_EXECUTE_URL + "&gcube-token=" + token + "&lang=en-US&Identifier=" + identifier; String serviceUrl = WPS_EXECUTE_URL + "&gcube-token=" + token + "&lang=en-US&Identifier=" + identifier;
serviceUrl += "&" + setUrl(params); serviceUrl += "&" + setUrl(params);
@ -138,10 +140,10 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
logger.info("ID: " + identifier.substring(identifier.lastIndexOf(".") + 1) + " elapsed time: " + elapsedTime); logger.info("ID: " + identifier.substring(identifier.lastIndexOf(".") + 1) + " elapsed time: " + elapsedTime);
String result = super.getResult(); String result = super.getResult();
String theLink = ""; String theLink = "";
//System.out.println(result);
BufferedReader r = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8))));
try { try {
BufferedReader r = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8))));
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(r)); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(r));
doc.getDocumentElement().normalize(); doc.getDocumentElement().normalize();
NodeList nListResult = doc.getElementsByTagName("ogr:Result"); NodeList nListResult = doc.getElementsByTagName("ogr:Result");
@ -165,9 +167,9 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
theLink = res; theLink = res;
} }
} }
RunnerCommander.updateResultList(identifier.substring(identifier.lastIndexOf(".") + 1) + ":::" + theLink); commander.updateResultList(identifier.substring(identifier.lastIndexOf(".") + 1) + ":::" + theLink);
} catch (Exception x) { } catch (Exception x) {
RunnerCommander.updateResultList(identifier.substring(identifier.lastIndexOf(".") + 1) + ":::" + Constants.ERROR_ID); commander.updateResultList(identifier.substring(identifier.lastIndexOf(".") + 1) + ":::" + Constants.ERROR_ID);
logger.error(x.getLocalizedMessage()); logger.error(x.getLocalizedMessage());
} }
} }

View File

@ -15,7 +15,7 @@ public class RunnerCommander extends Thread {
private String[] identifiers = null; private String[] identifiers = null;
private String link = ""; private String link = "";
private String token = ""; private String token = "";
private static ArrayList<String> outResultList = null; private ArrayList<String> outResultList = null;
private long sleepTime = 500l; private long sleepTime = 500l;
private long maxWaitingTime = 5l * 60l * 1000l; private long maxWaitingTime = 5l * 60l * 1000l;
private Logger logger = Logger.getLogger(RunnerCommander.class.getSimpleName()); private Logger logger = Logger.getLogger(RunnerCommander.class.getSimpleName());
@ -50,7 +50,7 @@ public class RunnerCommander extends Thread {
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
} }
public synchronized static void updateResultList(String res) { public synchronized void updateResultList(String res) {
outResultList.add(res); outResultList.add(res);
} }
@ -75,7 +75,7 @@ public class RunnerCommander extends Thread {
private void runAlgorithms() { private void runAlgorithms() {
for (String id : identifiers) { for (String id : identifiers) {
NlpAsyncNerRunner n = new NlpAsyncNerRunner(id, token, link, annotationList, null); NlpAsyncNerRunner n = new NlpAsyncNerRunner(id, token, link, annotationList, null, this);
n.start(); n.start();
} }
} }

View File

@ -101,14 +101,15 @@
<div class="left-side" id="result-text-div"></div> <div class="left-side" id="result-text-div"></div>
<div class="right-side"> <div class="right-side">
<ul class="collapsible" data-collapsible="accordion" id="ner-result-accordion"> <ul class="collapsible" data-collapsible="accordion" id="ner-result-accordion">
<li>
<div class="collapsible-header">Annotations</div>
<div class="collapsible-body" id="result-params-div"></div>
</li>
<li> <li>
<div class="collapsible-header">Algorithms</div> <div class="collapsible-header">Algorithms</div>
<div class="collapsible-body" id="algorithm-params-div"></div> <div class="collapsible-body" id="algorithm-params-div"></div>
</li> </li>
<li>
<div class="collapsible-header">Annotations</div>
<div class="collapsible-body" id="result-params-div"></div>
</li>
</ul> </ul>
</div> </div>
<div style="text-align: left;"> <div style="text-align: left;">

View File

@ -21,7 +21,18 @@ var checkedAlgs = [];
$(document).ready(function() { $(document).ready(function() {
disableExecuteButton(); disableExecuteButton();
$('.collapsible').collapsible(); // $('.collapsible').collapsible();
// $('.collapsible').collapsible({
// onOpen: function(el) {
// console.log(el);
// $('.collapsible').collapsible('close', el.prevObject.index());
// },
// onClose: function(el) {
// console.log(el);
// $('.collapsible').collapsible('open', el.prevObject.index());
// }
// });
$.ajax({ $.ajax({
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0", url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
type : "GET", type : "GET",
@ -37,6 +48,7 @@ $(document).ready(function() {
resizeTable(); resizeTable();
resizeLogo(); resizeLogo();
enableAjaxFileUpload(); enableAjaxFileUpload();
collapsibleHandler();
$("#logo-image").click(function() { $("#logo-image").click(function() {
backHandler(); backHandler();
@ -108,7 +120,6 @@ $(document).ready(function() {
}, },
onSuccess : function(files, data, xhr) { onSuccess : function(files, data, xhr) {
hideProgress(); hideProgress();
//console.log('' + data.language);
checkLanguage(data.language); checkLanguage(data.language);
selectAnnotationsByLanguage(); selectAnnotationsByLanguage();
$("#reset-upload").css("display", $("#reset-upload").css("display",
@ -139,6 +150,25 @@ $(document).ready(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);
// }
// });
}
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);
@ -637,7 +667,8 @@ buildAnnotationList = function(list) {
* Utility * Utility
*/ */
showAnnotationsList = function() { showAnnotationsList = function() {
$('.collapsible').collapsible('open', 0); $('.collapsible').collapsible();
$('.collapsible').collapsible('open', 1);
} }
/* /*
@ -721,9 +752,11 @@ enhanceColor = function(color) {
* 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) {
$("#result-text-div").empty(); if(color.startsWith("#"))
color = color.substring(1);
var complemetar = 0xFFFFFF - eval("0x" + color.substring(1)); $("#result-text-div").empty();
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));
@ -842,10 +875,7 @@ getIndices = function() {
*/ */
mergeIndices = function(indices) { mergeIndices = function(indices) {
var newIndices = []; var newIndices = [];
if (indices.length == 1) newIndices = mergeAll(indices);
newIndices = indices[0];
else
newIndices = mergeAll(indices);
return newIndices; return newIndices;
} }