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