2018-02-20 08:39:31 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<!-- input=http%3A%2F%2Fws1-clarind.esc.rzg.mpg.de%2Fdrop-off%2Fstorage%2F1513257926038.txt&lang=en&analysis=const-parsing -->
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
|
|
<title>NLPHub v1.2</title>
|
|
|
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
|
|
|
rel="stylesheet" />
|
|
|
|
<!--Import materialize.css-->
|
|
|
|
<link type="text/css" rel="stylesheet" href="css/materialize.min.css"
|
|
|
|
media="screen,projection" />
|
|
|
|
<link type="text/css" rel="stylesheet" href="css/custom.css" />
|
|
|
|
<!-- jQuery library -->
|
|
|
|
<script
|
|
|
|
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
|
|
|
<script type="text/javascript" src="js/materialize.min.js"></script>
|
|
|
|
<script type="text/javascript" src="js/jquery.simple.websocket.min.js"></script>
|
|
|
|
<script type="text/javascript" src="js/jquery.uploadfile.min.js"></script>
|
2018-02-28 15:02:01 +01:00
|
|
|
<script type="text/javascript" src="js/merge.js"></script>
|
2018-02-20 08:39:31 +01:00
|
|
|
<!-- <script type="text/javascript" src="js/main.js"></script> -->
|
|
|
|
<!-- scripting code -->
|
|
|
|
<script type="text/javascript">
|
|
|
|
var tableRawSize = 5;
|
|
|
|
var annotations = [];
|
|
|
|
var algorithms = [];
|
|
|
|
var languages = [];
|
|
|
|
var publicLink = null;
|
|
|
|
var pageGreen = "#4CAF50";
|
|
|
|
var pageGray = "#A0A0A0";
|
2018-02-20 16:41:48 +01:00
|
|
|
var savedAnnotations = "";
|
2018-02-22 17:47:59 +01:00
|
|
|
var jsonContent = null;
|
|
|
|
var named = null;
|
2018-02-26 15:39:10 +01:00
|
|
|
var resultText = "";
|
2018-02-20 08:39:31 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
// Starting point: get the csv file with algorithm parameters and set the page with valid algs info.
|
|
|
|
// ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
$
|
|
|
|
.ajax({
|
2018-03-02 14:48:35 +01:00
|
|
|
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
|
2018-02-20 08:39:31 +01:00
|
|
|
type : "GET",
|
|
|
|
async : true,
|
|
|
|
contentType : "text/plain; charset=utf-8",
|
|
|
|
success : function(data, stato) {
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#ner-result-container").hide();
|
2018-02-20 08:39:31 +01:00
|
|
|
var lineTokens = manageCsvData(data);
|
|
|
|
getAlgorithms(lineTokens);
|
|
|
|
buildAnnotationsAndLanguages();
|
|
|
|
resizeTable();
|
|
|
|
resizeLogo();
|
|
|
|
buildLanguageList();
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#back-ner-ui-button").click(function() {
|
|
|
|
$("#ner-result-container").hide();
|
|
|
|
$("#ner-ui").show();
|
2018-02-26 15:39:10 +01:00
|
|
|
$("#input-textarea").val("");
|
|
|
|
publicLink = null;
|
|
|
|
jsonContent = null;
|
2018-02-22 17:47:59 +01:00
|
|
|
});
|
|
|
|
|
2018-02-21 14:05:45 +01:00
|
|
|
$("#execute-button").css("background-color", pageGray);
|
|
|
|
|
|
|
|
$("#upload-button")
|
|
|
|
.uploadFile(
|
|
|
|
{
|
|
|
|
url : "/nlphub/nlphub-uploader-servlet",
|
|
|
|
fileName : "mytxtfile",
|
|
|
|
maxFileCount : 100,
|
|
|
|
multiple : false,
|
|
|
|
maxFileSize : 1024 * 1000 * 6.14,
|
|
|
|
showFileCounter : false,
|
|
|
|
showCancel : true,
|
|
|
|
dragDropStr : "<img class='img-prompt' src='img/upload.png' width='60px' height='60px' style='display:block; margin:auto; padding: 10px'>",
|
|
|
|
extErrorStr : "Error. Text file only",
|
|
|
|
sizeErrorStr : "Error. Max size: 6 Mb",
|
|
|
|
onLoad : function(obj) {
|
|
|
|
$("#file-info").remove();
|
|
|
|
$("#reset-upload").remove();
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#fu-container")
|
|
|
|
.append(
|
|
|
|
"<div id=\"right-child\" class=\"float-right-div\"></div>");
|
|
|
|
$("#right-child")
|
|
|
|
.append(
|
|
|
|
"<div id=\"file-info\" class=\"centered\"></div>");
|
|
|
|
$("#right-child")
|
|
|
|
.append(
|
|
|
|
"<div id=\"reset-upload\" class=\"centered\">Cancel</div>");
|
2018-02-21 14:05:45 +01:00
|
|
|
$("#reset-upload").hide();
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#reset-upload")
|
|
|
|
.click(
|
|
|
|
function() {
|
|
|
|
resetExecuteButton();
|
|
|
|
$("#file-info")
|
|
|
|
.empty();
|
|
|
|
$(
|
|
|
|
"#reset-upload")
|
|
|
|
.css(
|
|
|
|
"display",
|
|
|
|
"none");
|
|
|
|
textAreaEnable(true);
|
|
|
|
});
|
2018-02-21 14:05:45 +01:00
|
|
|
savedAnnotations = "";
|
|
|
|
setEventListeners();
|
|
|
|
},
|
|
|
|
onSelect : function(files) {
|
|
|
|
showProgress();
|
|
|
|
textAreaEnable(false);
|
2018-02-26 15:39:10 +01:00
|
|
|
$("#input-textarea").val("");
|
2018-02-21 14:05:45 +01:00
|
|
|
},
|
|
|
|
onSuccess : function(files, data, xhr) {
|
|
|
|
hideProgress();
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#reset-upload").css("display",
|
|
|
|
"inline");
|
2018-02-21 14:05:45 +01:00
|
|
|
console.log("files: " + files);
|
|
|
|
$("#file-info").empty();
|
|
|
|
$("#file-info")
|
|
|
|
.append(
|
|
|
|
"Uploaded: <span style=\"color:#4CAF50; letter-spacing: 1px; font-weight: bold;\">"
|
|
|
|
+ files
|
|
|
|
+ "</span>");
|
|
|
|
publicLink = data.message;
|
|
|
|
$("#execute-button").css(
|
|
|
|
"background-color",
|
|
|
|
pageGreen);
|
|
|
|
if (publicLink == null) {
|
|
|
|
alert("Error uploading file.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onError : function(files, status,
|
|
|
|
errMsg, pd) {
|
|
|
|
hideProgress();
|
|
|
|
textAreaEnable(true);
|
|
|
|
alert(errMsg);
|
|
|
|
}
|
|
|
|
});
|
2018-02-20 08:39:31 +01:00
|
|
|
},
|
|
|
|
error : function(richiesta, stato, errori) {
|
2018-02-26 15:39:10 +01:00
|
|
|
alert("Unexpected Error. Status: " + richiesta.status);
|
2018-02-20 08:39:31 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
manageCsvData = function(data) {
|
|
|
|
// first of all: split on the "newline" character in order to
|
|
|
|
// get all lines.
|
|
|
|
var lines = data.split("\n");
|
|
|
|
var tokens = [], lineTokens = [];
|
|
|
|
|
|
|
|
// second: parse each line
|
|
|
|
for (i in lines) {
|
|
|
|
var line = ',' + lines[i];
|
|
|
|
var tokenStart = -1;
|
|
|
|
for (var j = 0; j < line.length; j++) {
|
|
|
|
if (line.charAt(j) == '\"') {
|
|
|
|
j = line.indexOf('\"', j + 1);
|
|
|
|
if (j < 0)
|
|
|
|
return;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line.charAt(j) == ',') {
|
|
|
|
if (tokenStart == -1) {
|
|
|
|
tokenStart = j;
|
|
|
|
} else {
|
|
|
|
tokens[tokens.length] = line.substring(tokenStart + 1,
|
|
|
|
j);
|
|
|
|
tokenStart = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// get the new token and push it in the array
|
|
|
|
tokens[tokens.length] = line.substring(tokenStart + 1);
|
|
|
|
lineTokens[lineTokens.length] = tokens;
|
|
|
|
tokens = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return lineTokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAlgorithms = function(lineTokens) {
|
|
|
|
// build the list of supported algorithms
|
|
|
|
for (i = 0; i < lineTokens.length; i++) {
|
|
|
|
if ((i == 0) || (lineTokens[i].length != 8))
|
|
|
|
continue; // skip the header
|
|
|
|
if (lineTokens[i][7].trim().toUpperCase() == "OK") {
|
|
|
|
var algName = lineTokens[i][0].trim();
|
|
|
|
var algDescription = lineTokens[i][1].trim();
|
|
|
|
var algId = lineTokens[i][2].trim();
|
|
|
|
var annotationList = lineTokens[i][3].replace(/"/g, " ").trim();
|
|
|
|
var language = lineTokens[i][4].replace(/"/g, " ").trim();
|
|
|
|
|
|
|
|
algorithms[algorithms.length] = {
|
|
|
|
"name" : algName,
|
|
|
|
"description" : algDescription,
|
|
|
|
"id" : algId,
|
|
|
|
"lang" : language,
|
|
|
|
"annotations" : annotationList
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buildAnnotationsAndLanguages = function() {
|
|
|
|
// extract data about languages and annotations in order to populate the proper
|
|
|
|
// controls in the page
|
|
|
|
for (i in algorithms) {
|
|
|
|
var annotationList = algorithms[i].annotations;
|
|
|
|
var a = annotationList.split(/\s|,/);
|
|
|
|
for (j in a) {
|
|
|
|
a[j] = a[j].trim();
|
|
|
|
if (a[j].length > 0) {
|
|
|
|
var thereIs = false;
|
|
|
|
for (k in annotations) {
|
2018-02-28 15:02:01 +01:00
|
|
|
if (annotations[k].toUpperCase() == a[j].toUpperCase()) {
|
2018-02-20 08:39:31 +01:00
|
|
|
thereIs = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!thereIs)
|
|
|
|
annotations[annotations.length] = a[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var languageList = algorithms[i].lang;
|
|
|
|
var langs = languageList.split(/\s|,/);
|
|
|
|
for (j in langs) {
|
|
|
|
langs[j] = langs[j].trim();
|
|
|
|
if (langs[j].length > 0) {
|
|
|
|
var thereIs = false;
|
|
|
|
for (k in languages) {
|
2018-02-28 15:02:01 +01:00
|
|
|
if (languages[k].toUpperCase() == langs[j].toUpperCase()) {
|
2018-02-20 08:39:31 +01:00
|
|
|
thereIs = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!thereIs)
|
|
|
|
languages[languages.length] = langs[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
|
2018-02-20 08:39:31 +01:00
|
|
|
setEventListeners = function() {
|
|
|
|
$("#input-textarea").on("keyup", function() {
|
2018-02-21 14:05:45 +01:00
|
|
|
if ($("#input-textarea").val() == "")
|
|
|
|
$("#execute-button").css("background-color", pageGray);
|
|
|
|
else
|
|
|
|
$("#execute-button").css("background-color", pageGreen);
|
2018-02-20 08:39:31 +01:00
|
|
|
});
|
|
|
|
|
2018-02-21 14:05:45 +01:00
|
|
|
$("#execute-button")
|
|
|
|
.click(
|
|
|
|
function() {
|
|
|
|
if ((publicLink == null)
|
|
|
|
&& ($("#input-textarea").val() == "")) {
|
|
|
|
alert("You must upload a file or write some text in the text area before submit a request.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
showProgress();
|
|
|
|
// if some text has been written in the text area, then a corresponding text file
|
|
|
|
// must be written in the workspace and the public link is set.
|
|
|
|
if ($("#input-textarea").val().length > 0) {
|
|
|
|
freeText = $("#input-textarea").val();
|
|
|
|
$
|
|
|
|
.ajax({
|
|
|
|
url : "/nlphub/nlphub-uploader-servlet?freetext="
|
|
|
|
+ encodeURI(freeText),
|
|
|
|
type : "POST",
|
|
|
|
async : true,
|
|
|
|
contentType : "text/plain; charset=utf-8",
|
|
|
|
success : function(data, stato) {
|
|
|
|
publicLink = data.message;
|
|
|
|
if (publicLink == null) {
|
|
|
|
alert("Error uploading file.");
|
|
|
|
}
|
|
|
|
launchAlgorithm();
|
|
|
|
},
|
|
|
|
error : function(richiesta, stato,
|
|
|
|
errori) {
|
2018-02-26 15:39:10 +01:00
|
|
|
alert("Unexpected Error. Status: "
|
|
|
|
+ richiesta.status);
|
2018-02-21 14:05:45 +01:00
|
|
|
hideProgress();
|
|
|
|
textAreaEnable(true);
|
|
|
|
$("#file-info").empty();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
launchAlgorithm();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showProgress = function() {
|
|
|
|
var width = $(".progress-circular-div").width();
|
|
|
|
var height = $(".progress-circular-div").height();
|
2018-02-22 17:47:59 +01:00
|
|
|
var left = parseInt((window.innerWidth - width) / 2);
|
|
|
|
var top = parseInt((window.innerHeight - height) / 2);
|
2018-02-21 14:05:45 +01:00
|
|
|
$(".progress-circular-div").css("left", left);
|
|
|
|
$(".progress-circular-div").css("top", top);
|
|
|
|
$(".hidden-div").css("display", "block");
|
|
|
|
}
|
2018-02-22 17:47:59 +01:00
|
|
|
|
2018-02-21 14:05:45 +01:00
|
|
|
hideProgress = function() {
|
2018-02-22 17:47:59 +01:00
|
|
|
$(".hidden-div").css("display", "none");
|
2018-02-20 08:39:31 +01:00
|
|
|
}
|
2018-02-22 17:47:59 +01:00
|
|
|
|
2018-02-20 08:39:31 +01:00
|
|
|
launchAlgorithm = function() {
|
2018-02-21 14:05:45 +01:00
|
|
|
if (publicLink == null) {
|
2018-02-20 08:39:31 +01:00
|
|
|
alert("No input text available for the service.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var list = buildInputAnnotationList();
|
|
|
|
var annList = "";
|
2018-02-21 14:05:45 +01:00
|
|
|
for (i in list) {
|
2018-02-20 08:39:31 +01:00
|
|
|
annList += list[i] + ",";
|
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
annList = annList.substring(0, annList.length - 1);
|
2018-02-20 16:41:48 +01:00
|
|
|
savedAnnotations = annList;
|
2018-02-21 14:05:45 +01:00
|
|
|
|
2018-02-20 08:39:31 +01:00
|
|
|
var algList = "";
|
2018-02-21 14:05:45 +01:00
|
|
|
for (j in algorithms) {
|
2018-02-20 08:39:31 +01:00
|
|
|
algList += encodeURI(algorithms[j].id) + ",";
|
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
algList = algList.substring(0, algList.length - 1);
|
|
|
|
|
|
|
|
var parameters = "annotations=" + annList;
|
2018-02-20 08:39:31 +01:00
|
|
|
parameters += "&lang=" + $("#language-select").val();
|
|
|
|
parameters += "&plink=" + encodeURI(publicLink);
|
|
|
|
parameters += "&algs=" + algList;
|
2018-02-21 14:05:45 +01:00
|
|
|
|
|
|
|
$.ajax({
|
2018-02-20 08:39:31 +01:00
|
|
|
url : "/nlphub/nlphub-servlet?" + parameters,
|
|
|
|
type : "POST",
|
|
|
|
async : true,
|
|
|
|
success : function(data, stato) {
|
2018-03-06 14:26:22 +01:00
|
|
|
//hideProgress();
|
2018-02-21 14:05:45 +01:00
|
|
|
textAreaEnable(true);
|
|
|
|
$("#file-info").empty();
|
|
|
|
if (typeof (data.response) != 'undefined') {
|
2018-02-20 16:41:48 +01:00
|
|
|
var jsonOut = getOutputJson(data.message);
|
2018-02-21 14:05:45 +01:00
|
|
|
} else if (typeof (data.error) != 'undefined') {
|
2018-02-20 08:39:31 +01:00
|
|
|
alert(data.message);
|
2018-02-22 17:47:59 +01:00
|
|
|
} else {
|
2018-02-20 08:39:31 +01:00
|
|
|
alert("Unexpected response");
|
2018-02-21 14:05:45 +01:00
|
|
|
}
|
|
|
|
resetExecuteButton();
|
2018-02-20 08:39:31 +01:00
|
|
|
},
|
|
|
|
error : function(richiesta, stato, errori) {
|
2018-02-21 14:05:45 +01:00
|
|
|
hideProgress();
|
|
|
|
textAreaEnable(true);
|
2018-02-26 15:39:10 +01:00
|
|
|
alert("Unexpected Error. Status: " + richiesta.status);
|
2018-02-21 14:05:45 +01:00
|
|
|
resetExecuteButton();
|
2018-02-20 08:39:31 +01:00
|
|
|
}
|
|
|
|
});
|
2018-02-20 16:41:48 +01:00
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
|
2018-02-20 16:41:48 +01:00
|
|
|
getOutputJson = function(message) {
|
|
|
|
var tobemap = "";
|
2018-02-21 14:05:45 +01:00
|
|
|
for (var i = 0; i < message.length; i++) {
|
2018-02-20 16:41:48 +01:00
|
|
|
tobemap += message[i] + "|";
|
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
|
|
|
|
tobemap = tobemap.substring(0, tobemap.length - 1);
|
|
|
|
|
|
|
|
var parameters = "annotations=" + savedAnnotations;
|
2018-02-20 16:41:48 +01:00
|
|
|
parameters += "&plink=" + encodeURI(publicLink);
|
|
|
|
parameters += "&lang=" + $("#language-select").val();
|
|
|
|
parameters += "&tobemap=" + encodeURI(tobemap);
|
2018-02-28 15:02:01 +01:00
|
|
|
console.log(parameters);
|
2018-02-21 14:05:45 +01:00
|
|
|
|
|
|
|
$.ajax({
|
2018-02-20 16:41:48 +01:00
|
|
|
url : "/nlphub/nlphub-mapper-servlet?" + parameters,
|
|
|
|
type : "POST",
|
|
|
|
async : true,
|
|
|
|
success : function(data, stato) {
|
2018-03-06 14:26:22 +01:00
|
|
|
hideProgress();
|
2018-02-20 16:41:48 +01:00
|
|
|
console.log(data);
|
2018-02-28 15:02:01 +01:00
|
|
|
if((typeof (data.response) != "undefined") && (data.response.trim().toUpperCase() == "ERROR")) {
|
|
|
|
alert ("ERROR\n" + data.message);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#reset-upload").hide();
|
|
|
|
savedAnnotations = "";
|
|
|
|
publicLink = null;
|
|
|
|
showResult(data);
|
|
|
|
}
|
2018-02-20 16:41:48 +01:00
|
|
|
},
|
|
|
|
error : function(richiesta, stato, errori) {
|
2018-03-06 14:26:22 +01:00
|
|
|
hideProgress();
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#reset-upload").hide();
|
|
|
|
savedAnnotations = "";
|
|
|
|
publicLink = null;
|
2018-02-26 15:39:10 +01:00
|
|
|
alert("Unexpected Error. Status: " + richiesta.status);
|
2018-02-20 16:41:48 +01:00
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
});
|
2018-02-22 17:47:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
showResult = function(data) {
|
|
|
|
$("#ner-ui").hide();
|
|
|
|
$("#ner-result-container").show();
|
|
|
|
|
2018-02-26 15:39:10 +01:00
|
|
|
jsonContent = data;
|
|
|
|
//jsonContent = JSON.parse(purgeJson(data));
|
|
|
|
|
|
|
|
//resultText = jsonToText(jsonContent.output.text);
|
|
|
|
resultText = jsonContent.output.text;
|
2018-02-22 17:47:59 +01:00
|
|
|
|
|
|
|
$("#result-header").empty();
|
|
|
|
$("#result-params-div").empty();
|
|
|
|
$("#result-text-div").empty();
|
|
|
|
|
|
|
|
$("#result-header")
|
|
|
|
.append(
|
2018-03-06 14:26:22 +01:00
|
|
|
"<p>You can download the overall result as a JSON file <a href='" + jsonContent.link +"'>here</a></p>");
|
2018-02-26 15:39:10 +01:00
|
|
|
var localText = resultText;
|
|
|
|
localText = resultText.replace(/\n/g, "<br>");
|
|
|
|
$("#result-text-div").empty();
|
|
|
|
$("#result-text-div").append("<p>" + localText + "</p>");
|
2018-02-22 17:47:59 +01:00
|
|
|
|
|
|
|
showAnnotationList(jsonContent.output.annotations);
|
|
|
|
}
|
|
|
|
|
|
|
|
showAnnotationList = function(list) {
|
2018-02-26 15:39:10 +01:00
|
|
|
var colors = [];
|
2018-02-22 17:47:59 +01:00
|
|
|
var annotations = list.split(",");
|
2018-02-26 15:39:10 +01:00
|
|
|
for (var i = 0; i < annotations.length; i++) {
|
2018-02-22 17:47:59 +01:00
|
|
|
colors[colors.length] = randomRGB();
|
|
|
|
}
|
2018-02-26 15:39:10 +01:00
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#result-params-div")
|
|
|
|
.append("<form id='colored-annotations'></form>");
|
|
|
|
for (var i = 0; i < annotations.length; i++) {
|
2018-03-06 14:26:22 +01:00
|
|
|
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'>";
|
2018-02-26 15:39:10 +01:00
|
|
|
cb += "<label for='color-" + i + "'><span style='font-weight:bold; color:#" + colors[i] + "'>"
|
2018-02-22 17:47:59 +01:00
|
|
|
+ annotations[i] + "</span></label><br>";
|
|
|
|
$("#colored-annotations").append(cb);
|
|
|
|
}
|
|
|
|
$("#colored-annotations :radio").change(function() {
|
|
|
|
if (this.checked) {
|
|
|
|
rewriteText(this.getAttribute("named"), "#" + this.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
|
2018-02-26 15:39:10 +01:00
|
|
|
countSubstringOccurrencies = function(string, substring) {
|
|
|
|
var occurrencies = 0;
|
|
|
|
var index = 0;
|
|
|
|
var s = string;
|
|
|
|
while(index >= 0) {
|
|
|
|
index = s.indexOf(substring);
|
|
|
|
if(index >= 0) {
|
|
|
|
occurrencies++;
|
|
|
|
s = s.substring(index + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return occurrencies;
|
|
|
|
}
|
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
rewriteText = function(annotation, color) {
|
2018-02-26 15:39:10 +01:00
|
|
|
$("#result-text-div").empty();
|
2018-02-22 17:47:59 +01:00
|
|
|
console.log(annotation + " " + color);
|
2018-02-26 15:39:10 +01:00
|
|
|
var complement = "#"
|
|
|
|
+ (0xFFFFFF - eval("0x" + color.substring(1))).toString(16);
|
|
|
|
complement = "#F0F0F0";
|
2018-02-22 17:47:59 +01:00
|
|
|
var indices = getIndices(annotation);
|
|
|
|
var indexedText = "";
|
|
|
|
|
2018-02-28 15:02:01 +01:00
|
|
|
if ((typeof (indices) == 'undefined' ) || (indices.length == 0)) {
|
2018-02-26 15:39:10 +01:00
|
|
|
indexedText = resultText;
|
|
|
|
indexedText = indexedText.replace(/\n/g, "<br>");
|
|
|
|
$("#result-text-div").append("<p>" + indexedText + "</p>");
|
2018-02-22 17:47:59 +01:00
|
|
|
return;
|
2018-02-26 15:39:10 +01:00
|
|
|
}
|
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
var t = 0;
|
2018-02-26 15:39:10 +01:00
|
|
|
var offset = 0;
|
2018-02-22 17:47:59 +01:00
|
|
|
for (var i = 0; i < indices.length; i++) {
|
|
|
|
var index = indices[i];
|
|
|
|
var start = index[0];
|
|
|
|
var end = index[1];
|
2018-02-26 15:39:10 +01:00
|
|
|
indexedText += resultText.substring(t, start);
|
|
|
|
offset += countSubstringOccurrencies(resultText.substring(t, start), "\n");
|
|
|
|
offset += countSubstringOccurrencies(resultText.substring(t, start), "\r");
|
|
|
|
offset += countSubstringOccurrencies(resultText.substring(t, start), "\t");
|
|
|
|
start += offset;
|
|
|
|
end += offset;
|
2018-02-22 17:47:59 +01:00
|
|
|
var colored = "<span style='color:" + color + "; background:" + complement + "; font-weight:bold;'>"
|
2018-02-26 15:39:10 +01:00
|
|
|
+ resultText.substring(start, end) + "</span>";
|
2018-02-22 17:47:59 +01:00
|
|
|
indexedText += colored;
|
|
|
|
t = end;
|
|
|
|
}
|
2018-02-26 15:39:10 +01:00
|
|
|
if (t < resultText.length)
|
|
|
|
indexedText += resultText.substring(t);
|
|
|
|
|
|
|
|
indexedText = indexedText.replace(/\n/g, "<br>");
|
2018-02-22 17:47:59 +01:00
|
|
|
$("#result-text-div").append("<p>" + indexedText + "</p>");
|
|
|
|
}
|
|
|
|
|
2018-03-06 14:26:22 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
getIndices = function(annotation) {
|
|
|
|
var indices = [];
|
|
|
|
// get indices
|
|
|
|
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') {
|
|
|
|
indices[i] = [];
|
|
|
|
for (var k = 0; k < a.length; k++) {
|
|
|
|
var index = a[k].indices;
|
|
|
|
indices[i][k] = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 16:02:08 +01:00
|
|
|
var indices2 = [];
|
|
|
|
for(var i=0; i<indices.length; i++) {
|
|
|
|
if(typeof (indices[i]) != 'undefined')
|
|
|
|
indices2[indices2.length] = indices[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return mergeIndices(indices2);
|
2018-02-22 17:47:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mergeIndices = function(indices) {
|
|
|
|
// GESTIONE MULTIDIMENSIONALE DA FARE !!!!
|
|
|
|
var newIndices = []
|
2018-02-28 15:02:01 +01:00
|
|
|
if (indices.length <= 1)
|
2018-02-22 17:47:59 +01:00
|
|
|
newIndices = indices[0];
|
2018-02-28 15:02:01 +01:00
|
|
|
else
|
|
|
|
newIndices = mergeAll(indices);
|
2018-02-22 17:47:59 +01:00
|
|
|
return newIndices;
|
2018-02-20 08:39:31 +01:00
|
|
|
}
|
2018-02-22 17:47:59 +01:00
|
|
|
|
2018-02-21 14:05:45 +01:00
|
|
|
resetExecuteButton = function() {
|
|
|
|
publicLink = null;
|
|
|
|
$("#execute-button").css("background-color", pageGray);
|
|
|
|
}
|
2018-02-20 08:39:31 +01:00
|
|
|
|
|
|
|
resizeTable = function() {
|
|
|
|
// resize the annotation table
|
|
|
|
$("#annotations-table").empty();
|
|
|
|
var rowId = "";
|
|
|
|
var ratio = window.innerWidth / window.innerHeight;
|
|
|
|
|
|
|
|
if (ratio <= 0.35) {
|
|
|
|
tableRawSize = 1;
|
|
|
|
} else if ((ratio > 0.35) && (ratio <= 0.75)) {
|
|
|
|
tableRawSize = 2;
|
|
|
|
} else if ((ratio > 0.75) && (ratio <= 1)) {
|
|
|
|
tableRawSize = 3;
|
|
|
|
} else if ((ratio > 1) && (ratio <= 1.5)) {
|
|
|
|
tableRawSize = 4;
|
|
|
|
} else {
|
|
|
|
tableRawSize = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < annotations.length; i++) {
|
|
|
|
if (i % tableRawSize == 0) {
|
|
|
|
rowId = "row-" + i;
|
|
|
|
$("#annotations-table").append("<tr id=\"" + rowId +"\"></tr>");
|
|
|
|
}
|
|
|
|
var annotationElement = "<input type=\"checkbox\" id=\"check-" + i + "\" value=\"" + annotations[i] + "\" checked=\"checked\"></input> <label for=\"check-" + i + "\">"
|
|
|
|
+ annotations[i] + "</label>";
|
|
|
|
$("#" + rowId).append("<td>" + annotationElement + "</td>");
|
|
|
|
}
|
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
|
2018-02-20 08:39:31 +01:00
|
|
|
resizeLogo = function() {
|
2018-02-21 14:05:45 +01:00
|
|
|
if (window.innerWidth < 200)
|
|
|
|
$("#logo-image").width(window.innerWidth - 10);
|
2018-02-20 08:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
buildInputAnnotationList = function() {
|
|
|
|
var list = [];
|
|
|
|
for (var i = 0; i < annotations.length; i++) {
|
2018-02-21 14:05:45 +01:00
|
|
|
if ($("#check-" + i).is(":Checked"))
|
2018-02-20 08:39:31 +01:00
|
|
|
list[list.length] = $("#check-" + i).val();
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2018-02-21 14:05:45 +01:00
|
|
|
|
2018-02-20 08:39:31 +01:00
|
|
|
// event handlers
|
|
|
|
window.onresize = function(event) {
|
|
|
|
resizeTable();
|
|
|
|
resizeLogo();
|
|
|
|
};
|
2018-02-21 14:05:45 +01:00
|
|
|
|
|
|
|
$(".ajax-file-upload-abort").on("DOMAttrModified", function(event) {
|
2018-02-20 08:39:31 +01:00
|
|
|
$(".ajax-file-upload-abort").css("display", "none");
|
2018-02-21 14:05:45 +01:00
|
|
|
if (event.attributeName == "display") { // which attribute you want to watch for changes
|
|
|
|
$(".ajax-file-upload-abort").css("display", "none");
|
|
|
|
}
|
2018-02-20 08:39:31 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
buildLanguageList = function() {
|
|
|
|
// build the language selection input control
|
|
|
|
for (i in languages) {
|
|
|
|
var opt = "<option value=\"" + languages[i] + "\" selected=\"selected\">"
|
|
|
|
+ languages[i] + "</option>";
|
|
|
|
if (i > 1)
|
|
|
|
opt = "<option value=\"" + languages[i] + "\">" + languages[i]
|
|
|
|
+ "</option>";
|
|
|
|
$("#language-select").append(opt);
|
|
|
|
}
|
|
|
|
}
|
2018-02-22 17:47:59 +01:00
|
|
|
|
2018-02-21 14:05:45 +01:00
|
|
|
textAreaEnable = function(enable) {
|
2018-02-22 17:47:59 +01:00
|
|
|
if (enable == true)
|
2018-02-21 14:05:45 +01:00
|
|
|
$("#input-textarea").prop('disabled', false);
|
2018-02-22 17:47:59 +01:00
|
|
|
else
|
2018-02-21 14:05:45 +01:00
|
|
|
$("#input-textarea").prop('disabled', true);
|
|
|
|
}
|
2018-02-20 08:39:31 +01:00
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
purgeJson = function(json) {
|
2018-02-26 15:39:10 +01:00
|
|
|
console.log("purgeJson:before: " + json.length);
|
|
|
|
var purged = json.replace(/\n/g, "\\\\n").replace(/\r/g, "\\\\r")
|
|
|
|
.replace(/\t/g, "\\\\t");
|
|
|
|
console.log("purgeJson:after : " + purged.length);
|
|
|
|
return purged;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonToText = function(json) {
|
|
|
|
console.log("jsonToText:before: " + json.length);
|
|
|
|
var purged = json.replace(/\\n/g, "");
|
|
|
|
console.log("jsonToText:after : " + purged.length);
|
|
|
|
return purged;
|
|
|
|
//return json.replace(/\\n/g, "\n");
|
2018-02-22 17:47:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
randomRGB = function() {
|
|
|
|
var letters = '0123456789ABCDEF';
|
2018-02-26 15:39:10 +01:00
|
|
|
var color = '';
|
|
|
|
var couple = '';
|
|
|
|
for(var i=0; i < 3; i++) {
|
|
|
|
do {
|
|
|
|
couple = '';
|
|
|
|
for(j=0; j<2; j++) {
|
|
|
|
couple += letters[Math.floor(Math.random() * 16)];
|
|
|
|
}
|
|
|
|
} while((255 - parseInt("0x" + couple)) < 48)
|
|
|
|
color += couple;
|
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
2018-02-22 17:47:59 +01:00
|
|
|
}
|
2018-02-20 08:39:31 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
<body style="padding: 0 15px;">
|
2018-02-21 14:05:45 +01:00
|
|
|
|
|
|
|
<div class="logo">
|
|
|
|
<img id="logo-image" src="img/nlphub-logo-3.png">
|
|
|
|
</div>
|
2018-02-20 08:39:31 +01:00
|
|
|
|
|
|
|
<!-- the "main-div" contains all tabs and contents -->
|
|
|
|
<div class="main-div">
|
|
|
|
<!-- tabs div: each tab must refer a page div -->
|
|
|
|
<div class="col s12">
|
|
|
|
<ul class="tabs">
|
|
|
|
<li class="tab col s3"><a href="#ner">NER</a></li>
|
|
|
|
<li class="tab col s3"><a href="#other">other</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- "ner" div: contains the name entity recognizer interface -->
|
|
|
|
<div id="ner">
|
2018-02-22 17:47:59 +01:00
|
|
|
<div id="ner-ui">
|
|
|
|
<p class="flow-text">Name Entity Recognition</p>
|
|
|
|
<fieldset>
|
|
|
|
<legend>Language selection</legend>
|
|
|
|
<div class="row">
|
|
|
|
<div class="clearfix">
|
|
|
|
<div class="column half-width">
|
2018-03-06 14:26:22 +01:00
|
|
|
<p class="margin-3 text-align-right"></p>
|
2018-02-22 17:47:59 +01:00
|
|
|
</div>
|
|
|
|
<div class="column half-width">
|
|
|
|
<select id="language-select" class="margin-3 align-left">
|
|
|
|
</select>
|
|
|
|
</div>
|
2018-02-20 08:39:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-02-22 17:47:59 +01:00
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<legend>Input text</legend>
|
|
|
|
<div class="row">
|
|
|
|
<div class="clearfix">
|
|
|
|
<div class="column margin-right-10px">
|
2018-03-06 14:26:22 +01:00
|
|
|
<p>Drag a file on the Upload box, or select a file from your PC, or paste a text.</p>
|
2018-02-22 17:47:59 +01:00
|
|
|
</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"
|
2018-02-20 08:39:31 +01:00
|
|
|
id="upload-button">Upload text file</div>-->
|
2018-02-22 17:47:59 +01:00
|
|
|
<div class="waves-effect waves-light darken-1"
|
|
|
|
id="upload-button">Upload text file</div>
|
|
|
|
</div>
|
2018-02-20 08:39:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-02-22 17:47:59 +01:00
|
|
|
<div class="input-field col s12">
|
|
|
|
<textarea id="input-textarea" class="my-textarea" rows="8"
|
|
|
|
placeholder="paste your text here"></textarea>
|
|
|
|
</div>
|
2018-02-20 08:39:31 +01:00
|
|
|
</div>
|
2018-02-22 17:47:59 +01:00
|
|
|
</fieldset>
|
2018-02-20 08:39:31 +01:00
|
|
|
|
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
<fieldset>
|
2018-03-06 14:26:22 +01:00
|
|
|
<legend>Annotations (deselect those you don't want to be reported)</legend>
|
2018-02-22 17:47:59 +01:00
|
|
|
<div class="vscrollable">
|
|
|
|
<table id="annotations-table">
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</fieldset>
|
2018-02-20 08:39:31 +01:00
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
<!-- this is the "execute button" -->
|
|
|
|
<div style="text-align: center; padding: 5px;">
|
2018-03-06 14:26:22 +01:00
|
|
|
<a id="execute-button">Analyse</a>
|
2018-02-22 17:47:59 +01:00
|
|
|
</div>
|
2018-02-20 08:39:31 +01:00
|
|
|
</div>
|
2018-02-22 17:47:59 +01:00
|
|
|
<!-- this is the main result container -->
|
|
|
|
<div id="ner-result-container">
|
|
|
|
<div id="result-header" class="header-side"></div>
|
|
|
|
<div class="left-side" id="result-text-div"></div>
|
|
|
|
<div class="right-side" id="result-params-div"></div>
|
|
|
|
<div style="text-align: left;">
|
|
|
|
<div class="green-button float-right-div" id="back-ner-ui-button">back</div>
|
|
|
|
</div>
|
2018-02-20 08:39:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- end "#ner" -->
|
|
|
|
|
|
|
|
<div id="#other"></div>
|
|
|
|
|
2018-02-22 17:47:59 +01:00
|
|
|
<!-- this section is used only for the operation progress indicator -->
|
2018-02-21 14:05:45 +01:00
|
|
|
<div class="hidden-div progress-circular-div">
|
|
|
|
<div class="preloader-wrapper big active">
|
|
|
|
<div class="spinner-layer spinner-blue-only">
|
|
|
|
<div class="circle-clipper left">
|
|
|
|
<div class="circle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="gap-patch">
|
|
|
|
<div class="circle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="circle-clipper right">
|
|
|
|
<div class="circle"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="progress-caption">In progress</div>
|
|
|
|
</div>
|
|
|
|
|
2018-02-20 08:39:31 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
<!-- end "#main-div" -->
|
|
|
|
</body>
|
|
|
|
</html>
|