use of org.apache.commons.io.output.FileWriterWithEncoding in project dkpro-tc by dkpro.
the class LibsvmDataFormatOutcomeIdReport method execute.
@Override
public void execute() throws Exception {
init();
baslinePreparation();
Map<Integer, String> id2label = getId2LabelMapping(isRegression);
String header = buildHeader(id2label, isRegression);
List<String> predictions = readPredictions();
Map<String, String> index2instanceIdMap = getMapping(isUnit || isSequence);
Properties prop = new SortedKeyProperties();
int lineCounter = 0;
for (String line : predictions) {
if (line.startsWith("#")) {
continue;
}
String[] split = line.split(";");
String key = index2instanceIdMap.get(lineCounter + "");
String predictionString = getPrediction(split[0]);
String goldString = split[1];
if (isRegression) {
prop.setProperty(key, predictionString + ";" + goldString + ";" + THRESHOLD_CONSTANT);
} else {
int pred = Double.valueOf(predictionString).intValue();
int gold = Double.valueOf(goldString).intValue();
prop.setProperty(key, pred + ";" + gold + ";" + THRESHOLD_CONSTANT);
}
lineCounter++;
}
File targetFile = getTargetOutputFile();
FileWriterWithEncoding fw = null;
try {
fw = new FileWriterWithEncoding(targetFile, "utf-8");
prop.store(fw, header);
} finally {
IOUtils.closeQuietly(fw);
}
}
Aggregations