private void scoreLex(SampledRule rule){
  double lex_f_e=1.0;
  for (int i=rule.srcStartInclusive; i < rule.srcEndExclusive; ++i) {
    final int srcId=rule.sentencePair.source(i);
    double feSum=0.0;
    if (rule.sentencePair.isSourceUnaligned(i)) {
      int c_f_e=coocTable.getJointCount(srcId,LexCoocTable.NULL_ID);
      int c_e=coocTable.getTgtMarginal(LexCoocTable.NULL_ID);
      feSum=c_f_e / (double)c_e;
    }
 else {
      int[] tgtAlign=rule.sentencePair.f2e(i);
      for (      int j : tgtAlign) {
        int tgtId=rule.sentencePair.target(j);
        int c_f_e=coocTable.getJointCount(srcId,tgtId);
        int c_e=coocTable.getTgtMarginal(tgtId);
        feSum+=(c_f_e / (double)c_e);
      }
      feSum/=(double)tgtAlign.length;
    }
    if (feSum == 0.0)     feSum=MIN_LEX_PROB;
    lex_f_e*=feSum;
  }
  assert lex_f_e >= 0 && lex_f_e <= 1.0;
  double lex_e_f=1.0;
  for (int i=rule.tgtStartInclusive; i < rule.tgtEndExclusive; ++i) {
    final int tgtId=rule.sentencePair.target(i);
    double efSum=0.0;
    if (rule.sentencePair.isTargetUnaligned(i)) {
      int c_e_f=coocTable.getJointCount(LexCoocTable.NULL_ID,tgtId);
      int c_f=coocTable.getSrcMarginal(LexCoocTable.NULL_ID);
      efSum=c_e_f / (double)c_f;
    }
 else {
      int[] srcAlign=rule.sentencePair.e2f(i);
      for (      int j : srcAlign) {
        final int srcId=rule.sentencePair.source(j);
        int c_e_f=coocTable.getJointCount(srcId,tgtId);
        int c_f=coocTable.getSrcMarginal(srcId);
        efSum+=(c_e_f / (double)c_f);
      }
      efSum/=(double)srcAlign.length;
    }
    if (efSum == 0.0)     efSum=MIN_LEX_PROB;
    lex_e_f*=efSum;
  }
  assert lex_e_f >= 0.0 && lex_e_f <= 1.0;
  rule.lex_e_f=lex_e_f;
  rule.lex_f_e=lex_f_e;
}

private void scoreLex ( SampledRule rule ) { double lex_f_e = 1.0 ; for ( int i = rule . srcStartInclusive ; i < rule . srcEndExclusive ; ++ i ) { final int srcId = rule . sentencePair . source ( i ) ; double feSum = 0.0 ; if ( rule . sentencePair . isSourceUnaligned ( i ) ) { int c_f_e = coocTable . getJointCount ( srcId , LexCoocTable . NULL_ID ) ; int c_e = coocTable . getTgtMarginal ( LexCoocTable . NULL_ID ) ; feSum = c_f_e / ( double ) c_e ; } else { int [ ] tgtAlign = rule . sentencePair . f2e ( i ) ; for ( int j : tgtAlign ) { int tgtId = rule . sentencePair . target ( j ) ; int c_f_e = coocTable . getJointCount ( srcId , tgtId ) ; int c_e = coocTable . getTgtMarginal ( tgtId ) ; feSum += ( c_f_e / ( double ) c_e ) ; } feSum /= ( double ) tgtAlign . length ; } if ( feSum == 0.0 ) feSum = MIN_LEX_PROB ; lex_f_e *= feSum ; } assert lex_f_e >= 0 && lex_f_e <= 1.0 ; double lex_e_f = 1.0 ; for ( int i = rule . tgtStartInclusive ; i < rule . tgtEndExclusive ; ++ i ) { final int tgtId = rule . sentencePair . target ( i ) ; double efSum = 0.0 ; if ( rule . sentencePair . isTargetUnaligned ( i ) ) { int c_e_f = coocTable . getJointCount ( LexCoocTable . NULL_ID , tgtId ) ; int c_f = coocTable . getSrcMarginal ( LexCoocTable . NULL_ID ) ; efSum = c_e_f / ( double ) c_f ; } else { int [ ] srcAlign = rule . sentencePair . e2f ( i ) ; for ( int j : srcAlign ) { final int srcId = rule . sentencePair . source ( j ) ; int c_e_f = coocTable . getJointCount ( srcId , tgtId ) ; int c_f = coocTable . getSrcMarginal ( srcId ) ; efSum += ( c_e_f / ( double ) c_f ) ; } efSum /= ( double ) srcAlign . length ; } if ( efSum == 0.0 ) efSum = MIN_LEX_PROB ; lex_e_f *= efSum ; } assert lex_e_f >= 0.0 && lex_e_f <= 1.0 ; rule . lex_e_f = lex_e_f ; rule . lex_f_e = lex_f_e ; }
compute dense lexical probabilities from the table of global co - occurrences .
