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,
|
||||
response);
|
||||
commander.setSleepTime(100);
|
||||
commander.setMaxWaitingTime(90*1000);
|
||||
commander.startProcess();
|
||||
/*
|
||||
if (algs.length >= 1) {
|
||||
|
|
|
@ -79,27 +79,16 @@ 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<tokens.length; u++) {
|
||||
// System.out.println("[" + u + "] " + tokens[u]);
|
||||
// }
|
||||
try {
|
||||
String text = getDocument(documentLink);
|
||||
|
||||
|
||||
text = text.replaceAll("\n", "\\\\n");;
|
||||
text = text.replaceAll("\r", "\\\\r");
|
||||
text = text.replaceAll("\t", "\\\\t");
|
||||
text = text.replaceAll("\"", "\\\\\"");
|
||||
|
||||
// byte[] b = text.getBytes();
|
||||
// System.out.println(Constants.hexDump(b));
|
||||
|
||||
String out = "{";
|
||||
out += "\"text\":\"" + text + "\",";
|
||||
out += "\"annotations\":\"" + annotations + "\",";
|
||||
|
@ -109,11 +98,12 @@ public class NLPMapper extends HttpServlet {
|
|||
for (int i = 0; i < tokens.length; i++) {
|
||||
String token = tokens[i];
|
||||
String[] t = token.split(":::");
|
||||
//System.out.println(t[0]);
|
||||
//System.out.println(t[1]);
|
||||
if(t[1].equals(Constants.ERROR_ID)) {
|
||||
logger.error("Algorithm " + t[0] + " in error. Bypass...");
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
String json = ((JsonMapper) (getMapper(t[0]).newInstance())).getJson(t[0], t[1]);
|
||||
//System.out.println("" + json);
|
||||
out += json;
|
||||
if (i < tokens.length - 1)
|
||||
out += ",";
|
||||
|
@ -123,7 +113,6 @@ public class NLPMapper extends HttpServlet {
|
|||
}
|
||||
out += "]}";
|
||||
|
||||
|
||||
String resultLink = saveResult(out);
|
||||
String outResult = "{";
|
||||
outResult += "\"link\":\"" + resultLink + "\",";
|
||||
|
@ -172,6 +161,8 @@ public class NLPMapper extends HttpServlet {
|
|||
}
|
||||
|
||||
String link = ws.getPublicLink(fileName, token);
|
||||
|
||||
logger.info("Output json [" + fileName + "] created in " + (System.currentTimeMillis() - now) + " millisec.");
|
||||
return link;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@ package org.gcube.nlphub.legacy;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
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 TOKEN_PARAMETER = "gcube-token";
|
||||
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 {
|
||||
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 += "&lang=en-US";
|
||||
urlService += "&Identifier=" + RECOGNIZER_ID;
|
||||
|
|
|
@ -20,8 +20,8 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
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_DESCRIBE_PROCESS_URL = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService?request=DescribeProcess&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 = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=DescribeProcess&service=WPS&Version=1.0.0";
|
||||
private String identifier, token, httpMethod, annotations, publicLink, language;
|
||||
private Logger logger = Logger.getLogger(NlpAsyncNerRunner.class.getSimpleName());
|
||||
|
||||
|
@ -38,7 +38,6 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
|||
serviceUrl += "&" + setUrl(params);
|
||||
super.setBaseUrl(serviceUrl);
|
||||
super.setMethod(httpMethod);
|
||||
//System.out.println(serviceUrl);
|
||||
}
|
||||
|
||||
public NlpAsyncNerRunner(String baseUrl, String method) {
|
||||
|
|
|
@ -103,7 +103,7 @@ pre {
|
|||
float: left;
|
||||
margin: 10px;
|
||||
color: white;
|
||||
background-color: #4CAF50 !important;
|
||||
background-color: #4CAF50; /*!important;*/
|
||||
padding: 0.6rem;
|
||||
text-transform: uppercase;
|
||||
vertical-align: middle;
|
||||
|
@ -189,6 +189,7 @@ pre {
|
|||
#logo-image {
|
||||
width: 200px;
|
||||
height: auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ajax-file-upload-container {
|
||||
|
@ -239,6 +240,12 @@ select {
|
|||
border: 1px solid silver;
|
||||
height: 60vh;
|
||||
margin: 2px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#ner-result-accordion {
|
||||
height: 60vh;
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
.left-side-half {
|
||||
|
@ -280,6 +287,10 @@ select {
|
|||
}
|
||||
}
|
||||
|
||||
#algorithm-param_div {
|
||||
font-size: 12px !important;
|
||||
}
|
||||
|
||||
#result-text-div {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
@ -288,6 +299,16 @@ select {
|
|||
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){
|
||||
position: unset !important;
|
||||
|
@ -306,6 +327,11 @@ input[type="checkbox"]:checked {
|
|||
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){
|
||||
position: unset !important;
|
||||
|
|
|
@ -65,8 +65,6 @@
|
|||
</div>
|
||||
<div class="column margin-left-10px">
|
||||
<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"
|
||||
id="upload-button">Upload text file</div>
|
||||
</div>
|
||||
|
@ -101,7 +99,18 @@
|
|||
</div>
|
||||
<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 class="green-button float-right-div" id="back-ner-ui-button">back</div>
|
||||
</div>
|
||||
|
|
|
@ -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(
|
||||
"<div id=\"reset-upload\" class=\"centered\">Cancel</div>");
|
||||
$("#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();
|
||||
});
|
||||
|
@ -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("<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 color;
|
||||
var colors = [];
|
||||
|
@ -542,24 +596,93 @@ showAnnotationList = function(list) {
|
|||
}
|
||||
|
||||
$("#result-params-div").append("<form id='colored-annotations'></form>");
|
||||
|
||||
var firstRadio = true;
|
||||
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])) {
|
||||
cb += "disabled ";
|
||||
colors[i] = colorDisabled;
|
||||
}
|
||||
|
||||
if(firstRadio) {
|
||||
if(cb.indexOf("disabled") < 0) {
|
||||
firstRadio = false;
|
||||
cb += "checked ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
$("#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 = "<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
|
||||
*/
|
||||
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("<span style='color:" + color + ";'>" + annotation + "</span> occurs " + indices.length + " times.");
|
||||
var indexedText = "";
|
||||
$("#result-header-right").append("<span style='color:" + color + ";'>" + checkedAnnotation + "</span> occurs " + indices.length + " times.");
|
||||
|
||||
if(indices.length != 0) {
|
||||
var indexedText = "";
|
||||
|
||||
if ((typeof (indices) == 'undefined') || (indices.length == 0)) {
|
||||
indexedText = resultText;
|
||||
indexedText = indexedText.replace(/\n/g, "<br>");
|
||||
indexedText = indexedText.replace(/</g, "<");
|
||||
indexedText = indexedText.replace(/>/g, ">");
|
||||
$("#result-text-div").append("<p>" + indexedText + "</p>");
|
||||
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 = "<span style='color:" + color + "; background:"
|
||||
+ complement + "; font-weight:bold;'>"
|
||||
+ resultText.substring(start, end) + "</span>";
|
||||
indexedText += colored;
|
||||
t = end;
|
||||
}
|
||||
if (t < resultText.length)
|
||||
indexedText += resultText.substring(t);
|
||||
|
||||
if ((typeof (indices) == 'undefined') || (indices.length == 0)) {
|
||||
indexedText = resultText;
|
||||
indexedText = indexedText.replace(/\n/g, "<br>");
|
||||
indexedText = indexedText.replace(/</g, "<");
|
||||
indexedText = indexedText.replace(/>/g, ">");
|
||||
$("#result-text-div").append("<p>" + indexedText + "</p>");
|
||||
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 = "<span style='color:" + color + "; background:"
|
||||
+ complement + "; font-weight:bold;'>"
|
||||
+ resultText.substring(start, end) + "</span>";
|
||||
indexedText += colored;
|
||||
t = end;
|
||||
else {
|
||||
$("#result-text-div").append("<p>" + resultText + "</p>");
|
||||
}
|
||||
if (t < resultText.length)
|
||||
indexedText += resultText.substring(t);
|
||||
|
||||
indexedText = indexedText.replace(/\n/g, "<br>");
|
||||
$("#result-text-div").append("<p>" + indexedText + "</p>");
|
||||
|
||||
}, 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<checkedAlgs.length; j++) {
|
||||
if(checkedAlgs[j] == jsonContent.output.result[i].algorithm) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
continue;
|
||||
|
||||
var entities = jsonContent.output.result[i].entities;
|
||||
for (var j = 0; j < entities.length; j++) {
|
||||
a = entities[j][annotation];
|
||||
// filter on annotation
|
||||
a = entities[j][checkedAnnotation];
|
||||
if (typeof a != 'undefined') {
|
||||
indices[i] = [];
|
||||
for (var k = 0; k < a.length; k++) {
|
||||
|
@ -685,6 +825,9 @@ getIndices = function(annotation) {
|
|||
}
|
||||
}
|
||||
|
||||
if(indices.length == 0)
|
||||
return indices;
|
||||
|
||||
var indices2 = [];
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
if (typeof (indices[i]) != 'undefined')
|
||||
|
@ -699,7 +842,6 @@ getIndices = function(annotation) {
|
|||
*/
|
||||
mergeIndices = function(indices) {
|
||||
var newIndices = [];
|
||||
//console.log("--mergeIndices: indices.length=" + indices.length);
|
||||
if (indices.length == 1)
|
||||
newIndices = indices[0];
|
||||
else
|
||||
|
@ -801,7 +943,16 @@ $(".ajax-file-upload-abort").on("DOMAttrModified", function(event) {
|
|||
*/
|
||||
buildLanguageList = function() {
|
||||
// build the language selection input control
|
||||
var defaultLanguage = null;
|
||||
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]
|
||||
+ "\" selected=\"selected\">" + languages[i] + "</option>";
|
||||
if (i > 1)
|
||||
|
@ -809,9 +960,15 @@ buildLanguageList = function() {
|
|||
+ "</option>";
|
||||
$("#language-select").append(opt);
|
||||
}
|
||||
|
||||
if(defaultLanguage != null)
|
||||
$("#language-select").val(defaultLanguage);
|
||||
|
||||
$("#language-select").on("change", function() {
|
||||
selectAnnotationsByLanguage();
|
||||
});
|
||||
|
||||
$("#language-select").change();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue