Algorithm selection
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@165247 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e2729e357b
commit
43a834505d
|
@ -65,6 +65,7 @@ public class NLPHub extends HttpServlet {
|
||||||
RunnerCommander commander = new RunnerCommander(algs, request.getParameter("plink"), request.getParameter("annotations"), token,
|
RunnerCommander commander = new RunnerCommander(algs, request.getParameter("plink"), request.getParameter("annotations"), token,
|
||||||
response);
|
response);
|
||||||
commander.setSleepTime(100);
|
commander.setSleepTime(100);
|
||||||
|
commander.setMaxWaitingTime(90*1000);
|
||||||
commander.startProcess();
|
commander.startProcess();
|
||||||
/*
|
/*
|
||||||
if (algs.length >= 1) {
|
if (algs.length >= 1) {
|
||||||
|
|
|
@ -79,27 +79,16 @@ public class NLPMapper extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
String annotations = request.getParameter("annotations");
|
String annotations = request.getParameter("annotations");
|
||||||
//System.out.println("annotations\n: " + annotations);
|
|
||||||
String language = request.getParameter("lang");
|
String language = request.getParameter("lang");
|
||||||
PrintWriter writer = response.getWriter();
|
PrintWriter writer = response.getWriter();
|
||||||
//System.out.println("language\n: " + language);
|
|
||||||
|
|
||||||
//System.out.println("tokens length: " + tokens.length);
|
|
||||||
// for(int u=0; u<tokens.length; u++) {
|
|
||||||
// System.out.println("[" + u + "] " + tokens[u]);
|
|
||||||
// }
|
|
||||||
try {
|
try {
|
||||||
String text = getDocument(documentLink);
|
String text = getDocument(documentLink);
|
||||||
|
|
||||||
|
|
||||||
text = text.replaceAll("\n", "\\\\n");;
|
text = text.replaceAll("\n", "\\\\n");;
|
||||||
text = text.replaceAll("\r", "\\\\r");
|
text = text.replaceAll("\r", "\\\\r");
|
||||||
text = text.replaceAll("\t", "\\\\t");
|
text = text.replaceAll("\t", "\\\\t");
|
||||||
text = text.replaceAll("\"", "\\\\\"");
|
text = text.replaceAll("\"", "\\\\\"");
|
||||||
|
|
||||||
// byte[] b = text.getBytes();
|
|
||||||
// System.out.println(Constants.hexDump(b));
|
|
||||||
|
|
||||||
String out = "{";
|
String out = "{";
|
||||||
out += "\"text\":\"" + text + "\",";
|
out += "\"text\":\"" + text + "\",";
|
||||||
out += "\"annotations\":\"" + annotations + "\",";
|
out += "\"annotations\":\"" + annotations + "\",";
|
||||||
|
@ -109,11 +98,12 @@ public class NLPMapper extends HttpServlet {
|
||||||
for (int i = 0; i < tokens.length; i++) {
|
for (int i = 0; i < tokens.length; i++) {
|
||||||
String token = tokens[i];
|
String token = tokens[i];
|
||||||
String[] t = token.split(":::");
|
String[] t = token.split(":::");
|
||||||
//System.out.println(t[0]);
|
if(t[1].equals(Constants.ERROR_ID)) {
|
||||||
//System.out.println(t[1]);
|
logger.error("Algorithm " + t[0] + " in error. Bypass...");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String json = ((JsonMapper) (getMapper(t[0]).newInstance())).getJson(t[0], t[1]);
|
String json = ((JsonMapper) (getMapper(t[0]).newInstance())).getJson(t[0], t[1]);
|
||||||
//System.out.println("" + json);
|
|
||||||
out += json;
|
out += json;
|
||||||
if (i < tokens.length - 1)
|
if (i < tokens.length - 1)
|
||||||
out += ",";
|
out += ",";
|
||||||
|
@ -123,7 +113,6 @@ public class NLPMapper extends HttpServlet {
|
||||||
}
|
}
|
||||||
out += "]}";
|
out += "]}";
|
||||||
|
|
||||||
|
|
||||||
String resultLink = saveResult(out);
|
String resultLink = saveResult(out);
|
||||||
String outResult = "{";
|
String outResult = "{";
|
||||||
outResult += "\"link\":\"" + resultLink + "\",";
|
outResult += "\"link\":\"" + resultLink + "\",";
|
||||||
|
@ -172,6 +161,8 @@ public class NLPMapper extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
String link = ws.getPublicLink(fileName, token);
|
String link = ws.getPublicLink(fileName, token);
|
||||||
|
|
||||||
|
logger.info("Output json [" + fileName + "] created in " + (System.currentTimeMillis() - now) + " millisec.");
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ package org.gcube.nlphub.legacy;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
//public static String DATAMINER_URL = "http://dataminer0-proto.d4science.org";
|
||||||
|
//public static String DATAMINER_URL = "http://dataminer2-proto.d4science.org";
|
||||||
|
public static String DATAMINER_URL = "http://dataminer-prototypes.d4science.org";
|
||||||
public static String DEFAULT_DESCRIPTION = "NlpHub upload";
|
public static String DEFAULT_DESCRIPTION = "NlpHub upload";
|
||||||
public static String TOKEN_PARAMETER = "gcube-token";
|
public static String TOKEN_PARAMETER = "gcube-token";
|
||||||
public static String TEST_TOKEN = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
|
public static String TEST_TOKEN = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
|
||||||
|
|
|
@ -54,7 +54,8 @@ public class NLpLanguageRecognizer extends DataminerClient {
|
||||||
|
|
||||||
public static void run(String sentence, String token, String publicLink, HttpServletResponse response) throws NlpHubException {
|
public static void run(String sentence, String token, String publicLink, HttpServletResponse response) throws NlpHubException {
|
||||||
try {
|
try {
|
||||||
String urlService = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
//String urlService = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
||||||
|
String urlService = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
||||||
urlService += "&gcube-token=" + token;
|
urlService += "&gcube-token=" + token;
|
||||||
urlService += "&lang=en-US";
|
urlService += "&lang=en-US";
|
||||||
urlService += "&Identifier=" + RECOGNIZER_ID;
|
urlService += "&Identifier=" + RECOGNIZER_ID;
|
||||||
|
|
|
@ -20,8 +20,8 @@ import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
public final static String WPS_EXECUTE_URL = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
public final static String WPS_EXECUTE_URL = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
||||||
public final static String WPS_DESCRIBE_PROCESS_URL = "http://dataminer-prototypes.d4science.org/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());
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
serviceUrl += "&" + setUrl(params);
|
serviceUrl += "&" + setUrl(params);
|
||||||
super.setBaseUrl(serviceUrl);
|
super.setBaseUrl(serviceUrl);
|
||||||
super.setMethod(httpMethod);
|
super.setMethod(httpMethod);
|
||||||
//System.out.println(serviceUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NlpAsyncNerRunner(String baseUrl, String method) {
|
public NlpAsyncNerRunner(String baseUrl, String method) {
|
||||||
|
|
|
@ -103,7 +103,7 @@ pre {
|
||||||
float: left;
|
float: left;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
color: white;
|
color: white;
|
||||||
background-color: #4CAF50 !important;
|
background-color: #4CAF50; /*!important;*/
|
||||||
padding: 0.6rem;
|
padding: 0.6rem;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
@ -189,6 +189,7 @@ pre {
|
||||||
#logo-image {
|
#logo-image {
|
||||||
width: 200px;
|
width: 200px;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ajax-file-upload-container {
|
.ajax-file-upload-container {
|
||||||
|
@ -239,6 +240,12 @@ select {
|
||||||
border: 1px solid silver;
|
border: 1px solid silver;
|
||||||
height: 60vh;
|
height: 60vh;
|
||||||
margin: 2px;
|
margin: 2px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ner-result-accordion {
|
||||||
|
height: 60vh;
|
||||||
|
margin: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.left-side-half {
|
.left-side-half {
|
||||||
|
@ -280,6 +287,10 @@ select {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#algorithm-param_div {
|
||||||
|
font-size: 12px !important;
|
||||||
|
}
|
||||||
|
|
||||||
#result-text-div {
|
#result-text-div {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +299,16 @@ select {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.collapsible-body {
|
||||||
|
padding-left: 2px !important;
|
||||||
|
padding-right: 2px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collapsible-header {
|
||||||
|
color: white;
|
||||||
|
background-color: #4CAF50;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
input[type="checkbox"]:not(:checked){
|
input[type="checkbox"]:not(:checked){
|
||||||
position: unset !important;
|
position: unset !important;
|
||||||
|
@ -306,6 +327,11 @@ input[type="checkbox"]:checked {
|
||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.collapsible {
|
||||||
|
-webkit-box-shadow: none !important;
|
||||||
|
-moz-box-shadow: none !important;;
|
||||||
|
box-shadow: none !important;;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
#result-params-div input[type="checkbox"]:not(:checked){
|
#result-params-div input[type="checkbox"]:not(:checked){
|
||||||
position: unset !important;
|
position: unset !important;
|
||||||
|
|
|
@ -65,8 +65,6 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="column margin-left-10px">
|
<div class="column margin-left-10px">
|
||||||
<div class="centered full-width" id="fu-container">
|
<div class="centered full-width" id="fu-container">
|
||||||
<!-- <div class="waves-effect waves-light btn green darken-1"
|
|
||||||
id="upload-button">Upload text file</div>-->
|
|
||||||
<div class="waves-effect waves-light darken-1"
|
<div class="waves-effect waves-light darken-1"
|
||||||
id="upload-button">Upload text file</div>
|
id="upload-button">Upload text file</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -101,7 +99,18 @@
|
||||||
</div>
|
</div>
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="left-side" id="result-text-div"></div>
|
<div class="left-side" id="result-text-div"></div>
|
||||||
<div class="right-side" id="result-params-div"></div>
|
<div class="right-side">
|
||||||
|
<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>
|
||||||
|
<div class="collapsible-header">Algorithms</div>
|
||||||
|
<div class="collapsible-body" id="algorithm-params-div"></div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
<div style="text-align: left;">
|
<div style="text-align: left;">
|
||||||
<div class="green-button float-right-div" id="back-ner-ui-button">back</div>
|
<div class="green-button float-right-div" id="back-ner-ui-button">back</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,6 +11,8 @@ var named = null;
|
||||||
var resultText = "";
|
var resultText = "";
|
||||||
var hexLetters = '0123456789ABCDEF';
|
var hexLetters = '0123456789ABCDEF';
|
||||||
var txtFlag = true;
|
var txtFlag = true;
|
||||||
|
var checkedAnnotation = "";
|
||||||
|
var checkedAlgs = [];
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
// Starting point: get the csv file with algorithm parameters and set the page
|
// Starting point: get the csv file with algorithm parameters and set the page
|
||||||
|
@ -19,6 +21,7 @@ var txtFlag = true;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
disableExecuteButton();
|
disableExecuteButton();
|
||||||
|
$('.collapsible').collapsible();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
|
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
|
||||||
type : "GET",
|
type : "GET",
|
||||||
|
@ -33,13 +36,14 @@ $(document).ready(function() {
|
||||||
buildAnnotations();
|
buildAnnotations();
|
||||||
resizeTable();
|
resizeTable();
|
||||||
resizeLogo();
|
resizeLogo();
|
||||||
|
enableAjaxFileUpload();
|
||||||
|
|
||||||
|
$("#logo-image").click(function() {
|
||||||
|
backHandler();
|
||||||
|
});
|
||||||
|
|
||||||
$("#back-ner-ui-button").click(function() {
|
$("#back-ner-ui-button").click(function() {
|
||||||
$("#ner-result-container").hide();
|
backHandler();
|
||||||
$("#ner-ui").show();
|
|
||||||
$("#input-textarea").val("");
|
|
||||||
publicLink = null;
|
|
||||||
jsonContent = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
disableExecuteButton();
|
disableExecuteButton();
|
||||||
|
@ -72,8 +76,7 @@ $(document).ready(function() {
|
||||||
.append(
|
.append(
|
||||||
"<div id=\"reset-upload\" class=\"centered\">Cancel</div>");
|
"<div id=\"reset-upload\" class=\"centered\">Cancel</div>");
|
||||||
$("#reset-upload").hide();
|
$("#reset-upload").hide();
|
||||||
$("#reset-upload").click(
|
$("#reset-upload").click(function() {
|
||||||
function() {
|
|
||||||
resetExecuteButton();
|
resetExecuteButton();
|
||||||
$("#file-info").empty();
|
$("#file-info").empty();
|
||||||
$("#reset-upload").css(
|
$("#reset-upload").css(
|
||||||
|
@ -94,6 +97,9 @@ $(document).ready(function() {
|
||||||
txtFlag = false;
|
txtFlag = false;
|
||||||
alert("The application supports text file only (.TXT)");
|
alert("The application supports text file only (.TXT)");
|
||||||
}
|
}
|
||||||
|
publicLink = null;
|
||||||
|
textAreaEnable(false);
|
||||||
|
$("#input-textarea").val("");
|
||||||
},
|
},
|
||||||
onSubmit: function(files) {
|
onSubmit: function(files) {
|
||||||
var submitFlag = txtFlag;
|
var submitFlag = txtFlag;
|
||||||
|
@ -107,7 +113,6 @@ $(document).ready(function() {
|
||||||
selectAnnotationsByLanguage();
|
selectAnnotationsByLanguage();
|
||||||
$("#reset-upload").css("display",
|
$("#reset-upload").css("display",
|
||||||
"inline");
|
"inline");
|
||||||
//console.log("files: " + files);
|
|
||||||
$("#file-info").empty();
|
$("#file-info").empty();
|
||||||
$("#file-info")
|
$("#file-info")
|
||||||
.append(
|
.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
|
* Utility function processing the language indication returned by the language recognition service
|
||||||
|
@ -286,16 +327,22 @@ isEnabled = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
enableDisableTextArea = function() {
|
enableDisableTextArea = function() {
|
||||||
if ($("#input-textarea").val() == "")
|
if ($("#input-textarea").val() == "") {
|
||||||
disableExecuteButton();
|
disableExecuteButton();
|
||||||
else
|
enableAjaxFileUpload();
|
||||||
|
}
|
||||||
|
else {
|
||||||
enableExecuteButton();
|
enableExecuteButton();
|
||||||
|
disableAjaxFileUpload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the listeners on the text area and the execute button
|
* Set the listeners on the text area and the execute button
|
||||||
*/
|
*/
|
||||||
setEventListeners = function() {
|
setEventListeners = function() {
|
||||||
|
$(".ajax-file-upload").attr("id", "ajax-file-upload-id");
|
||||||
|
|
||||||
$("#input-textarea").on("keyup", function() {
|
$("#input-textarea").on("keyup", function() {
|
||||||
enableDisableTextArea();
|
enableDisableTextArea();
|
||||||
});
|
});
|
||||||
|
@ -421,6 +468,7 @@ launchAlgorithm = function() {
|
||||||
}
|
}
|
||||||
if (algList.length == 0) {
|
if (algList.length == 0) {
|
||||||
alert("Warning. No algorithm matching with selected language.");
|
alert("Warning. No algorithm matching with selected language.");
|
||||||
|
hideProgress();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
algList = algList.substring(0, algList.length - 1);
|
algList = algList.substring(0, algList.length - 1);
|
||||||
|
@ -436,8 +484,6 @@ launchAlgorithm = function() {
|
||||||
async : true,
|
async : true,
|
||||||
success : function(data, stato) {
|
success : function(data, stato) {
|
||||||
textAreaEnable(true);
|
textAreaEnable(true);
|
||||||
$("#file-info").empty();
|
|
||||||
$("#reset-upload").css("display", "none");
|
|
||||||
if (typeof (data.response) != 'undefined') {
|
if (typeof (data.response) != 'undefined') {
|
||||||
var jsonOut = getOutputJson(data.message);
|
var jsonOut = getOutputJson(data.message);
|
||||||
} else if (typeof (data.error) != 'undefined') {
|
} else if (typeof (data.error) != 'undefined') {
|
||||||
|
@ -447,13 +493,13 @@ launchAlgorithm = function() {
|
||||||
hideProgress();
|
hideProgress();
|
||||||
alert("Unexpected response");
|
alert("Unexpected response");
|
||||||
}
|
}
|
||||||
resetExecuteButton();
|
//resetExecuteButton();
|
||||||
},
|
},
|
||||||
error : function(richiesta, stato, errori) {
|
error : function(richiesta, stato, errori) {
|
||||||
hideProgress();
|
hideProgress();
|
||||||
textAreaEnable(true);
|
textAreaEnable(true);
|
||||||
alert("Unexpected Error. Status: " + richiesta.status);
|
alert("Unexpected Error. Status: " + richiesta.status);
|
||||||
resetExecuteButton();
|
//resetExecuteButton();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -464,8 +510,14 @@ launchAlgorithm = function() {
|
||||||
getOutputJson = function(message) {
|
getOutputJson = function(message) {
|
||||||
var tobemap = "";
|
var tobemap = "";
|
||||||
for (var i = 0; i < message.length; i++) {
|
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 {
|
||||||
tobemap += message[i] + "|";
|
tobemap += message[i] + "|";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tobemap = tobemap.substring(0, tobemap.length - 1);
|
tobemap = tobemap.substring(0, tobemap.length - 1);
|
||||||
|
|
||||||
|
@ -486,9 +538,7 @@ getOutputJson = function(message) {
|
||||||
&& (data.response.trim().toUpperCase() == "ERROR")) {
|
&& (data.response.trim().toUpperCase() == "ERROR")) {
|
||||||
alert("ERROR\n" + data.message);
|
alert("ERROR\n" + data.message);
|
||||||
} else {
|
} else {
|
||||||
$("#reset-upload").hide();
|
|
||||||
savedAnnotations = "";
|
savedAnnotations = "";
|
||||||
publicLink = null;
|
|
||||||
showResult(data);
|
showResult(data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -496,7 +546,7 @@ getOutputJson = function(message) {
|
||||||
hideProgress();
|
hideProgress();
|
||||||
$("#reset-upload").hide();
|
$("#reset-upload").hide();
|
||||||
savedAnnotations = "";
|
savedAnnotations = "";
|
||||||
publicLink = null;
|
//publicLink = null;
|
||||||
alert("Unexpected Error. Status: " + richiesta.status);
|
alert("Unexpected Error. Status: " + richiesta.status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -526,10 +576,14 @@ showResult = function(data) {
|
||||||
$("#result-text-div").empty();
|
$("#result-text-div").empty();
|
||||||
$("#result-text-div").append("<p>" + localText + "</p>");
|
$("#result-text-div").append("<p>" + localText + "</p>");
|
||||||
|
|
||||||
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 colorDisabled = "CCCCCC";
|
||||||
var color;
|
var color;
|
||||||
var colors = [];
|
var colors = [];
|
||||||
|
@ -542,24 +596,93 @@ showAnnotationList = function(list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#result-params-div").append("<form id='colored-annotations'></form>");
|
$("#result-params-div").append("<form id='colored-annotations'></form>");
|
||||||
|
|
||||||
|
var firstRadio = true;
|
||||||
for (var i = 0; i < annotations.length; i++) {
|
for (var i = 0; i < annotations.length; i++) {
|
||||||
var cb = "<input type='radio' name='foo' ";
|
var cb = "<input type='radio' name='foo-ner-annotations' ";
|
||||||
if (!checkAnnotation(annotations[i])) {
|
if (!checkAnnotation(annotations[i])) {
|
||||||
cb += "disabled ";
|
cb += "disabled ";
|
||||||
colors[i] = colorDisabled;
|
colors[i] = colorDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(firstRadio) {
|
||||||
|
if(cb.indexOf("disabled") < 0) {
|
||||||
|
firstRadio = false;
|
||||||
|
cb += "checked ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
cb += "named='" + annotations[i] + "' value='" + colors[i]
|
cb += "named='" + annotations[i] + "' value='" + colors[i]
|
||||||
+ "' id='color-" + i + "' class='filled-in'>";
|
+ "' id='color-" + i + "' class='filled-in'>";
|
||||||
cb += "<label for='color-" + i
|
cb += "<label for='color-" + i
|
||||||
+ "'><span style='font-weight:bold; color:#" + colors[i] + "'>"
|
+ "'><span style='font-weight:bold; color:#" + colors[i] + "'>"
|
||||||
+ annotations[i] + "</span></label><br>";
|
+ annotations[i] + "</span></label><br>";
|
||||||
$("#colored-annotations").append(cb);
|
$("#colored-annotations").append(cb);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#colored-annotations :radio").change(function() {
|
$("#colored-annotations :radio").change(function() {
|
||||||
if (this.checked) {
|
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 = "<p><input type='checkbox' name='foo-ner-algs' checked named='"
|
||||||
|
+ jsonContent.output.result[i].algorithm + "' id='algorithm" + i + "'>";
|
||||||
|
cb += "<label for='algorithm" + i + "'>" + findNameByAlgorithmId(jsonContent.output.result[i].algorithm) +"</label></p>";
|
||||||
|
$("#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 <p> containing the text highlighted on annotation value
|
* Write the html paragraph <p> containing the text highlighted on annotation value
|
||||||
*/
|
*/
|
||||||
rewriteText = function(annotation, color) {
|
rewriteText = function(color) {
|
||||||
$("#result-text-div").empty();
|
$("#result-text-div").empty();
|
||||||
|
|
||||||
var complemetar = 0xFFFFFF - eval("0x" + color.substring(1));
|
var complemetar = 0xFFFFFF - eval("0x" + color.substring(1));
|
||||||
|
@ -609,11 +732,13 @@ rewriteText = function(annotation, color) {
|
||||||
showProgress();
|
showProgress();
|
||||||
$(".hidden-div").show();
|
$(".hidden-div").show();
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
var indices = getIndices(annotation);
|
var indices = getIndices();
|
||||||
$(".hidden-div").hide();
|
$(".hidden-div").hide();
|
||||||
|
|
||||||
$("#result-header-right").empty();
|
$("#result-header-right").empty();
|
||||||
$("#result-header-right").append("<span style='color:" + color + ";'>" + annotation + "</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 = "";
|
var indexedText = "";
|
||||||
|
|
||||||
if ((typeof (indices) == 'undefined') || (indices.length == 0)) {
|
if ((typeof (indices) == 'undefined') || (indices.length == 0)) {
|
||||||
|
@ -644,7 +769,10 @@ rewriteText = function(annotation, color) {
|
||||||
|
|
||||||
indexedText = indexedText.replace(/\n/g, "<br>");
|
indexedText = indexedText.replace(/\n/g, "<br>");
|
||||||
$("#result-text-div").append("<p>" + indexedText + "</p>");
|
$("#result-text-div").append("<p>" + indexedText + "</p>");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#result-text-div").append("<p>" + resultText + "</p>");
|
||||||
|
}
|
||||||
}, 50);
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,13 +796,25 @@ checkAnnotation = function(annotation) {
|
||||||
/*
|
/*
|
||||||
* Retrieve the annotation indices from the json
|
* Retrieve the annotation indices from the json
|
||||||
*/
|
*/
|
||||||
getIndices = function(annotation) {
|
getIndices = function() {
|
||||||
var indices = [];
|
var indices = [];
|
||||||
// get indices
|
// get indices
|
||||||
for (var i = 0; i < jsonContent.output.result.length; i++) {
|
for (var i = 0; i < jsonContent.output.result.length; i++) {
|
||||||
|
// filter on algorithm
|
||||||
|
var found = false;
|
||||||
|
for(var j=0; j<checkedAlgs.length; j++) {
|
||||||
|
if(checkedAlgs[j] == jsonContent.output.result[i].algorithm) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found)
|
||||||
|
continue;
|
||||||
|
|
||||||
var entities = jsonContent.output.result[i].entities;
|
var entities = jsonContent.output.result[i].entities;
|
||||||
for (var j = 0; j < entities.length; j++) {
|
for (var j = 0; j < entities.length; j++) {
|
||||||
a = entities[j][annotation];
|
// filter on annotation
|
||||||
|
a = entities[j][checkedAnnotation];
|
||||||
if (typeof a != 'undefined') {
|
if (typeof a != 'undefined') {
|
||||||
indices[i] = [];
|
indices[i] = [];
|
||||||
for (var k = 0; k < a.length; k++) {
|
for (var k = 0; k < a.length; k++) {
|
||||||
|
@ -685,6 +825,9 @@ getIndices = function(annotation) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(indices.length == 0)
|
||||||
|
return indices;
|
||||||
|
|
||||||
var indices2 = [];
|
var indices2 = [];
|
||||||
for (var i = 0; i < indices.length; i++) {
|
for (var i = 0; i < indices.length; i++) {
|
||||||
if (typeof (indices[i]) != 'undefined')
|
if (typeof (indices[i]) != 'undefined')
|
||||||
|
@ -699,7 +842,6 @@ getIndices = function(annotation) {
|
||||||
*/
|
*/
|
||||||
mergeIndices = function(indices) {
|
mergeIndices = function(indices) {
|
||||||
var newIndices = [];
|
var newIndices = [];
|
||||||
//console.log("--mergeIndices: indices.length=" + indices.length);
|
|
||||||
if (indices.length == 1)
|
if (indices.length == 1)
|
||||||
newIndices = indices[0];
|
newIndices = indices[0];
|
||||||
else
|
else
|
||||||
|
@ -801,7 +943,16 @@ $(".ajax-file-upload-abort").on("DOMAttrModified", function(event) {
|
||||||
*/
|
*/
|
||||||
buildLanguageList = function() {
|
buildLanguageList = function() {
|
||||||
// build the language selection input control
|
// build the language selection input control
|
||||||
|
var defaultLanguage = null;
|
||||||
for (i in languages) {
|
for (i in languages) {
|
||||||
|
languages[i] = languages[i].trim();
|
||||||
|
languages[i] = languages[i].replace(/\w\S*/g,
|
||||||
|
function(txt) {
|
||||||
|
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
||||||
|
});
|
||||||
|
if(languages[i] == "English")
|
||||||
|
defaultLanguage = languages[i];
|
||||||
|
|
||||||
var opt = "<option value=\"" + languages[i]
|
var opt = "<option value=\"" + languages[i]
|
||||||
+ "\" selected=\"selected\">" + languages[i] + "</option>";
|
+ "\" selected=\"selected\">" + languages[i] + "</option>";
|
||||||
if (i > 1)
|
if (i > 1)
|
||||||
|
@ -809,9 +960,15 @@ buildLanguageList = function() {
|
||||||
+ "</option>";
|
+ "</option>";
|
||||||
$("#language-select").append(opt);
|
$("#language-select").append(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(defaultLanguage != null)
|
||||||
|
$("#language-select").val(defaultLanguage);
|
||||||
|
|
||||||
$("#language-select").on("change", function() {
|
$("#language-select").on("change", function() {
|
||||||
selectAnnotationsByLanguage();
|
selectAnnotationsByLanguage();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#language-select").change();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -73,7 +73,7 @@ mergeAll = function(indices) {
|
||||||
// [1] 'compareSegment'.
|
// [1] 'compareSegment'.
|
||||||
// when two segment are equals or included compareSegment returns 0
|
// when two segment are equals or included compareSegment returns 0
|
||||||
// when two segment are intersecting compareSegment returns -1
|
// 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'
|
// [2] 'mergeSegment'
|
||||||
// returns the "union" of two segments
|
// returns the "union" of two segments
|
||||||
|
|
Loading…
Reference in New Issue