public void readTstData ( String dataFile ) { if ( tstData != null ) { tstData . clear ( ) ; } else { tstData = new ArrayList ( ) ; } // open data file BufferedReader fin = null ; try { fin = new BufferedReader ( new InputStreamReader ( new FileInputStream ( dataFile ) , "UTF-8" ) ) ; System . out . println ( "Reading testing data ..." ) ; String line ; while ( ( line = fin . readLine ( ) ) != null ) { StringTokenizer strTok = new StringTokenizer ( line , " \t\r\n" ) ; int len = strTok . countTokens ( ) ; if ( len <= 1 ) { // skip this invalid line continue ; } List strCps = new ArrayList ( ) ; for ( int i = 0 ; i < len - 1 ; i ++ ) { strCps . add ( strTok . nextToken ( ) ) ; } String labelStr = strTok . nextToken ( ) ; List intCps = new ArrayList ( ) ; for ( int i = 0 ; i < strCps . size ( ) ; i ++ ) { String cpStr = ( String ) strCps . get ( i ) ; Integer cpInt = ( Integer ) cpStr2Int . get ( cpStr ) ; if ( cpInt != null ) { intCps . add ( cpInt ) ; } else { // do nothing } } Integer labelInt = ( Integer ) lbStr2Int . get ( labelStr ) ; if ( labelInt == null ) { System . out . println ( "Reading testing observation, label not found or invalid" ) ; return ; } int [ ] cps = new int [ intCps . size ( ) ] ; for ( int i = 0 ; i < cps . length ; i ++ ) { cps [ i ] = ( ( Integer ) intCps . get ( i ) ) . intValue ( ) ; } Observation obsr = new Observation ( labelInt . intValue ( ) , cps ) ; // add this observation to the data tstData . add ( obsr ) ; } System . out . println ( "Reading " + Integer . toString ( tstData . size ( ) ) + " testing data examples completed!" ) ; } catch ( IOException e ) { System . out . println ( e . toString ( ) ) ; return ; } option . numTestExps = tstData . size ( ) ; }
Read tst data .