public void readDict ( BufferedReader fin ) throws IOException { dict . clear ( ) ; String line ; // get dictionary size if ( ( line = fin . readLine ( ) ) == null ) { System . out . println ( "No dictionary size information" ) ; return ; } int dictSize = Integer . parseInt ( line ) ; if ( dictSize <= 0 ) { System . out . println ( "Invalid dictionary size" ) ; } System . out . println ( "Reading dictionary ..." ) ; // main loop for reading dictionary content for ( int i = 0 ; i < dictSize ; i ++ ) { line = fin . readLine ( ) ; if ( line == null ) { System . out . println ( "Invalid dictionary line" ) ; return ; } StringTokenizer strTok = new StringTokenizer ( line , " \t\r\n" ) ; int len = strTok . countTokens ( ) ; if ( len < 2 ) { // invalid line continue ; } StringTokenizer cpTok = new StringTokenizer ( strTok . nextToken ( ) , ":" ) ; int cp = Integer . parseInt ( cpTok . nextToken ( ) ) ; int cpCount = Integer . parseInt ( cpTok . nextToken ( ) ) ; // create a new element Element elem = new Element ( ) ; elem . count = cpCount ; elem . chosen = 1 ; while ( strTok . hasMoreTokens ( ) ) { StringTokenizer lbTok = new StringTokenizer ( strTok . nextToken ( ) , ":" ) ; int label = Integer . parseInt ( lbTok . nextToken ( ) ) ; int count = Integer . parseInt ( lbTok . nextToken ( ) ) ; int fidx = Integer . parseInt ( lbTok . nextToken ( ) ) ; CountFIdx cntFIdx = new CountFIdx ( count , fidx ) ; elem . lbCntFidxes . put ( new Integer ( label ) , cntFIdx ) ; } // insert the element to the dictionary dict . put ( new Integer ( cp ) , elem ) ; } System . out . println ( "Reading dictionary (" + Integer . toString ( dict . size ( ) ) + " entries) completed!" ) ; // read the line ###... line = fin . readLine ( ) ; }
Read dict .