protected void evaluate( Collection<EquivClassCandRanking> cands, Dictionary testDict, String outFileName) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(outFileName)); DecimalFormat df = new DecimalFormat("0.00"); writer.write("K\tAccuracy@TopK\tNumInDict"); writer.newLine(); Set<EquivalenceClass> goldTrans; double oneInTopK, total, accInTopK; for (int i = 0; i < K.length; i++) { oneInTopK = 0; total = 0; for (EquivClassCandRanking ranking : cands) { goldTrans = testDict.translate(ranking.getEqClass()); if (goldTrans != null) { oneInTopK += (ranking.numInTopK(goldTrans, K[i]) > 0) ? 1 : 0; total++; } } accInTopK = 100.0 * oneInTopK / total; writer.write(K[i] + "\t" + df.format(accInTopK) + "\t" + total); writer.newLine(); } writer.close(); }