@ Override public void outputText ( SDocumentGraph graph , boolean alignmc , int matchNumber , Writer out ) throws IOException , IllegalArgumentException { // first match if ( matchNumber == 0 ) { // output header List < String > headerLine = new ArrayList <> ( ) ; for ( Map . Entry < Integer , TreeSet < String > > match : annotationsForMatchedNodes . entrySet ( ) ) { int node_id = match . getKey ( ) ; headerLine . add ( String . valueOf ( node_id ) + "_id" ) ; headerLine . add ( String . valueOf ( node_id ) + "_span" ) ; for ( String annoName : match . getValue ( ) ) { headerLine . add ( String . valueOf ( node_id ) + "_anno_" + annoName ) ; } } for ( String key : metakeys ) { headerLine . add ( "meta_" + key ) ; } out . append ( StringUtils . join ( headerLine , "\t" ) ) ; out . append ( "\n" ) ; } // output nodes in the order of the matches SortedMap < Integer , String > contentLine = new TreeMap <> ( ) ; for ( SNode node : this . getMatchedNodes ( graph ) ) { List < String > nodeLine = new ArrayList <> ( ) ; // export id RelannisNodeFeature feats = RelannisNodeFeature . extract ( node ) ; nodeLine . add ( String . valueOf ( feats . getInternalID ( ) ) ) ; // export spanned text String span = graph . getText ( node ) ; if ( span != null ) nodeLine . add ( graph . getText ( node ) ) ; else nodeLine . add ( "" ) ; // export annotations int node_id = node . getFeature ( AnnisConstants . ANNIS_NS , AnnisConstants . FEAT_MATCHEDNODE ) . getValue_SNUMERIC ( ) . intValue ( ) ; for ( String annoName : annotationsForMatchedNodes . get ( node_id ) ) { SAnnotation anno = node . getAnnotation ( annoName ) ; if ( anno != null ) { nodeLine . add ( anno . getValue_STEXT ( ) ) ; } else nodeLine . add ( "'NULL'" ) ; } // add everything to line contentLine . put ( node_id , StringUtils . join ( nodeLine , "\t" ) ) ; } out . append ( StringUtils . join ( contentLine . values ( ) , "\t" ) ) ; // export Metadata // TODO cache the metadata if ( ! metakeys . isEmpty ( ) ) { // TODO is this the best way to get the corpus name? String corpus_name = CommonHelper . getCorpusPath ( java . net . URI . create ( graph . getDocument ( ) . getId ( ) ) ) . get ( 0 ) ; List < Annotation > asList = Helper . getMetaData ( corpus_name , graph . getDocument ( ) . getName ( ) ) ; for ( Annotation anno : asList ) { if ( metakeys . contains ( anno . getName ( ) ) ) out . append ( "\t" + anno . getValue ( ) ) ; } } out . append ( "\n" ) ; }
Takes a match and outputs a csv - line