private int init(File f) throws IOException {
  Runtime rt=Runtime.getRuntime();
  long prePhraseTableLoadMemUsed=rt.totalMemory() - rt.freeMemory();
  final long startTime=System.nanoTime();
  LineNumberReader reader=IOTools.getReaderFromFile(f);
  int numScores=-1;
  for (String line; (line=reader.readLine()) != null; ) {
    List<List<String>> fields=StringUtils.splitFieldsFast(line,CompiledPhraseTable.FIELD_DELIM);
    assert fields.size() == 5 : String.format("phrase table line %d has %d fields",reader.getLineNumber(),fields.size());
    Sequence<IString> source=IStrings.toIStringSequence(fields.get(0));
    Sequence<IString> target=IStrings.toIStringSequence(fields.get(1));
    String targetConstellation=StringUtils.join(fields.get(3));
    List<String> scoreList=fields.get(4);
    if (numScores < 0) {
      numScores=scoreList.size();
    }
 else     if (numScores != scoreList.size()) {
      throw new RuntimeException(String.format("Error (line %d): Each entry must have exactly the same number of translation\n" + "scores per line. Prior entries had %d, while the current entry has %d:",reader.getLineNumber(),numScores,scoreList.size()));
    }
    float[] scores;
    try {
      scores=IOTools.stringListToNumeric(scoreList);
    }
 catch (    NumberFormatException e) {
      e.printStackTrace();
      throw new RuntimeException(String.format("Number format error on line %d",reader.getLineNumber()));
    }
    if (targetConstellation.equals("")) {
      addEntry(source,target,null,scores);
    }
 else {
      addEntry(source,target,PhraseAlignment.getPhraseAlignment(targetConstellation),scores);
    }
    if (source.size() > longestSourcePhrase) {
      longestSourcePhrase=source.size();
    }
    if (target.size() > longestTargetPhrase) {
      longestTargetPhrase=target.size();
    }
  }
  reader.close();
  long postPhraseTableLoadMemUsed=rt.totalMemory() - rt.freeMemory();
  double elapsedTime=((double)System.nanoTime() - startTime) / 1e9;
  System.err.printf("Done loading phrase table: %s (mem used: %d MiB time: %.3f s)%n",f.getAbsolutePath(),(postPhraseTableLoadMemUsed - prePhraseTableLoadMemUsed) / (1024 * 1024),elapsedTime);
  System.err.println("Longest foreign phrase: " + longestSourcePhrase);
  return numScores;
}

private int init ( File f ) throws IOException { Runtime rt = Runtime . getRuntime ( ) ; long prePhraseTableLoadMemUsed = rt . totalMemory ( ) - rt . freeMemory ( ) ; final long startTime = System . nanoTime ( ) ; LineNumberReader reader = IOTools . getReaderFromFile ( f ) ; int numScores = - 1 ; for ( String line ; ( line = reader . readLine ( ) ) != null ; ) { List < List < String > > fields = StringUtils . splitFieldsFast ( line , CompiledPhraseTable . FIELD_DELIM ) ; assert fields . size ( ) == 5 : String . format ( "phrase table line %d has %d fields" , reader . getLineNumber ( ) , fields . size ( ) ) ; Sequence < IString > source = IStrings . toIStringSequence ( fields . get ( 0 ) ) ; Sequence < IString > target = IStrings . toIStringSequence ( fields . get ( 1 ) ) ; String targetConstellation = StringUtils . join ( fields . get ( 3 ) ) ; List < String > scoreList = fields . get ( 4 ) ; if ( numScores < 0 ) { numScores = scoreList . size ( ) ; } else if ( numScores != scoreList . size ( ) ) { throw new RuntimeException ( String . format ( "Error (line %d): Each entry must have exactly the same number of translation\n" + "scores per line. Prior entries had %d, while the current entry has %d:" , reader . getLineNumber ( ) , numScores , scoreList . size ( ) ) ) ; } float [ ] scores ; try { scores = IOTools . stringListToNumeric ( scoreList ) ; } catch ( NumberFormatException e ) { e . printStackTrace ( ) ; throw new RuntimeException ( String . format ( "Number format error on line %d" , reader . getLineNumber ( ) ) ) ; } if ( targetConstellation . equals ( "" ) ) { addEntry ( source , target , null , scores ) ; } else { addEntry ( source , target , PhraseAlignment . getPhraseAlignment ( targetConstellation ) , scores ) ; } if ( source . size ( ) > longestSourcePhrase ) { longestSourcePhrase = source . size ( ) ; } if ( target . size ( ) > longestTargetPhrase ) { longestTargetPhrase = target . size ( ) ; } } reader . close ( ) ; long postPhraseTableLoadMemUsed = rt . totalMemory ( ) - rt . freeMemory ( ) ; double elapsedTime = ( ( double ) System . nanoTime ( ) - startTime ) / 1e9 ; System . err . printf ( "Done loading phrase table: %s (mem used: %d MiB time: %.3f s)%n" , f . getAbsolutePath ( ) , ( postPhraseTableLoadMemUsed - prePhraseTableLoadMemUsed ) / ( 1024 * 1024 ) , elapsedTime ) ; System . err . println ( "Longest foreign phrase: " + longestSourcePhrase ) ; return numScores ; }
load the phrase table from file .
