@ Override public void tag ( Annotation sentence ) { SequenceInput < Annotation > sequenceInput = new SequenceInput <> ( sentence . tokens ( ) ) ; Labeling result = labeler . label ( featurizer . extractSequence ( sequenceInput . iterator ( ) ) ) ; for ( int i = 0 ; i < sentence . tokenLength ( ) ; ) { if ( result . getLabel ( i ) . equals ( "O" ) ) { i ++ ; } else { Annotation start = sentence . tokenAt ( i ) ; String type = result . getLabel ( i ) . substring ( 2 ) ; i ++ ; while ( i < sentence . tokenLength ( ) && result . getLabel ( i ) . startsWith ( "I-" ) ) { i ++ ; } Annotation end = sentence . tokenAt ( i - 1 ) ; HString span = start . union ( end ) ; Annotation entity = sentence . document ( ) . annotationBuilder ( ) . type ( annotationType ) . bounds ( span ) . createAttached ( ) ; entity . put ( annotationType . getTagAttribute ( ) , annotationType . getTagAttribute ( ) . getValueType ( ) . decode ( type ) ) ; } } }
Tag labeling result .