public static void printSVMLightFormat ( PrintWriter pw , ClassicCounter < Integer > c , int classNo ) { Integer [ ] features = c . keySet ( ) . toArray ( new Integer [ c . keySet ( ) . size ( ) ] ) ; Arrays . sort ( features ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( classNo ) ; sb . append ( ' ' ) ; for ( int f : features ) { sb . append ( f + 1 ) . append ( ' ' ) . append ( c . getCount ( f ) ) . append ( ' ' ) ; } pw . println ( sb . toString ( ) ) ; }
Need to sort the counter by feature keys and dump it