Some fix...

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@164756 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Erik Perrone 2018-03-06 13:26:22 +00:00
parent 50ea25069a
commit 48edb1d2ee
3 changed files with 65 additions and 42 deletions

View File

@ -128,6 +128,7 @@ public class DataminerClient {
@Override
public void running(double percentage) {
logger.debug("Operation Running: " + percentage);
//System.out.println("Operation Running: " + percentage);
}
@Override
@ -135,7 +136,7 @@ public class DataminerClient {
logger.error("Operation Failed");
logger.error(message);
logger.error(exception.getStackTrace().toString());
System.out.println(exception.getLocalizedMessage());
//System.out.println(exception.getLocalizedMessage());
}
@Override
@ -154,11 +155,13 @@ public class DataminerClient {
@Override
public void accepted() {
logger.debug("Operation Accepted");
}
};
DMMonitor dmMonitor = new DMMonitor(computationId, sClient);
dmMonitor.setDelay(1000);
dmMonitor.setSleep(1000);
dmMonitor.setPeriod(1000);
dmMonitor.add(listener);
dmMonitor.start();
}

View File

@ -80,12 +80,16 @@ public class NlpNerRunner extends DataminerClient {
for (String key : mapResource.getMap().keySet()) {
Resource r = mapResource.getMap().get(key);
if (r.isFile()) {
FileResource f = (FileResource) r;
String link = f.getUrl();
System.out.println("url: " + link);
String op = computationId.getOperatorId();
op = op.substring(op.lastIndexOf(".") + 1);
testEndOfProcess(op + ":::" + link);
String mimeType = f.getMimeType();
if (mimeType.equalsIgnoreCase("application/d4science")) {
String link = f.getUrl();
System.out.println("url: " + link);
String op = computationId.getOperatorId();
op = op.substring(op.lastIndexOf(".") + 1);
testEndOfProcess(op + ":::" + link);
}
}
}
}
@ -118,6 +122,7 @@ public class NlpNerRunner extends DataminerClient {
if (outputLinks.size() == identifiers.length) {
String[] links = new String[outputLinks.size()];
links = outputLinks.toArray(links);
System.out.println("testEndOfProcess");
writeResponse(links);
}
}
@ -125,11 +130,23 @@ public class NlpNerRunner extends DataminerClient {
private void writeResponse(String[] content) {
if (response != null) {
response.setContentType("application/json;charset=UTF-8");
PrintWriter writer = null;
try {
PrintWriter writer = response.getWriter();
writer.println(new JsonManager().getSuccessJsonResponse(content));
writer = response.getWriter();
String msg = new JsonManager().getSuccessJsonResponse(content);
System.out.println("msg: " + msg);
writer.println(msg);
if(writer.checkError()) {
logger.error("writeResponse method has some problem in writing result.");
System.out.println("writeResponse method has some problem in writing result.");
}
} catch (Exception ex) {
logger.error(ex.getLocalizedMessage());
ex.printStackTrace();
} finally {
if(writer != null)
writer.close();
}
}
@ -138,15 +155,20 @@ public class NlpNerRunner extends DataminerClient {
private void writeResponse(String content, boolean isOk) {
if (response != null) {
response.setContentType("application/json;charset=UTF-8");
PrintWriter writer = null;
try {
PrintWriter writer = response.getWriter();
writer = response.getWriter();
if (isOk) {
writer.println(new JsonManager().getSuccessJsonResponse("" + content));
} else {
writer.println(new JsonManager().getErrorJsonResponse("" + content));
}
writer.flush();
} catch (Exception ex) {
logger.error(ex.getLocalizedMessage());
} finally {
if(writer != null)
writer.close();
}
}
}
@ -189,9 +211,9 @@ public class NlpNerRunner extends DataminerClient {
* "http://dataminer-prototypes.d4science.org/wps/"; String identifier = "";
* identifier =
* "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.ENGLISH_NAMED_ENTITY_RECOGNIZER";
* // identifier = //
* // identifier = // //
* "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.NEWSTANBOLWRAPPER";
* // identifier = //
* // identifier = // //
* "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.GENERIC_OPINION_MINING_ENGLISH";
* String token = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462"; String
* pLink =
@ -202,8 +224,8 @@ public class NlpNerRunner extends DataminerClient {
* params.add(p);
*
* NlpNerRunner runner = new NlpNerRunner(service, identifier, token); //
* try { // runner.run(pLink, service, identifier, params); // } catch
* (NlpHubException e) { // e.printStackTrace(); // } }
* try { runner.run(pLink, service, identifier, params); } catch
* (NlpHubException e) { e.printStackTrace(); } }
*/
}

View File

@ -59,24 +59,6 @@
jsonContent = null;
});
// the following line is only for develop
/*
var devData = "{\"link\":\"http://data.d4science.org/Wm5XY1p0TlFIM3NXZnZ1SkhLRlRMK3l6N05jVFhiSXFHbWJQNStIS0N6Yz0\",\"output\":"
+ "{\"text\":\"yes, we can do it tomorrow in the evening.\",\"annotations\":\"Date,Sentence\",\"language\":\"English\",\"result\":"
+ "[{\"algorithm\":\"ENGLISH_NAMED_ENTITY_RECOGNIZER\",\"entities\":[{\"Date\":[{\"indices\":[18,26],\"ruleFinal\":\"DateOnlyFinal\",\"kind\":\"date\",\"rule\":\"GazDateWords\"}]},{\"Sentence\":[{\"indices\":[0,42]}]}]}]}}";
devData = "{\"link\":\"http://data.d4science.org/dXZ5L3RrRjYyTWNXZnZ1SkhLRlRMeXZzd1prOVFqWDFHbWJQNStIS0N6Yz0\",\"output\":"
+ "{\"text\":\"In the 1970s, Iraq under Baath Party dictator Brigadier General Ahmad Hassan al-Bakr had grown close to the Soviet Union, "
+ "with which it signed a treaty of friendship in 1972 and from which it began importing arms. In 1973, al-Bakr supported the Syrians in their war with Israel.\","
+ "\"annotations\":\"Date,Person\",\"language\":\"English\",\"result\": [{\"algorithm\":\"ENGLISH_NAMED_ENTITY_RECOGNIZER\",\"entities\":[{\"Date\":[{\"indices\":[3,12],"
+ "\"ruleFinal\":\"DateOnlyFinal\",\"kind\":\"date\",\"rule\":\"YearSpan1\"},{\"indices\":[169,173],\"ruleFinal\":\"DateOnlyFinal\",\"kind\":\"date\",\"rule\":\"YearContext1\"},"
+ "{\"indices\":[217,221],\"ruleFinal\":\"YearOnlyFinal\",\"kind\":\"date\",\"rule\":\"TempYear2\"}]},{\"Person\":[{\"indices\":[46,76],\"firstName\":\"Ahmad\",\"ruleFinal\":\""
+ "PersonFinal\",\"gender\":\"unknown\",\"surname\":\"Hassan\",\"kind\":\"personName\",\"rule\":\"PersonTitleGenderUnknown\",\"title\":\"Brigadier\"},{\"indices\":[77,84],\"firstName\":"
+ "\"al\",\"ruleFinal\":\"PersonFinal\",\"gender\":\"male\",\"surname\":\"Bakr\",\"kind\":\"fullName\",\"rule\":\"PersonFull\"},{\"indices\":[223,230],\"firstName\":\"al\",\"ruleFinal\":\"PersonFinal\",\"gender\":\"male\",\"surname\":\"Bakr\",\"kind\":\"fullName\",\"rule\":\"PersonFull\"}]}]}]}}";
showResult(devData);
*/
// --------------------------------------
$("#execute-button").css("background-color", pageGray);
$("#upload-button")
@ -355,7 +337,7 @@
type : "POST",
async : true,
success : function(data, stato) {
hideProgress();
//hideProgress();
textAreaEnable(true);
$("#file-info").empty();
if (typeof (data.response) != 'undefined') {
@ -395,6 +377,7 @@
type : "POST",
async : true,
success : function(data, stato) {
hideProgress();
console.log(data);
if((typeof (data.response) != "undefined") && (data.response.trim().toUpperCase() == "ERROR")) {
alert ("ERROR\n" + data.message);
@ -407,6 +390,7 @@
}
},
error : function(richiesta, stato, errori) {
hideProgress();
$("#reset-upload").hide();
savedAnnotations = "";
publicLink = null;
@ -431,7 +415,7 @@
$("#result-header")
.append(
"<p>You can download the result file from <a href='" + jsonContent.link +"'>here</a></p>");
"<p>You can download the overall result as a JSON file <a href='" + jsonContent.link +"'>here</a></p>");
var localText = resultText;
localText = resultText.replace(/\n/g, "<br>");
$("#result-text-div").empty();
@ -450,7 +434,11 @@
$("#result-params-div")
.append("<form id='colored-annotations'></form>");
for (var i = 0; i < annotations.length; i++) {
var cb = "<input type='radio' name='foo' named='" + annotations[i] + "' value='" + colors[i] + "' id='color-" + i + "' class='filled-in'>";
var cb = "<input type='radio' name='foo' ";
if(!checkAnnotation(annotations[i])) {
cb += "disabled ";
}
cb += "named='" + annotations[i] + "' value='" + colors[i] + "' id='color-" + i + "' class='filled-in'>";
cb += "<label for='color-" + i + "'><span style='font-weight:bold; color:#" + colors[i] + "'>"
+ annotations[i] + "</span></label><br>";
$("#colored-annotations").append(cb);
@ -516,6 +504,19 @@
$("#result-text-div").append("<p>" + indexedText + "</p>");
}
checkAnnotation = function(annotation) {
for (var i = 0; i < jsonContent.output.result.length; i++) {
var entities = jsonContent.output.result[i].entities;
for (var j = 0; j < entities.length; j++) {
a = entities[j][annotation];
if (typeof a != 'undefined') {
return true;
}
}
}
return false;
}
getIndices = function(annotation) {
var indices = [];
// get indices
@ -692,8 +693,7 @@
<div class="row">
<div class="clearfix">
<div class="column half-width">
<p class="margin-3 text-align-right">Select the desired
language:</p>
<p class="margin-3 text-align-right"></p>
</div>
<div class="column half-width">
<select id="language-select" class="margin-3 align-left">
@ -708,9 +708,7 @@
<div class="row">
<div class="clearfix">
<div class="column margin-right-10px">
<p>To upload a text file you can use the button or drag a
file on the "upload arrow". Otherwise, write some text in the
text area.</p>
<p>Drag a file on the Upload box, or select a file from your PC, or paste a text.</p>
</div>
<div class="column margin-left-10px">
<div class="centered full-width" id="fu-container">
@ -730,7 +728,7 @@
<fieldset>
<legend>Annotations (mark annotation you want to use)</legend>
<legend>Annotations (deselect those you don't want to be reported)</legend>
<div class="vscrollable">
<table id="annotations-table">
</table>
@ -739,7 +737,7 @@
<!-- this is the "execute button" -->
<div style="text-align: center; padding: 5px;">
<a id="execute-button">Execute</a>
<a id="execute-button">Analyse</a>
</div>
</div>
<!-- this is the main result container -->