Skip to content

Commit

Permalink
#536 - Outcome2IdReport - Gold and actual values do not correspond
Browse files Browse the repository at this point in the history
  • Loading branch information
Horsmann committed Feb 27, 2019
1 parent c486284 commit 71480f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -133,7 +134,7 @@ protected void baslinePreparation() throws Exception

private Map<String, String> getMapping(boolean isUnit) throws IOException
{

File f;
if (isUnit) {
f = new File(getContext().getFolder(TEST_TASK_INPUT_KEY_TEST_DATA, AccessMode.READONLY),
Expand All @@ -146,7 +147,7 @@ private Map<String, String> getMapping(boolean isUnit) throws IOException

Map<String, String> m = new HashMap<>();

int idx = 0;
int lineId = 0;
for (String l : FileUtils.readLines(f, UTF_8)) {
if (l.startsWith("#")) {
continue;
Expand All @@ -156,14 +157,22 @@ private Map<String, String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -150,7 +151,7 @@ protected String getPrediction(String string)

private Map<String, String> getMapping(boolean isUnit) throws IOException
{

File f;
if (isUnit) {
f = new File(getContext().getFolder(TEST_TASK_INPUT_KEY_TEST_DATA, AccessMode.READONLY),
Expand All @@ -163,7 +164,7 @@ private Map<String, String> getMapping(boolean isUnit) throws IOException

Map<String, String> m = new HashMap<>();

int idx = 0;
int lineId = 0;
for (String l : FileUtils.readLines(f, UTF_8)) {
if (l.startsWith("#")) {
continue;
Expand All @@ -172,15 +173,23 @@ private Map<String, String> 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;
}
Expand Down

0 comments on commit 71480f3

Please sign in to comment.