2018-03-09 14:40:21 +01:00
var tableRawSize = 5 ;
var annotations = [ ] ;
var algorithms = [ ] ;
var languages = [ ] ;
var publicLink = null ;
var pageGreen = "#4CAF50" ;
var pageGray = "#A0A0A0" ;
var savedAnnotations = "" ;
var jsonContent = null ;
var named = null ;
var resultText = "" ;
var hexLetters = '0123456789ABCDEF' ;
2018-03-15 15:40:50 +01:00
var txtFlag = true ;
2018-03-19 16:31:23 +01:00
var checkedAnnotation = "" ;
2018-03-21 15:44:38 +01:00
var algIndexedArray = [ ] ;
2018-03-22 13:10:09 +01:00
var computedLanguage = "" ;
2018-03-23 11:04:58 +01:00
var dataMiner = "" ;
2018-05-10 19:21:15 +02:00
var appLocation = window . location . href ;
var appRoot = "" ;
2018-03-09 14:40:21 +01:00
// ------------------------------------------------------------------------------------------------------
// Starting point: get the csv file with algorithm parameters and set the page
// with valid algs info.
// ------------------------------------------------------------------------------------------------------
2018-03-13 14:31:37 +01:00
$ ( document ) . ready ( function ( ) {
2018-05-10 19:21:15 +02:00
console . log ( 'HREF: ' + appLocation ) ;
appRoot = contextPath ;
console . log ( 'appRoot: ' + appRoot ) ;
2018-07-02 11:36:22 +02:00
evaluateRequest ( ) ;
} ) ;
evaluateRequest = function ( ) {
2018-04-16 16:53:57 +02:00
$ ( ".popup-text" ) . hide ( ) ;
2018-03-13 14:31:37 +01:00
disableExecuteButton ( ) ;
2018-03-20 17:03:42 +01:00
showAnnotationsList ( ) ;
2018-07-02 11:36:22 +02:00
checkAuth ( ) ;
}
checkAuth = function ( ) {
if ( gCubeToken === undefined || gCubeToken == null ) {
alert ( "Unexpected error token is null!\n." ) ;
return null ;
}
dataMinerClusterInfo ( ) ;
2018-03-22 13:10:09 +01:00
checkInputLink ( ) ;
2018-07-02 11:36:22 +02:00
}
dataMinerClusterInfo = function ( ) {
if ( gCubeToken === undefined || gCubeToken == null ) {
alert ( "Unexpected error token is null!\n." ) ;
return null ;
}
var discoverDataMinerServiceUrl = appRoot + "/discover-dataminer-servlet?gcube-token=" + gCubeToken ;
$ . ajax ( {
url : discoverDataMinerServiceUrl ,
type : "GET" ,
async : true ,
success : function ( data ) {
var dataminerHost = data ;
console . log ( "Retrieved dataMinerServiceUrl: " + dataminerHost ) ;
dataMiner = dataminerHost ;
//alert("DataMiner Host: "+dataminerHost);
return ;
} ,
error : function ( request , error ) {
alert ( "Unexpected error reading from link: '" + discoverDataMinerServiceUrl
+ "'\nStatus: " + request . status + "\nError: "
+ error + "\n." ) ;
hideProgress ( ) ;
initApplication ( ) ;
}
} ) ;
}
2018-03-22 13:10:09 +01:00
checkInputLink = function ( ) {
2018-05-09 17:44:19 +02:00
if ( inputFile != "" ) {
2018-03-22 13:10:09 +01:00
showProgress ( ) ;
$ . ajax ( {
url : inputFile ,
type : "GET" ,
async : true ,
success : function ( data , stato ) {
2018-03-23 11:04:58 +01:00
freeText = data ;
2018-05-09 17:44:19 +02:00
var uploaderUrl = appRoot
+ "/nlphub-uploader-servlet?getlang=on&freetext="
+ encodeURIComponent ( freeText ) + "&dataminer="
2018-07-02 11:36:22 +02:00
+ dataMiner ; //encodeURIComponent(dataMiner);
2018-05-09 17:44:19 +02:00
if ( gCubeToken . length > 0 )
uploaderUrl += "&gcube-token=" + gCubeToken ;
2018-03-22 13:10:09 +01:00
$ . ajax ( {
2018-05-09 17:44:19 +02:00
url : uploaderUrl ,
type : "POST" ,
async : true ,
contentType : "text/plain; charset=utf-8" ,
success : function ( data , stato ) {
hideProgress ( ) ;
$ ( "#input-textarea" ) . val ( freeText ) ;
computedLanguage = data . language ;
initApplication ( ) ;
} ,
error : function ( richiesta , stato , errori ) {
alert ( "Unexpected Error. Status: " + richiesta . status ) ;
hideProgress ( ) ;
textAreaEnable ( true ) ;
$ ( "#file-info" ) . empty ( ) ;
initApplication ( ) ;
}
} ) ;
2018-03-22 13:10:09 +01:00
} ,
error : function ( richiesta , stato , errori ) {
2018-05-09 17:44:19 +02:00
alert ( "Unexpected error reading from link: '" + inputFile
+ "'.\nStatus: " + richiesta . status + " Error: "
+ errori + "\nClick OK to start application." ) ;
2018-03-22 13:10:09 +01:00
hideProgress ( ) ;
initApplication ( ) ;
}
} ) ;
2018-05-09 17:44:19 +02:00
} else
initApplication ( ) ;
2018-03-22 13:10:09 +01:00
}
initApplication = function ( ) {
2018-05-09 17:44:19 +02:00
$
. ajax ( {
url : "https://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0" ,
type : "GET" ,
async : true ,
contentType : "text/plain; charset=utf-8" ,
success : function ( data , stato ) {
$ ( "#ner-result-container" ) . hide ( ) ;
2018-07-02 11:36:22 +02:00
var algorithmsEnable = manageCsvData ( data ) ;
getAlgorithms ( algorithmsEnable ) ;
2018-05-09 17:44:19 +02:00
buildLanguageSelection ( ) ;
buildLanguageList ( ) ;
buildAnnotations ( ) ;
resizeTable ( ) ;
resizeLogo ( ) ;
enableAjaxFileUpload ( ) ;
collapsibleHandler ( ) ;
$ ( "#logo-image" ) . click ( function ( ) {
backHandler ( ) ;
} ) ;
2018-03-13 14:31:37 +01:00
2018-05-09 17:44:19 +02:00
$ ( "#back-ner-ui-button" ) . click ( function ( ) {
backHandler ( ) ;
} ) ;
disableExecuteButton ( ) ;
var uploaderUrl = appRoot
+ "/nlphub-uploader-servlet?dataminer="
2018-07-02 11:36:22 +02:00
//+ encodeURIComponent(dataMiner);
+ dataMiner ;
2018-05-09 17:44:19 +02:00
if ( gCubeToken . length > 0 )
uploaderUrl += "&gcube-token=" + gCubeToken ;
$ ( "#upload-button" )
. uploadFile (
{
url : uploaderUrl ,
fileName : "mytxtfile" ,
maxFileCount : 100 ,
multiple : false ,
maxFileSize : 1024 * 1000 * 1 ,
showFileCounter : false ,
showCancel : true ,
// allowedTypes: "txt,.txt",
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 ) {
txtFlag = true ;
$ ( "#file-info" ) . remove ( ) ;
$ ( "#reset-upload" ) . remove ( ) ;
$ ( "#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>" ) ;
$ ( "#reset-upload" ) . hide ( ) ;
$ ( "#reset-upload" )
. click (
function ( ) {
resetExecuteButton ( ) ;
$ ( "#file-info" )
. empty ( ) ;
$ (
"#reset-upload" )
. css (
"display" ,
"none" ) ;
textAreaEnable ( true ) ;
} ) ;
savedAnnotations = "" ;
setEventListeners ( ) ;
} ,
onSelect : function ( files ) {
var fileName = files [ 0 ] . name ;
var extension = ""
+ fileName
. substring ( fileName
. lastIndexOf ( "." ) ) ;
if ( extension . toUpperCase ( ) == ".TXT" ) {
showProgress ( ) ;
textAreaEnable ( false ) ;
$ ( "#input-textarea" ) . val ( "" ) ;
} else {
txtFlag = false ;
alert ( "The application supports text file only (.TXT)" ) ;
}
publicLink = null ;
textAreaEnable ( false ) ;
$ ( "#input-textarea" ) . val ( "" ) ;
} ,
onSubmit : function ( files ) {
var submitFlag = txtFlag ;
txtFlag = true ;
return submitFlag ;
} ,
onSuccess : function ( files , data , xhr ) {
hideProgress ( ) ;
checkLanguage ( data . language ) ;
selectAnnotationsByLanguage ( ) ;
$ ( "#reset-upload" ) . css ( "display" ,
"inline" ) ;
$ ( "#file-info" ) . empty ( ) ;
$ ( "#file-info" )
. append (
"Uploaded: <span style=\"color:#4CAF50; letter-spacing: 1px; font-weight: bold;\">"
+ files
+ "</span>" ) ;
publicLink = data . message ;
enableExecuteButton ( ) ;
if ( publicLink == null ) {
alert ( "Error uploading file." ) ;
}
} ,
onError : function ( files , status ,
errMsg , pd ) {
hideProgress ( ) ;
textAreaEnable ( true ) ;
alert ( errMsg ) ;
}
} ) ;
if ( $ ( "#input-textarea" ) . val ( ) != "" ) {
disableAjaxFileUpload ( ) ;
if ( computedLanguage != "" ) {
checkLanguage ( computedLanguage ) ;
selectAnnotationsByLanguage ( ) ;
computedLanguage = "" ;
}
enableExecuteButton ( ) ;
}
} ,
error : function ( richiesta , stato , errori ) {
alert ( "Unexpected Error. Status: " + richiesta . status ) ;
2018-03-22 13:10:09 +01:00
}
2018-05-09 17:44:19 +02:00
} ) ;
2018-03-22 13:10:09 +01:00
}
/ *
* Set the listeners on the text area and the execute button
* /
setEventListeners = function ( ) {
$ ( ".ajax-file-upload" ) . attr ( "id" , "ajax-file-upload-id" ) ;
2018-05-09 17:44:19 +02:00
2018-03-22 13:10:09 +01:00
$ ( "#input-textarea" ) . on ( "keyup" , function ( ) {
enableDisableTextArea ( ) ;
} ) ;
2018-05-09 17:44:19 +02:00
2018-03-22 13:10:09 +01:00
$ ( "#input-textarea" ) . change ( function ( ) {
enableDisableTextArea ( ) ;
} ) ;
2018-05-09 17:44:19 +02:00
2018-03-22 13:10:09 +01:00
window . addEventListener ( 'contextmenu' , function ( e ) {
enableDisableTextArea ( ) ;
2018-05-09 17:44:19 +02:00
} , false ) ;
2018-04-16 16:53:57 +02:00
$ ( ".popup-text" ) . click ( function ( e ) {
hidePopupText ( ) ;
} ) ;
2018-05-09 17:44:19 +02:00
2018-03-22 13:10:09 +01:00
$ ( "#execute-button" )
. click (
function ( ) {
2018-05-09 17:44:19 +02:00
if ( ! isEnabled ( ) )
2018-03-22 13:10:09 +01:00
return ;
2018-05-09 17:44:19 +02:00
2018-03-22 13:10:09 +01:00
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 ;
}
disableExecuteButton ( ) ;
2018-05-09 17:44:19 +02:00
2018-03-22 13:10:09 +01:00
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 ) {
2018-05-09 17:44:19 +02:00
// if(publicLink == null) {
2018-04-11 11:43:11 +02:00
freeText = $ ( "#input-textarea" ) . val ( ) ;
2018-05-09 17:44:19 +02:00
var uploaderUrl = appRoot
+ "/nlphub-uploader-servlet?freetext="
+ encodeURIComponent ( freeText )
+ "&dataminer="
2018-07-02 11:36:22 +02:00
//+ encodeURIComponent(dataMiner);
+ dataMiner ;
2018-05-09 17:44:19 +02:00
if ( gCubeToken . length > 0 )
2018-04-11 11:43:11 +02:00
uploaderUrl += "&gcube-token=" + gCubeToken ;
$ . ajax ( {
2018-05-09 17:44:19 +02:00
url : uploaderUrl ,
type : "POST" ,
async : true ,
contentType : "text/plain; charset=utf-8" ,
success : function ( data , stato ) {
publicLink = data . message ;
if ( publicLink == null ) {
alert ( "Error uploading file." ) ;
2018-04-11 11:43:11 +02:00
}
2018-05-09 17:44:19 +02:00
runAlgorithm ( ) ;
} ,
error : function ( richiesta , stato , errori ) {
alert ( "Unexpected Error. Status: "
+ richiesta . status ) ;
hideProgress ( ) ;
textAreaEnable ( true ) ;
$ ( "#file-info" ) . empty ( ) ;
}
} ) ;
2018-03-22 13:10:09 +01:00
}
2018-03-13 14:31:37 +01:00
2018-03-22 13:10:09 +01:00
else {
runAlgorithm ( ) ;
}
} ) ;
}
2018-03-20 14:45:49 +01:00
collapsibleHandler = function ( ) {
2018-05-09 17:44:19 +02:00
// $('.collapsible').collapsible();
// $('.collapsible').collapsible({
// onOpen: function(el) {
// if(el.index() == 0)
// $('.collapsible').collapsible('close', 1);
// else
// $('.collapsible').collapsible('close', 0);
// },
// onClose: function(el) {
// if(el.index() == 0)
// $('.collapsible').collapsible('open', 1);
// else
// $('.collapsible').collapsible('open', 0);
// }
// });
2018-03-20 14:45:49 +01:00
}
2018-05-09 17:44:19 +02:00
enableAjaxFileUpload = function ( ) {
2018-03-19 16:31:23 +01:00
$ ( ".ajax-file-upload" ) . attr ( "enabled" , "true" ) ;
$ ( ".ajax-file-upload" ) . css ( "background" , pageGreen ) ;
try {
2018-07-02 11:36:22 +02:00
var fUploadElement = document . getElementById ( "ajax-file-upload-id" ) ;
if ( fUploadElement != null ) {
fUploadElement . removeEventListener (
2018-05-09 17:44:19 +02:00
"click" , listenAjaxFileUpload ) ;
2018-07-02 11:36:22 +02:00
}
2018-05-09 17:44:19 +02:00
} catch ( err ) {
2018-03-19 16:31:23 +01:00
console . log ( err . message ) ;
}
}
2018-05-09 17:44:19 +02:00
disableAjaxFileUpload = function ( ) {
2018-03-19 16:31:23 +01:00
$ ( ".ajax-file-upload" ) . attr ( "enabled" , "false" ) ;
$ ( ".ajax-file-upload" ) . css ( "background" , pageGray ) ;
try {
2018-05-09 17:44:19 +02:00
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 ) ;
2018-03-19 16:31:23 +01:00
}
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
}
listenAjaxFileUpload = function ( event ) {
event . preventDefault ( ) ;
}
backHandler = function ( ) {
2018-05-09 17:44:19 +02:00
if ( $ ( "#ner-ui" ) . is ( ":visible" ) )
2018-03-19 16:31:23 +01:00
return ;
$ ( "#ner-result-container" ) . hide ( ) ;
2018-04-16 16:53:57 +02:00
$ ( ".popup-text" ) . hide ( ) ;
2018-03-19 16:31:23 +01:00
$ ( "#ner-ui" ) . show ( ) ;
2018-05-09 17:44:19 +02:00
if ( publicLink != null ) {
2018-03-19 16:31:23 +01:00
enableExecuteButton ( ) ;
2018-05-09 17:44:19 +02:00
if ( document . getElementById ( "reset-upload" ) != null ) {
if ( $ ( "#reset-upload" ) . is ( ":visible" ) )
2018-03-27 17:01:18 +02:00
textAreaEnable ( false ) ;
}
2018-03-19 16:31:23 +01:00
}
}
2018-03-09 14:40:21 +01:00
/ *
2018-05-09 17:44:19 +02:00
* Utility function processing the language indication returned by the language
* recognition service
2018-03-09 14:40:21 +01:00
* /
checkLanguage = function ( lang ) {
2018-05-09 17:44:19 +02:00
if ( lang == 'unavailable' )
2018-03-15 15:40:50 +01:00
return ;
2018-03-09 14:40:21 +01:00
var options = $ ( "#language-select option" ) ;
2018-05-09 17:44:19 +02:00
for ( var i = 0 ; i < options . length ; i ++ ) {
if ( options [ i ] . innerText . toLowerCase ( ) == lang . toLowerCase ( ) ) {
2018-03-09 14:40:21 +01:00
$ ( "#language-select" ) . val ( options [ i ] . innerText ) ;
buildAnnotations ( ) ;
return ;
}
2018-02-20 08:39:31 +01:00
}
2018-05-09 17:44:19 +02:00
alert ( "The uploaded file seems to be in "
+ lang
+ ", but this language is not currently supported. Please, be aware of this, should you decide to continue and use the tools of another language... \"Praemonitus praemunitus!\"" ) ;
2018-03-09 14:40:21 +01:00
}
2018-02-20 08:39:31 +01:00
2018-03-09 14:40:21 +01:00
/ *
2018-05-09 17:44:19 +02:00
* CSV parser
2018-03-09 14:40:21 +01:00
* /
manageCsvData = function ( data ) {
2018-03-23 11:04:58 +01:00
var tokensPerLine = 8 ;
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
// 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 {
2018-03-23 11:04:58 +01:00
tokens . push ( line . substring ( tokenStart + 1 , j ) ) ;
2018-03-09 14:40:21 +01:00
tokenStart = j ;
}
}
}
// get the new token and push it in the array
2018-03-23 11:04:58 +01:00
tokens . push ( line . substring ( tokenStart + 1 ) ) ;
2018-05-09 17:44:19 +02:00
if ( tokens . length != tokensPerLine )
2018-03-23 11:04:58 +01:00
continue ; // skip...
2018-05-09 17:44:19 +02:00
2018-03-23 11:04:58 +01:00
lineTokens . push ( tokens ) ;
var description = tokens [ 1 ] . toUpperCase ( ) . trim ( ) ;
2018-07-02 11:36:22 +02:00
/ * i f ( d e s c r i p t i o n = = " C L O U D C O M P U T I N G " )
dataMiner = tokens [ 2 ] ; * /
2018-03-09 14:40:21 +01:00
tokens = [ ] ;
2018-02-20 08:39:31 +01:00
}
2018-03-09 14:40:21 +01:00
return lineTokens ;
}
/ *
2018-05-09 17:44:19 +02:00
* Map the supported algorithms ( from CSV ) in the internal global algorithm
* array
2018-03-09 14:40:21 +01:00
* /
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
2018-03-23 11:04:58 +01:00
if ( lineTokens [ i ] [ 1 ] . toUpperCase ( ) . trim ( ) != activePage . toUpperCase ( ) )
continue ;
2018-03-09 14:40:21 +01:00
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 ( ) ;
2018-05-09 17:44:19 +02:00
algorithms . push ( {
2018-03-09 14:40:21 +01:00
"name" : algName ,
"description" : algDescription ,
"id" : algId ,
"lang" : language ,
"annotations" : annotationList
2018-03-21 15:44:38 +01:00
} ) ;
2018-05-09 17:44:19 +02:00
algIndexedArray [ algorithms [ algorithms . length - 1 ] . id
. substr ( algorithms [ 0 ] . id . lastIndexOf ( "." ) + 1 ) ] = algorithms [ algorithms . length - 1 ] ;
2018-02-20 08:39:31 +01:00
}
}
2018-03-09 14:40:21 +01:00
}
2018-02-20 08:39:31 +01:00
2018-03-09 14:40:21 +01:00
/ *
* Build the annotation list based on the language selected
* /
buildAnnotations = function ( ) {
annotations = [ ] ;
var language = $ ( "#language-select" ) . val ( ) ;
for ( i in algorithms ) {
if ( algorithms [ i ] . lang . toLowerCase ( ) != language . toLowerCase ( ) )
continue ;
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 ) {
if ( annotations [ k ] . toUpperCase ( ) == a [ j ] . toUpperCase ( ) ) {
thereIs = true ;
break ;
}
}
if ( ! thereIs )
annotations [ annotations . length ] = a [ j ] ;
}
}
}
2018-02-20 08:39:31 +01:00
}
2018-03-09 14:40:21 +01:00
/ *
* Build the language array
* /
buildLanguageSelection = function ( ) {
for ( i in algorithms ) {
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 ) {
if ( languages [ k ] . toUpperCase ( ) == langs [ j ] . toUpperCase ( ) ) {
thereIs = true ;
break ;
}
}
if ( ! thereIs )
languages [ languages . length ] = langs [ j ] ;
}
}
2018-02-20 08:39:31 +01:00
}
}
2018-03-13 14:31:37 +01:00
enableExecuteButton = function ( ) {
$ ( "#execute-button" ) . css ( "background-color" , pageGreen ) ;
$ ( "#execute-button" ) . attr ( "enable" , "true" ) ;
}
disableExecuteButton = function ( ) {
$ ( "#execute-button" ) . css ( "background-color" , pageGray ) ;
$ ( "#execute-button" ) . attr ( "enable" , "false" ) ;
}
isEnabled = function ( ) {
2018-05-09 17:44:19 +02:00
if ( $ ( "#execute-button" ) . attr ( "enable" ) == "true" )
2018-03-13 14:31:37 +01:00
return true ;
return false ;
}
enableDisableTextArea = function ( ) {
2018-03-19 16:31:23 +01:00
if ( $ ( "#input-textarea" ) . val ( ) == "" ) {
2018-03-13 14:31:37 +01:00
disableExecuteButton ( ) ;
2018-03-19 16:31:23 +01:00
enableAjaxFileUpload ( ) ;
2018-05-09 17:44:19 +02:00
} else {
2018-03-13 14:31:37 +01:00
enableExecuteButton ( ) ;
2018-03-19 16:31:23 +01:00
disableAjaxFileUpload ( ) ;
}
2018-03-13 14:31:37 +01:00
}
2018-03-09 14:40:21 +01:00
/ *
* show the in - progress popup
* /
showProgress = function ( ) {
$ ( ".hidden-div" ) . css ( "display" , "block" ) ;
2018-03-16 11:01:37 +01:00
$ ( ".hidden-div" ) . show ( ) ;
2018-03-09 14:40:21 +01:00
}
/ *
* hide the in - progress popup
* /
hideProgress = function ( ) {
$ ( ".hidden-div" ) . css ( "display" , "none" ) ;
2018-03-16 11:01:37 +01:00
$ ( ".hidden-div" ) . hide ( ) ;
2018-03-09 14:40:21 +01:00
}
/ *
* run the algorithms selected by the chosen language
* /
2018-03-22 13:10:09 +01:00
runAlgorithm = function ( ) {
2018-03-09 14:40:21 +01:00
if ( publicLink == null ) {
alert ( "No input text available for the service." ) ;
return ;
}
var list = buildInputAnnotationList ( ) ;
var annList = "" ;
for ( i in list ) {
annList += list [ i ] + "," ;
}
annList = annList . substring ( 0 , annList . length - 1 ) ;
savedAnnotations = annList ;
2018-03-15 15:40:50 +01:00
// build the algorithm list, selecting on:
// [1] the language
// [2] the annotations
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
var algList = "" ;
for ( j in algorithms ) {
if ( algorithms [ j ] . lang . toLowerCase ( ) . indexOf (
$ ( "#language-select" ) . val ( ) . toLowerCase ( ) ) >= 0 ) {
2018-03-15 15:40:50 +01:00
var algAnnotations = algorithms [ j ] . annotations . toLowerCase ( ) ;
2018-05-09 17:44:19 +02:00
for ( k in list ) {
2018-03-15 15:40:50 +01:00
var a = list [ k ] . toLowerCase ( ) ;
2018-05-09 17:44:19 +02:00
if ( algAnnotations . indexOf ( a ) > - 1 ) {
2018-03-15 15:40:50 +01:00
algList += encodeURI ( algorithms [ j ] . id ) + "," ;
break ;
}
}
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
}
2018-02-20 08:39:31 +01:00
}
2018-03-09 14:40:21 +01:00
if ( algList . length == 0 ) {
alert ( "Warning. No algorithm matching with selected language." ) ;
2018-03-19 16:31:23 +01:00
hideProgress ( ) ;
2018-03-09 14:40:21 +01:00
return ;
}
algList = algList . substring ( 0 , algList . length - 1 ) ;
var parameters = "annotations=" + annList ;
2018-07-02 11:36:22 +02:00
parameters += "&dataminer=" + dataMiner ; //+ encodeURIComponent(dataMiner);
2018-03-09 14:40:21 +01:00
parameters += "&lang=" + $ ( "#language-select" ) . val ( ) ;
2018-03-23 11:04:58 +01:00
parameters += "&plink=" + encodeURIComponent ( publicLink ) ;
2018-03-09 14:40:21 +01:00
parameters += "&algs=" + algList ;
2018-04-11 11:43:11 +02:00
var nlphubUrl = appRoot + "/nlphub-servlet?" + parameters ;
2018-05-09 17:44:19 +02:00
if ( gCubeToken . length > 0 )
2018-03-23 11:04:58 +01:00
nlphubUrl += "&gcube-token=" + gCubeToken ;
2018-03-09 14:40:21 +01:00
$ . ajax ( {
2018-03-23 11:04:58 +01:00
url : nlphubUrl ,
2018-03-09 14:40:21 +01:00
type : "POST" ,
async : true ,
success : function ( data , stato ) {
textAreaEnable ( true ) ;
if ( typeof ( data . response ) != 'undefined' ) {
var jsonOut = getOutputJson ( data . message ) ;
} else if ( typeof ( data . error ) != 'undefined' ) {
hideProgress ( ) ;
alert ( data . message ) ;
2018-02-20 08:39:31 +01:00
} else {
2018-03-09 14:40:21 +01:00
hideProgress ( ) ;
alert ( "Unexpected response" ) ;
2018-02-20 08:39:31 +01:00
}
2018-03-09 14:40:21 +01:00
} ,
error : function ( richiesta , stato , errori ) {
hideProgress ( ) ;
textAreaEnable ( true ) ;
alert ( "Unexpected Error. Status: " + richiesta . status ) ;
2018-02-20 08:39:31 +01:00
}
2018-03-09 14:40:21 +01:00
} ) ;
}
/ *
* Get the final json returned by the server
* /
getOutputJson = function ( message ) {
var tobemap = "" ;
for ( var i = 0 ; i < message . length ; i ++ ) {
2018-03-19 16:31:23 +01:00
var splitted = message [ i ] . split ( ":::" ) ;
2018-05-09 17:44:19 +02:00
if ( splitted [ 1 ] . toLowerCase ( ) . trim ( ) == "error" ) {
alert ( "Some error occurrend running algorithm " + splitted [ 0 ]
+ ". Trying to get other results..." ) ;
} else {
2018-03-19 16:31:23 +01:00
tobemap += message [ i ] + "|" ;
}
2018-03-09 14:40:21 +01:00
}
tobemap = tobemap . substring ( 0 , tobemap . length - 1 ) ;
2018-02-20 08:39:31 +01:00
2018-03-09 14:40:21 +01:00
var parameters = "annotations=" + savedAnnotations ;
parameters += "&plink=" + encodeURI ( publicLink ) ;
parameters += "&lang=" + $ ( "#language-select" ) . val ( ) ;
parameters += "&tobemap=" + encodeURI ( tobemap ) ;
2018-04-11 11:43:11 +02:00
var mapperUrl = appRoot + "/nlphub-mapper-servlet?" + parameters ;
2018-05-09 17:44:19 +02:00
if ( gCubeToken . length > 0 )
2018-03-23 11:04:58 +01:00
mapperUrl += "&gcube-token=" + gCubeToken ;
2018-03-09 14:40:21 +01:00
$ . ajax ( {
2018-03-23 11:04:58 +01:00
url : mapperUrl ,
2018-03-09 14:40:21 +01:00
type : "POST" ,
async : true ,
success : function ( data , stato ) {
hideProgress ( ) ;
if ( ( typeof ( data . response ) != "undefined" )
&& ( data . response . trim ( ) . toUpperCase ( ) == "ERROR" ) ) {
alert ( "ERROR\n" + data . message ) ;
} else {
savedAnnotations = "" ;
showResult ( data ) ;
}
} ,
error : function ( richiesta , stato , errori ) {
hideProgress ( ) ;
$ ( "#reset-upload" ) . hide ( ) ;
savedAnnotations = "" ;
2018-05-09 17:44:19 +02:00
// publicLink = null;
2018-03-09 14:40:21 +01:00
alert ( "Unexpected Error. Status: " + richiesta . status ) ;
}
2018-02-20 08:39:31 +01:00
} ) ;
}
2018-03-09 14:40:21 +01:00
/ *
2018-05-09 17:44:19 +02:00
* Show the computation result
2018-03-09 14:40:21 +01:00
* /
showResult = function ( data ) {
$ ( "#ner-ui" ) . hide ( ) ;
$ ( "#ner-result-container" ) . show ( ) ;
jsonContent = data ;
resultText = jsonContent . output . text ;
2018-03-13 14:31:37 +01:00
$ ( "#result-header-left" ) . empty ( ) ;
$ ( "#result-header-right" ) . empty ( ) ;
2018-03-09 14:40:21 +01:00
$ ( "#result-params-div" ) . empty ( ) ;
$ ( "#result-text-div" ) . empty ( ) ;
2018-03-13 14:31:37 +01:00
$ ( "#result-header-left" ) . append (
"You can download the overall result as a JSON file <a href='"
+ jsonContent . link + "'>here</a>" ) ;
$ ( "#result-header-right" ) . append ( " " ) ;
2018-03-09 14:40:21 +01:00
var localText = resultText ;
localText = resultText . replace ( /\n/g , "<br>" ) ;
$ ( "#result-text-div" ) . empty ( ) ;
$ ( "#result-text-div" ) . append ( "<p>" + localText + "</p>" ) ;
2018-03-19 16:31:23 +01:00
buildAlgortihmList ( ) ;
buildAnnotationList ( jsonContent . output . annotations ) ;
2018-03-09 14:40:21 +01:00
}
2018-03-19 16:31:23 +01:00
/ *
* Build the list of radio - button controls with the annotations
* /
buildAnnotationList = function ( list ) {
2018-03-09 14:40:21 +01:00
var colorDisabled = "CCCCCC" ;
var color ;
var colors = [ ] ;
var annotations = list . split ( "," ) ;
for ( var i = 0 ; i < annotations . length ; i ++ ) {
do {
color = randomRGB ( ) ;
} while ( color == colorDisabled ) ;
colors [ colors . length ] = color ;
}
$ ( "#result-params-div" ) . append ( "<form id='colored-annotations'></form>" ) ;
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
var firstRadio = true ;
2018-03-09 14:40:21 +01:00
for ( var i = 0 ; i < annotations . length ; i ++ ) {
2018-03-19 16:31:23 +01:00
var cb = "<input type='radio' name='foo-ner-annotations' " ;
2018-03-09 14:40:21 +01:00
if ( ! checkAnnotation ( annotations [ i ] ) ) {
cb += "disabled " ;
colors [ i ] = colorDisabled ;
}
2018-05-09 17:44:19 +02:00
if ( firstRadio ) {
if ( cb . indexOf ( "disabled" ) < 0 ) {
2018-03-19 16:31:23 +01:00
firstRadio = false ;
cb += "checked " ;
}
}
2018-03-09 14:40:21 +01:00
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 ) ;
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
}
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
$ ( "#colored-annotations :radio" ) . change ( function ( ) {
if ( this . checked ) {
2018-05-09 17:44:19 +02:00
checkedAnnotation = this . getAttribute ( "named" ) ;
2018-03-21 15:44:38 +01:00
filterAlgorithmsByAnnotation ( checkedAnnotation ) ;
2018-03-19 16:31:23 +01:00
rewriteText ( "#" + this . value ) ;
2018-03-09 14:40:21 +01:00
}
} ) ;
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
showAnnotationsList ( ) ;
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
$ ( "#colored-annotations :radio" ) . change ( ) ;
}
/ *
* Utility
* /
showAnnotationsList = function ( ) {
2018-03-20 17:03:42 +01:00
$ ( '.collapsible' ) . collapsible ( 'close' , 0 ) ;
$ ( '.collapsible' ) . collapsible ( 'close' , 1 ) ;
$ ( '.collapsible' ) . collapsible ( 'open' , 1 ) ;
2018-03-19 16:31:23 +01:00
}
2018-05-09 17:44:19 +02:00
/ *
2018-03-19 16:31:23 +01:00
* build the list of check - box controls for algorithms
* /
buildAlgortihmList = function ( ) {
$ ( "#algorithm-params-div" ) . empty ( ) ;
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
for ( var i = 0 ; i < jsonContent . output . result . length ; i ++ ) {
2018-05-09 18:43:59 +02:00
if ( typeof jsonContent . output . result [ i ] === 'undefined'
|| jsonContent . output . result [ i ] == null ) {
2018-05-09 17:44:19 +02:00
console . log ( "No result for " + i ) ;
} else {
var cb = "<div class='alg-info-p'><input type='checkbox' name='foo-ner-algs' checked named='"
+ jsonContent . output . result [ i ] . algorithm
+ "' id='algorithm" + i + "'>" ;
cb += "<label class='label-alg-info' for='algorithm" + i
+ "'></label></div>" ;
cb += "<div class='alg-info-p' onclick='getAlgInformation(\""
+ jsonContent . output . result [ i ] . algorithm
+ "\")'>"
+ findNameByAlgorithmId ( jsonContent . output . result [ i ] . algorithm )
+ "</div><div class='clearfix'></div>" ;
$ ( "#algorithm-params-div" ) . append ( cb ) ;
}
2018-03-19 16:31:23 +01:00
}
2018-05-09 17:44:19 +02:00
$ ( "#algorithm-params-div :checkbox" ) . change ( function ( ) {
// buildCheckedAlgs();
2018-03-19 16:31:23 +01:00
rewriteText ( $ ( "#colored-annotations :checked" ) [ 0 ] . value ) ;
} ) ;
}
2018-04-16 16:53:57 +02:00
getAlgInformation = function ( alg ) {
var algId = "" ;
2018-05-09 17:44:19 +02:00
for ( var i in algorithms ) {
if ( algorithms [ i ] . id . indexOf ( alg ) > 0 ) {
2018-04-16 16:53:57 +02:00
algId = algorithms [ i ] . id ;
break ;
}
}
2018-05-09 17:44:19 +02:00
if ( algId == "" ) {
2018-04-16 16:53:57 +02:00
alert ( "Invalid algorithm identifier." ) ;
return ;
}
2018-07-02 11:36:22 +02:00
console . log ( "getAlgorithm from dataMiner: " + dataMiner ) ;
2018-04-16 16:53:57 +02:00
var parameters = "getInfo=on" ;
2018-07-02 11:36:22 +02:00
parameters += "&dataminer=" + dataMiner ; //encodeURIComponent(dataMiner);
2018-04-16 16:53:57 +02:00
parameters += "&algId=" + algId ;
2018-07-02 11:36:22 +02:00
console . log ( "parameters: " + parameters ) ;
2018-04-16 16:53:57 +02:00
var nlphubUrl = appRoot + "/nlphub-servlet?" + parameters ;
2018-05-09 17:44:19 +02:00
if ( gCubeToken . length > 0 )
2018-04-16 16:53:57 +02:00
nlphubUrl += "&gcube-token=" + gCubeToken ;
$ . ajax ( {
url : nlphubUrl ,
type : "GET" ,
async : true ,
success : function ( data , stato ) {
2018-05-09 17:44:19 +02:00
// alert(data.message);
2019-05-31 15:26:17 +02:00
let linkMessage = "<a target='_blank' rel='noopener noreferrer' href='" + data . message + "'>" + data . message + "</a>" ;
showPopupText ( linkMessage ) ;
2018-04-16 16:53:57 +02:00
} ,
error : function ( richiesta , stato , errori ) {
alert ( "Unexpected Error. Status: " + richiesta . status ) ;
}
} ) ;
}
showPopupText = function ( text ) {
$ ( ".popup-text-content" ) . empty ( ) ;
$ ( ".popup-text-content" ) . append ( "<p>" + text + "</p>" ) ;
$ ( ".popup-text" ) . show ( ) ;
}
hidePopupText = function ( ) {
$ ( ".popup-text-content" ) . empty ( ) ;
$ ( ".popup-text" ) . hide ( ) ;
}
2018-03-19 16:31:23 +01:00
/ *
* Utility function
* /
findNameByAlgorithmId = function ( id ) {
2018-05-09 17:44:19 +02:00
for ( i in algorithms ) {
if ( algorithms [ i ] . id . substr ( algorithms [ i ] . id . lastIndexOf ( "." ) + 1 ) == id )
2018-03-19 16:31:23 +01:00
return algorithms [ i ] . name ;
}
return id ;
2018-03-09 14:40:21 +01:00
}
/ *
2018-05-09 17:44:19 +02:00
* Utility function
2018-03-09 14:40:21 +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 ;
}
/ *
* Utility
* /
enhanceColor = function ( color ) {
var c = eval ( "0x" + color ) ;
var hi = Math . round ( c / 16 ) ;
2018-05-09 17:44:19 +02:00
if ( hi < 15 ) {
2018-03-09 14:40:21 +01:00
hi += Math . round ( ( 15 - hi ) / 1.5 ) ;
}
2018-05-09 17:44:19 +02:00
if ( hi > 15 )
hi = 15 ;
return '' + hexLetters [ hi ] + hexLetters [ c % 16 ] ;
2018-03-09 14:40:21 +01:00
}
/ *
2018-05-09 17:44:19 +02:00
* Write the html paragraph < p > containing the text highlighted on annotation
* value
2018-03-09 14:40:21 +01:00
* /
2018-03-19 16:31:23 +01:00
rewriteText = function ( color ) {
2018-05-09 17:44:19 +02:00
if ( color . startsWith ( "#" ) )
2018-03-20 14:45:49 +01:00
color = color . substring ( 1 ) ;
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
$ ( "#result-text-div" ) . empty ( ) ;
2018-03-20 14:45:49 +01:00
var complemetar = 0xFFFFFF - eval ( "0x" + color ) ;
2018-03-09 14:40:21 +01:00
var complement = complemetar . toString ( 16 ) ;
2018-05-09 17:44:19 +02:00
var R = enhanceColor ( complement . substring ( 0 , 2 ) ) ;
var G = enhanceColor ( complement . substring ( 2 , 4 ) ) ;
2018-03-09 14:40:21 +01:00
var B = enhanceColor ( complement . substring ( 4 ) ) ;
complement = "#" + R + G + B ;
2018-03-16 11:01:37 +01:00
showProgress ( ) ;
$ ( ".hidden-div" ) . show ( ) ;
window . setTimeout ( function ( ) {
2018-03-19 16:31:23 +01:00
var indices = getIndices ( ) ;
2018-05-09 17:44:19 +02:00
$ ( ".hidden-div" ) . hide ( ) ;
2018-03-16 11:01:37 +01:00
$ ( "#result-header-right" ) . empty ( ) ;
2018-05-09 17:44:19 +02:00
$ ( "#result-header-right" ) . append (
"<span style='color:" + color + ";'>" + checkedAnnotation
+ "</span> occurs " + indices . length + " times." ) ;
2018-03-16 11:01:37 +01:00
2018-05-09 17:44:19 +02:00
if ( indices . length != 0 ) {
2018-03-19 16:31:23 +01:00
var indexedText = "" ;
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
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 ;
}
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
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 ) ;
2018-05-09 17:44:19 +02:00
2018-03-19 16:31:23 +01:00
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 ) ;
2018-05-09 17:44:19 +02:00
2018-03-16 11:01:37 +01:00
indexedText = indexedText . replace ( /\n/g , "<br>" ) ;
$ ( "#result-text-div" ) . append ( "<p>" + indexedText + "</p>" ) ;
2018-05-09 17:44:19 +02:00
} else {
2018-03-19 16:31:23 +01:00
$ ( "#result-text-div" ) . append ( "<p>" + resultText + "</p>" ) ;
2018-03-16 11:01:37 +01:00
}
} , 50 ) ;
2018-03-09 14:40:21 +01:00
}
2018-03-21 15:44:38 +01:00
filterAlgorithmsByAnnotation = function ( ) {
2018-05-09 17:44:19 +02:00
if ( $ ( "#result-params-div input[type=radio]:checked" ) . length < 1 )
2018-03-21 15:44:38 +01:00
return ;
2018-05-09 17:44:19 +02:00
var annotation = $ ( "#result-params-div input[type=radio]:checked" ) [ 0 ]
. getAttribute ( "named" ) ;
2018-03-21 15:44:38 +01:00
var algs = $ ( "#algorithm-params-div input[type=checkbox]" ) ;
2018-05-09 17:44:19 +02:00
for ( var i = 0 ; i < algs . length ; i ++ ) {
var named = $ ( "#algorithm-params-div input[type=checkbox]" ) [ i ]
. getAttribute ( "named" ) ;
var annList = algIndexedArray [ named ] . annotations ;
if ( annList . indexOf ( annotation ) >= 0 ) {
$ ( $ ( "#algorithm-params-div input[type=checkbox]" ) [ i ] ) . prop (
"checked" , true ) ;
} else {
$ ( $ ( "#algorithm-params-div input[type=checkbox]" ) [ i ] ) . prop (
"checked" , false ) ;
2018-03-21 15:44:38 +01:00
}
}
}
2018-03-09 14:40:21 +01:00
/ *
2018-05-09 17:44:19 +02:00
* Find if the annotation is present in the json
2018-03-09 14:40:21 +01:00
* /
checkAnnotation = function ( annotation ) {
for ( var i = 0 ; i < jsonContent . output . result . length ; i ++ ) {
2018-05-09 18:43:59 +02:00
if ( typeof jsonContent . output . result [ i ] === 'undefined'
|| jsonContent . output . result [ i ] == null ) {
console . log ( "No result for " + i ) ;
} else {
var entities = jsonContent . output . result [ i ] . entities ;
for ( var j = 0 ; j < entities . length ; j ++ ) {
a = entities [ j ] [ annotation ] ;
if ( typeof a != 'undefined' ) {
if ( a . length > 0 )
return true ;
}
2018-03-09 14:40:21 +01:00
}
}
}
return false ;
}
/ *
* Retrieve the annotation indices from the json
* /
2018-03-19 16:31:23 +01:00
getIndices = function ( ) {
2018-03-21 15:44:38 +01:00
var checkedAlgs = $ ( "#algorithm-params-div input[type=checkbox]:checked" ) ;
2018-03-09 14:40:21 +01:00
var indices = [ ] ;
// get indices
for ( var i = 0 ; i < jsonContent . output . result . length ; i ++ ) {
2018-05-10 19:21:15 +02:00
if ( typeof jsonContent . output . result [ i ] === 'undefined'
|| jsonContent . output . result [ i ] == null ) {
console . log ( "No result for " + i ) ;
} else {
// filter on algorithm
var found = false ;
for ( var j = 0 ; j < checkedAlgs . length ; j ++ ) {
if ( checkedAlgs [ j ] . getAttribute ( "named" ) == jsonContent . output . result [ i ] . algorithm ) {
found = true ;
break ;
}
2018-03-19 16:31:23 +01:00
}
2018-05-10 19:21:15 +02:00
if ( ! found )
continue ;
2018-05-09 17:44:19 +02:00
2018-05-10 19:21:15 +02:00
var entities = jsonContent . output . result [ i ] . entities ;
for ( var j = 0 ; j < entities . length ; j ++ ) {
// filter on annotation
a = entities [ j ] [ checkedAnnotation ] ;
if ( typeof a != 'undefined' ) {
indices [ i ] = [ ] ;
for ( var k = 0 ; k < a . length ; k ++ ) {
var index = a [ k ] . indices ;
indices [ i ] [ k ] = index ;
}
2018-03-09 14:40:21 +01:00
}
}
}
}
2018-05-09 17:44:19 +02:00
if ( indices . length == 0 )
2018-03-19 16:31:23 +01:00
return indices ;
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +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 ) ;
}
/ *
* Merge the indices
* /
mergeIndices = function ( indices ) {
2018-03-15 15:40:50 +01:00
var newIndices = [ ] ;
2018-03-20 14:45:49 +01:00
newIndices = mergeAll ( indices ) ;
2018-03-09 14:40:21 +01:00
return newIndices ;
}
/ *
* Utility function
* /
resetExecuteButton = function ( ) {
publicLink = null ;
2018-03-13 14:31:37 +01:00
disableExecuteButton ( ) ;
2018-03-09 14:40:21 +01:00
}
/ *
* Resize the annotation table based on the screen geometry
* /
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>" ) ;
}
2018-03-15 15:40:50 +01:00
2018-03-09 14:40:21 +01:00
var annotationElement = "<input type=\"checkbox\" id=\"check-" + i
+ "\" value=\"" + annotations [ i ]
+ "\" checked=\"checked\"></input> <label for=\"check-" + i
+ "\">" + annotations [ i ] + "</label>" ;
2018-05-09 17:44:19 +02:00
if ( ( annotations [ i ] . toLowerCase ( ) == "keyword" )
|| ( annotations [ i ] . toLowerCase ( ) == "event" ) ) {
2018-03-15 15:40:50 +01:00
annotationElement = "<input type=\"checkbox\" id=\"check-" + i
2018-05-09 17:44:19 +02:00
+ "\" value=\"" + annotations [ i ]
+ "\"></input> <label for=\"check-" + i + "\">"
+ annotations [ i ] + "</label>" ;
2018-03-15 15:40:50 +01:00
}
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
$ ( "#" + rowId ) . append ( "<td>" + annotationElement + "</td>" ) ;
}
}
/ *
* Resize the page logo image based on the screen geometry
* /
resizeLogo = function ( ) {
if ( window . innerWidth < 200 )
$ ( "#logo-image" ) . width ( window . innerWidth - 10 ) ;
}
/ *
* Build the annotation list for the service invocation
* /
buildInputAnnotationList = function ( ) {
var list = [ ] ;
for ( var i = 0 ; i < annotations . length ; i ++ ) {
if ( $ ( "#check-" + i ) . is ( ":Checked" ) )
list [ list . length ] = $ ( "#check-" + i ) . val ( ) ;
}
return list ;
}
/ *
* Handler for the window resize event
* /
window . onresize = function ( event ) {
resizeTable ( ) ;
resizeLogo ( ) ;
} ;
/ *
* Handler for the file upload control
* /
$ ( ".ajax-file-upload-abort" ) . on ( "DOMAttrModified" , function ( event ) {
$ ( ".ajax-file-upload-abort" ) . css ( "display" , "none" ) ;
if ( event . attributeName == "display" ) { // which attribute you want to watch
2018-05-09 17:44:19 +02:00
// for changes
2018-03-09 14:40:21 +01:00
$ ( ".ajax-file-upload-abort" ) . css ( "display" , "none" ) ;
}
} ) ;
/ *
* Build the option list of supported language
* /
buildLanguageList = function ( ) {
// build the language selection input control
2018-03-19 16:31:23 +01:00
var defaultLanguage = null ;
2018-03-09 14:40:21 +01:00
for ( i in languages ) {
2018-03-19 16:31:23 +01:00
languages [ i ] = languages [ i ] . trim ( ) ;
2018-05-09 17:44:19 +02:00
languages [ i ] = languages [ i ] . replace ( /\w\S*/g , function ( txt ) {
return txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ;
} ) ;
if ( languages [ i ] == "English" )
2018-03-19 16:31:23 +01:00
defaultLanguage = languages [ i ] ;
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
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-05-09 17:44:19 +02:00
if ( defaultLanguage != null )
2018-03-19 16:31:23 +01:00
$ ( "#language-select" ) . val ( defaultLanguage ) ;
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
$ ( "#language-select" ) . on ( "change" , function ( ) {
selectAnnotationsByLanguage ( ) ;
} ) ;
2018-05-09 17:44:19 +02:00
2018-03-09 14:40:21 +01:00
}
/ *
* Utility
* /
selectAnnotationsByLanguage = function ( ) {
buildAnnotations ( ) ;
resizeTable ( ) ;
}
/ *
* Enable / disable the input text area
* /
textAreaEnable = function ( enable ) {
if ( enable == true )
$ ( "#input-textarea" ) . prop ( 'disabled' , false ) ;
else
$ ( "#input-textarea" ) . prop ( 'disabled' , true ) ;
}
/ *
* Get a random RGB color
* /
randomRGB = function ( ) {
var color = '' ;
var couple = '' ;
for ( var i = 0 ; i < 3 ; i ++ ) {
2018-05-09 17:44:19 +02:00
couple = '' + hexLetters [ Math . floor ( Math . random ( ) * 10 ) ]
+ hexLetters [ Math . floor ( Math . random ( ) * 16 ) ] ;
2018-03-09 14:40:21 +01:00
color += couple ;
}
return color ;
}