diff --git a/dkpro-tc-io-libsvm/src/main/java/org/dkpro/tc/io/libsvm/reports/LibsvmDataFormatOutcomeIdReport.java b/dkpro-tc-io-libsvm/src/main/java/org/dkpro/tc/io/libsvm/reports/LibsvmDataFormatOutcomeIdReport.java index b6f0c70af..b5f8ddaa6 100644 --- a/dkpro-tc-io-libsvm/src/main/java/org/dkpro/tc/io/libsvm/reports/LibsvmDataFormatOutcomeIdReport.java +++ b/dkpro-tc-io-libsvm/src/main/java/org/dkpro/tc/io/libsvm/reports/LibsvmDataFormatOutcomeIdReport.java @@ -17,6 +17,8 @@ ******************************************************************************/ package org.dkpro.tc.io.libsvm.reports; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -35,7 +37,6 @@ import org.dkpro.tc.io.libsvm.AdapterFormat; import org.dkpro.tc.io.libsvm.LibsvmDataFormatWriter; import org.dkpro.tc.ml.report.TcAbstractReport; -import static java.nio.charset.StandardCharsets.UTF_8; public class LibsvmDataFormatOutcomeIdReport extends TcAbstractReport @@ -133,7 +134,7 @@ protected void baslinePreparation() throws Exception private Map getMapping(boolean isUnit) throws IOException { - + File f; if (isUnit) { f = new File(getContext().getFolder(TEST_TASK_INPUT_KEY_TEST_DATA, AccessMode.READONLY), @@ -146,7 +147,7 @@ private Map getMapping(boolean isUnit) throws IOException Map m = new HashMap<>(); - int idx = 0; + int lineId = 0; for (String l : FileUtils.readLines(f, UTF_8)) { if (l.startsWith("#")) { continue; @@ -156,14 +157,22 @@ private Map getMapping(boolean isUnit) throws IOException } String[] split = l.split("\t"); + String key = null; + if (isUnit) { + key = split[0]; + } + else { + key = lineId + ""; + } + //not title set in the reader that could be retrieved String value=""; if(split.length >= 2) { value = split[1]; } - m.put(idx + "", value.isEmpty() ? idx + "" : value); - idx++; + m.put(key, value.isEmpty() ? lineId + "" : value); + lineId++; } return m; } diff --git a/dkpro-tc-ml-vowpalwabbit/src/main/java/org/dkpro/tc/ml/vowpalwabbit/report/VowpalWabbitOutcomeIDReport.java b/dkpro-tc-ml-vowpalwabbit/src/main/java/org/dkpro/tc/ml/vowpalwabbit/report/VowpalWabbitOutcomeIDReport.java index 562f235ad..fd5cd7d3c 100644 --- a/dkpro-tc-ml-vowpalwabbit/src/main/java/org/dkpro/tc/ml/vowpalwabbit/report/VowpalWabbitOutcomeIDReport.java +++ b/dkpro-tc-ml-vowpalwabbit/src/main/java/org/dkpro/tc/ml/vowpalwabbit/report/VowpalWabbitOutcomeIDReport.java @@ -17,6 +17,8 @@ ******************************************************************************/ package org.dkpro.tc.ml.vowpalwabbit.report; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -38,7 +40,6 @@ import org.dkpro.tc.core.Constants; import org.dkpro.tc.ml.report.TcAbstractReport; import org.dkpro.tc.ml.vowpalwabbit.writer.VowpalWabbitDataWriter; -import static java.nio.charset.StandardCharsets.UTF_8; /** * Writes a instanceId / outcome data for each classification instance. @@ -150,7 +151,7 @@ protected String getPrediction(String string) private Map getMapping(boolean isUnit) throws IOException { - + File f; if (isUnit) { f = new File(getContext().getFolder(TEST_TASK_INPUT_KEY_TEST_DATA, AccessMode.READONLY), @@ -163,7 +164,7 @@ private Map getMapping(boolean isUnit) throws IOException Map m = new HashMap<>(); - int idx = 0; + int lineId = 0; for (String l : FileUtils.readLines(f, UTF_8)) { if (l.startsWith("#")) { continue; @@ -172,15 +173,23 @@ private Map getMapping(boolean isUnit) throws IOException continue; } String[] split = l.split("\t"); - - // not title set in the reader that could be retrieved - String value = ""; - if (split.length >= 2) { + + String key = null; + if (isUnit) { + key = split[0]; + } + else { + key = lineId + ""; + } + + //not title set in the reader that could be retrieved + String value=""; + if(split.length >= 2) { value = split[1]; } - m.put(idx + "", value.isEmpty() ? idx + "" : value); - idx++; + m.put(key, value.isEmpty() ? lineId + "" : value); + lineId++; } return m; }