@ -59,6 +59,8 @@ function setupInterface(data, file, urls) {
let save _timeout = null ;
let save _timeout = null ;
let listener _defaults = { prevent _repeat : true } ;
function notifyChange ( ) {
function notifyChange ( ) {
if ( save _timeout != null ) clearTimeout ( save _timeout ) ;
if ( save _timeout != null ) clearTimeout ( save _timeout ) ;
has _changes = true ;
has _changes = true ;
@ -184,10 +186,9 @@ function setupInterface(data, file, urls) {
function makeTdEditable ( td ) {
function makeTdEditable ( td ) {
editingTd = {
editingTd = {
elem : td ,
data : td . innerHTML ,
data : td . innerHTML ,
finish :
finish :
function ( td, isOk) {
function ( isOk) {
if ( isOk ) {
if ( isOk ) {
@ -199,16 +200,13 @@ function setupInterface(data, file, urls) {
data . data [ tableInfo . nRow ] [ tableInfo . column ] = newValue ;
data . data [ tableInfo . nRow ] [ tableInfo . column ] = newValue ;
sanitizeData ( ) ;
notifyChange ( ) ;
notifyChange ( ) ;
updateTable ( ) ;
}
}
else {
else {
$ ( td ) . html ( editingTd . data ) ;
$ ( td ) . html ( editingTd . data ) ;
}
}
let listener = new window . keypress . Listener ( td ) ;
listener . simple _combo ( "enter" , function ( ) { td . click ( ) ; } ) ;
editingTd = null ;
editingTd = null ;
$ ( td ) . focus ( ) ;
$ ( td ) . focus ( ) ;
}
}
@ -225,7 +223,7 @@ function setupInterface(data, file, urls) {
textArea . focus ( ) ;
textArea . focus ( ) ;
let edit _html =
let edit _html =
` <div class="edit-controls" >
` <div class="edit-controls" id="TdEdit" >
< button class = "btn btn-secondary btn-sm" id = "edit-ok" > OK < / b u t t o n >
< button class = "btn btn-secondary btn-sm" id = "edit-ok" > OK < / b u t t o n >
< button class = "btn btn-secondary btn-sm" id = "edit-cancel" > CANCEL < / b u t t o n >
< button class = "btn btn-secondary btn-sm" id = "edit-cancel" > CANCEL < / b u t t o n >
< / d i v > `
< / d i v > `
@ -234,96 +232,100 @@ function setupInterface(data, file, urls) {
$ ( '#edit-ok' ) . on ( 'click' ,
$ ( '#edit-ok' ) . on ( 'click' ,
function ( evt ) {
function ( evt ) {
editingTd . finish ( editingTd . elem , true ) ;
editingTd . finish ( true ) ;
} ) ;
} ) ;
$ ( '#edit-cancel' ) . on ( 'click' ,
$ ( '#edit-cancel' ) . on ( 'click' ,
function ( evt ) {
function ( evt ) {
editingTd . finish ( editingTd . elem , false ) ;
editingTd . finish ( false ) ;
} ) ;
} ) ;
let listener = new window . keypress . Listener ( td) ;
let listener = new window . keypress . Listener ( $( '#edi t-area') , listener _ defaults ) ;
listener . simple _combo ( 'enter' , function ( ) { $ ( '#edit-ok' ) . click ( ) ; } ) ;
listener . simple _combo ( 'enter' , function ( ) { $ ( '#edit-ok' ) . click ( ) ; } ) ;
listener . simple _combo ( 'esc' , function ( ) { $ ( '#edit-cancel' ) . click ( ) ; } ) ;
listener . simple _combo ( 'esc' , function ( ) { $ ( '#edit-cancel' ) . click ( ) ; } ) ;
}
}
function sanitizeData ( ) {
word _pos = 1 ;
for ( let i = 0 ; i < data . data . length ; i ++ ) {
if ( ( data . data [ i ] [ 'TOKEN' ] == null ) || ( data . data [ i ] [ 'TOKEN' ] . toString ( ) . length == 0 ) ) {
word _pos = 0 ;
}
data . data [ i ] [ 'No.' ] = word _pos ;
if ( data . data [ i ] [ 'TOKEN' ] == null ) data . data [ i ] [ 'TOKEN' ] = '' ;
if ( data . data [ i ] [ 'GND-ID' ] == null ) data . data [ i ] [ 'GND-ID' ] = '' ;
if ( data . data [ i ] [ 'NE-TAG' ] == null ) data . data [ i ] [ 'NE-TAG' ] = '' ;
if ( data . data [ i ] [ 'NE-EMB' ] == null ) data . data [ i ] [ 'NE-EMB' ] = '' ;
data . data [ i ] [ 'TOKEN' ] = data . data [ i ] [ 'TOKEN' ] . toString ( ) . replace ( /(\r\n|\n|\r)/gm , "" ) ;
data . data [ i ] [ 'GND-ID' ] = data . data [ i ] [ 'GND-ID' ] . toString ( ) . replace ( /(\r\n|\n|\r)/gm , "" ) ;
data . data [ i ] [ 'NE-TAG' ] = data . data [ i ] [ 'NE-TAG' ] . toString ( ) . replace ( /(\r\n|\n|\r)/gm , "" ) ;
data . data [ i ] [ 'NE-EMB' ] = data . data [ i ] [ 'NE-EMB' ] . toString ( ) . replace ( /(\r\n|\n|\r)/gm , "" ) ;
word _pos ++ ;
}
}
function tableEditAction ( nRow , action ) {
function tableEditAction ( nRow , action ) {
if ( editingTd != null ) return ;
if ( action == null ) return ;
if ( action == null ) return ;
if ( data . data [ nRow ] [ 'TOKEN' ] == null ) data . data [ nRow ] [ 'TOKEN' ] = '' ;
if ( action . includes ( 'merge' ) ) {
if ( action . includes ( 'merge' ) ) {
if ( nRow < 1 ) return ;
if ( nRow < 1 ) return ;
let pos = nRow + 1 ;
if ( data . data [ nRow - 1 ] [ 'TOKEN' ] == null ) data . data [ nRow - 1 ] [ 'TOKEN' ] = '' ;
word _pos = data . data [ nRow - 1 ] [ 'No.' ] + 1
while ( ( pos < data . data . length ) && ( data . data [ pos ] [ 'No.' ] > 1 ) ) {
data . data [ pos ] [ 'No.' ] = word _pos ;
pos ++ ;
word _pos ++ ;
}
data . data [ nRow - 1 ] [ 'TOKEN' ] += data . data [ nRow ] [ 'TOKEN' ] ;
data . data [ nRow - 1 ] [ 'TOKEN' ] =
data . data [ nRow - 1 ] [ 'TOKEN' ] . toString ( ) + data . data [ nRow ] [ 'TOKEN' ] . toString ( ) ;
data . data . splice ( nRow , 1 ) ;
data . data . splice ( nRow , 1 ) ;
notifyChange ( ) ;
}
}
else if ( action . includes ( 'split' ) ) {
else if ( action . includes ( 'split' ) ) {
data . data . splice ( nRow , 0 , JSON . parse ( JSON . stringify ( data . data [ nRow ] ) ) ) ;
data . data . splice ( nRow , 0 , JSON . parse ( JSON . stringify ( data . data [ nRow ] ) ) ) ;
data . data [ nRow + 1 ] [ 'No.' ] += 1 ;
let pos = nRow + 2 ;
while ( ( pos < data . data . length ) && ( data . data [ pos ] [ 'No.' ] > 1 ) ) {
data . data [ pos ] [ 'No.' ] ++ ;
pos ++ ;
}
}
else if ( action . includes ( 'delete' ) ) {
notifyChange( ) ;
data . data . splice ( nRow , 1 ) ;
}
}
else if ( action . includes ( 'sentence' ) ) {
else if ( action . includes ( 'sentence' ) ) {
let pos = nRow ;
let new _line = JSON . parse ( JSON . stringify ( data . data [ nRow ] ) ) ;
new _line [ 'TOKEN' ] = '' ;
let new _row = JSON . parse ( JSON . stringify ( data . data [ pos ] ) )
new _line [ 'NE-TAG' ] = 'O' ;
new _line [ 'NE-EMB' ] = 'O' ;
new _line [ 'GND-ID' ] = '' ;
console . log ( new _row )
data . data . splice ( nRow , 0 , new _line ) ;
data . data . splice ( pos , 0 , new _row ) ;
data . data [ pos ] [ 'No.' ] = 0
data . data [ pos ] [ 'TOKEN' ] = ''
pos += 1
let word _pos = 1 ;
while ( ( pos < data . data . length ) && ( data . data [ pos ] [ 'No.' ] != 1 ) && ( data . data [ pos ] [ 'TOKEN' ] != '' ) ) {
data . data [ pos ] [ 'No.' ] = word _pos ;
pos ++ ;
word _pos ++ ;
}
}
sanitizeData ( ) ;
notifyChange ( ) ;
notifyChange ( ) ;
}
updateTable ( ) ;
updateTable ( ) ;
}
}
function makeLineSplitMerge ( td ) {
function makeLineSplitMerge ( td ) {
editingTd = {
editingTd = {
elem : td ,
data : td . innerHTML ,
data : td . innerHTML ,
tokenizer_action : null ,
finish: function ( action , isOk ) {
finish : function ( td , isOk ) {
$ ( td ) . html ( editingTd . data ) ;
$ ( td ) . html ( editingTd . data ) ;
$ ( td ) . addClass ( 'editable' ) ;
$ ( td ) . addClass ( 'editable' ) ;
let tableInfo = $ ( td ) . data ( 'tableInfo' ) ;
let tableInfo = $ ( td ) . data ( 'tableInfo' ) ;
tableEditAction ( tableInfo . nRow , editingTd . tokenizer _action )
editingTd = null ;
editingTd = null ;
tableEditAction ( tableInfo . nRow , action )
$ ( td ) . focus ( ) ;
}
}
} ;
} ;
@ -337,23 +339,16 @@ function setupInterface(data, file, urls) {
$ ( td ) . removeClass ( 'editable' ) ;
$ ( td ) . removeClass ( 'editable' ) ;
$ ( td ) . html ( edit _html ) ;
$ ( td ) . html ( edit _html ) ;
$ ( '#tokenizer' ) . mouseleave (
$ ( '#tokenizer' ) . mouseleave ( function ( event ) { editingTd . finish ( null , false ) ; } ) ;
function ( event ) {
editingTd . finish ( editingTd . elem , false ) ;
} ) ;
$ ( '.tokenizer-action' ) . click (
$ ( '.tokenizer-action' ) . click ( function ( event ) { editingTd . finish ( $ ( event . target ) . text ( ) , true ) ; } ) ;
function ( event ) {
editingTd . tokenizer _action = $ ( event . target ) . text ( ) ;
} ) ;
}
}
function makeTagEdit ( td ) {
function makeTagEdit ( td ) {
editingTd = {
editingTd = {
elem : td ,
data : td . innerHTML ,
data : td . innerHTML ,
finish : function ( td, isOk) {
finish : function ( isOk) {
let tableInfo = $ ( td ) . data ( 'tableInfo' ) ;
let tableInfo = $ ( td ) . data ( 'tableInfo' ) ;
@ -401,25 +396,22 @@ function setupInterface(data, file, urls) {
$ ( td ) . removeClass ( 'editable' ) ;
$ ( td ) . removeClass ( 'editable' ) ;
$ ( td ) . html ( edit _html ) ;
$ ( td ) . html ( edit _html ) ;
$ ( '#tagger' ) . mouseleave (
$ ( '#tagger' ) . mouseleave ( function ( event ) { editingTd . finish ( false ) ; } ) ;
function ( event ) {
editingTd . finish ( editingTd . elem , false ) ;
} ) ;
$ ( '.type_select' ) . click (
$ ( '.type_select' ) . click (
function ( event ) {
function ( event ) {
editingTd . data = $ ( event . target ) . text ( ) ;
editingTd . data = $ ( event . target ) . text ( ) ;
editingTd . finish ( true ) ;
} ) ;
} ) ;
}
}
function createTable ( ) {
function createTable ( ) {
editingTd = null ;
sanitizeData( ) ;
let editable _html = ` <td class="editable hover"> ` ;
let editable _html = ` <td class="editable hover"> ` ;
$ ( '#table-body' ) . empty ( ) ;
$ . each ( data . data ,
$ . each ( data . data ,
function ( nRow , el ) {
function ( nRow , el ) {
@ -435,7 +427,7 @@ function setupInterface(data, file, urls) {
data ( 'tableInfo' , { 'nRow' : nRow } )
data ( 'tableInfo' , { 'nRow' : nRow } )
) ;
) ;
let row _listener = new window . keypress . Listener ( row );
let row _listener = new window . keypress . Listener ( row , listener _defaults );
row _listener . sequence _combo ( '0' ,
row _listener . sequence _combo ( '0' ,
function ( ) {
function ( ) {
@ -459,37 +451,42 @@ function setupInterface(data, file, urls) {
tableEditAction ( row . data ( 'tableInfo' ) . nRow , 'merge' ) ;
tableEditAction ( row . data ( 'tableInfo' ) . nRow , 'merge' ) ;
} ) ;
} ) ;
row _listener . sequence _combo ( 'd l' , function ( ) {
tableEditAction ( row . data ( 'tableInfo' ) . nRow , 'delete' ) ;
} ) ;
$ . each ( el ,
$ . each ( el ,
function ( column , content ) {
function ( column , content ) {
let td = $ ( editable _html )
let td = $ ( editable _html )
let listener = new window . keypress . Listener ( td );
let listener = new window . keypress . Listener ( td , listener _defaults );
if ( do _not _display . has ( column ) ) return
if ( do _not _display . has ( column ) ) return
let clickAction = function ( ) { console . log ( 'Do something different' ) ; }
let clickAction = function ( ) { console . log ( 'Do something different' ) ; }
if ( column == 'No.' ) {
if ( column == 'No.' ) {
clickAction = makeLineSplitMerge ;
clickAction = makeLineSplitMerge
}
}
if ( ( column == 'TOKEN' ) || ( column == 'GND-ID' ) ) {
if ( ( column == 'TOKEN' ) || ( column == 'GND-ID' ) ) {
clickAction = makeTdEditable
clickAction = makeTdEditable ;
listener . simple _combo ( "enter" , function ( ) {
listener . simple _combo ( 'enter' , function ( ) { $ ( td ) . click ( ) ; } ) ;
td . click ( ) ;
} ) ;
}
}
if ( ( column == 'NE-TAG' ) || ( column == 'NE-EMB' ) ) {
if ( ( column == 'NE-TAG' ) || ( column == 'NE-EMB' ) ) {
clickAction = makeTagEdit
clickAction = makeTagEdit ;
function tagAction ( tag ) {
tableInfo = $ ( td ) . data ( 'tableInfo' ) ;
let tagAction = function ( tag ) {
data . data [ tableInfo . nRow ] [ tableInfo . column ] = tag ;
data . data [ $ ( td ) . data ( 'tableInfo' ) . nRow ] [ column ] = tag ;
$ ( td ) . html ( tag ) ;
td . html ( tag ) ;
colorCode ( ) ;
colorCode ( ) ;
notifyChange ( ) ;
notifyChange ( ) ;
} ;
} ;