public static String autoGenerateStyleMap ( AnalysisEngineMetaData aTaeMetaData ) { // styles used in automatically generated style maps final String [ ] STYLES = { "color:black; background:lightblue;" , "color:black; background:lightgreen;" , "color:black; background:orange;" , "color:black; background:yellow;" , "color:black; background:pink;" , "color:black; background:salmon;" , "color:black; background:cyan;" , "color:black; background:violet;" , "color:black; background:tan;" , "color:white; background:brown;" , "color:white; background:blue;" , "color:white; background:green;" , "color:white; background:red;" , "color:white; background:mediumpurple;" } ; // get list of output types from TAE ArrayList outputTypes = new ArrayList ( ) ; Capability [ ] capabilities = aTaeMetaData . getCapabilities ( ) ; for ( int i = 0 ; i < capabilities . length ; i ++ ) { TypeOrFeature [ ] outputs = capabilities [ i ] . getOutputs ( ) ; for ( int j = 0 ; j < outputs . length ; j ++ ) { if ( outputs [ j ] . isType ( ) && ! outputTypes . contains ( outputs [ j ] . getName ( ) ) ) { outputTypes . add ( outputs [ j ] . getName ( ) ) ; } } } // generate style map by mapping each type to a background color StringBuffer buf = new StringBuffer ( ) ; buf . append ( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ) ; buf . append ( "<styleMap>\n" ) ; int i = 0 ; Iterator it = outputTypes . iterator ( ) ; while ( it . hasNext ( ) ) { String outputType = ( String ) it . next ( ) ; String label = outputType ; int lastDot = outputType . lastIndexOf ( ' ' ) ; if ( lastDot > - 1 ) { label = outputType . substring ( lastDot + 1 ) ; } buf . append ( "<rule>\n" ) ; buf . append ( "<pattern>" ) ; buf . append ( outputType ) ; buf . append ( "</pattern>\n" ) ; buf . append ( "<label>" ) ; buf . append ( label ) ; buf . append ( "</label>\n" ) ; buf . append ( "<style>" ) ; buf . append ( STYLES [ i % STYLES . length ] ) ; buf . append ( "</style>\n" ) ; buf . append ( "</rule>\n" ) ; i ++ ; } buf . append ( "</styleMap>\n" ) ; return buf . toString ( ) ; }
Automatically generates a style map for the given text analysis engine . The style map will be returned as an XML string .