Search in sources :

Example 11 with FileWriterWithEncoding

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);
    }
}
Also used : FileWriterWithEncoding(org.apache.commons.io.output.FileWriterWithEncoding) SortedKeyProperties(org.dkpro.tc.ml.report.util.SortedKeyProperties) Properties(java.util.Properties) SortedKeyProperties(org.dkpro.tc.ml.report.util.SortedKeyProperties) File(java.io.File)

Aggregations

FileWriterWithEncoding (org.apache.commons.io.output.FileWriterWithEncoding)11 File (java.io.File)8 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)3 Properties (java.util.Properties)3 CSVWriter (au.com.bytecode.opencsv.CSVWriter)2 BufferedWriter (java.io.BufferedWriter)2 SortedKeyProperties (org.dkpro.tc.ml.report.util.SortedKeyProperties)2 QueryData (annis.ql.parser.QueryData)1 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)1 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ZipFile (java.util.zip.ZipFile)1 SAXSVGDocumentFactory (org.apache.batik.dom.svg.SAXSVGDocumentFactory)1 TranscoderInput (org.apache.batik.transcoder.TranscoderInput)1 TranscoderOutput (org.apache.batik.transcoder.TranscoderOutput)1 SVGTranscoder (org.apache.batik.transcoder.svg2svg.SVGTranscoder)1