Package com.csvreader

Examples of com.csvreader.CsvWriter


                    writableData.add(finalValues);
                }

            }
            FileWriter fileWriter = new FileWriter(resource.getFile(), false);
            CsvWriter csvWriter = new CsvWriter(fileWriter, COMMA_SEPARATOR);
            // finally we have the values in order to be written to the CSV file.
            for (String[] data : writableData) {
                csvWriter.writeRecord(data);
               
            }
            csvWriter.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }catch(Exception ex){
            throw new RuntimeException(ex);
View Full Code Here


        }
    }

    protected void saveFeatureWeights(List<Map.Entry<String, Double>> featureWeights, File outputFeatureWeightsFile) {
        try {
            CsvWriter writer = new CsvWriter(new FileWriter(outputFeatureWeightsFile), ',');

            writer.write("Feature");
            writer.write("Weight");
            writer.write("WeightSquared");
            writer.endRecord();

            for (Map.Entry<String, Double> entry : featureWeights) {
                writer.write(entry.getKey());
                writer.write(entry.getValue() + "");
                writer.write(entry.getValue() * entry.getValue() + "");
                writer.endRecord();
            }
            writer.close();
            System.out.println("Saved feature weights to " + outputFeatureWeightsFile);
        } catch (IOException e) {
            System.err.println("Error writing feature weights to " + outputFeatureWeightsFile);
            System.err.println("\t" + e.getMessage());
        }
View Full Code Here

        }
    }

    @Override
    public boolean save(OutputStream destination) throws IOException {
        CsvWriter out = new CsvWriter(destination, ',', Charset.forName("UTF-8"));

        out.write("Threshold");
        out.write("True Positive Rate");
        out.write("False Positive Rate");
        out.endRecord();

        for (int i = 0; i < size(); i++) {
            double threshold = getThresholdValue(i);
            double fpRate = getFalsePositiveRate(i);
            double tpRate = getTruePositiveRate(i);

            out.write("" + threshold);
            out.write("" + tpRate);
            out.write("" + fpRate);
            out.endRecord();
        }

        out.flush();
        return true;


    }
View Full Code Here

        }
       
        //Add a BOM for Excel
        destination.write(charset.encode("\ufeff").array());
       
        CsvWriter out = new CsvWriter(destination, ',', charset);
       
        String[] row = new String[NUM_OUTPUT_COLUMNS];
        row[ID_COLUMN] = ID_COLUMN_NAME;
        row[PARTICIPANT_COLUMN] = PARTICIPANT_COLUMN_NAME;
        row[TIME_COLUMN] = TIME_COLUMN_NAME;
        row[MESSAGE_COLUMN] = MESSAGE_COLUMN_NAME;
        row[TRUTH_COLUMN] = TRUTH_COLUMN_NAME;
        row[PREDICTION_COLUMN] = PREDICTION_COLUMN_NAME;
        row[CONFIDENCE_COLUMN] = CONFIDENCE_COLUMN_NAME;
        row[SEGMENT_COLUMN] = SEGMENT_COLUMN_NAME;

        out.writeRecord(row);

        for (Message message : messages) {
            row[ID_COLUMN] = Integer.toString(message.getId());
            row[PARTICIPANT_COLUMN] = message.getParticipant();
            row[TIME_COLUMN] = dateFormat.format(message.getTimestamp());
            row[MESSAGE_COLUMN] = message.getMessage();
            row[TRUTH_COLUMN] = message.hasTrueLabel() ? message.getTrueLabel().toString() : null;
            row[PREDICTION_COLUMN] = message.hasPredictedLabel() ? message.getPredictedLabel().toString() : null;
            row[CONFIDENCE_COLUMN] = message.hasPredictionConfidence() ? message.getPredictionConfidence().toString() : null;
            row[SEGMENT_COLUMN] = message.hasSegmentId() ? Integer.toString(message.getSegmentId()) : null;

            out.writeRecord(row);
        }

        out.flush();
        return true;
    }
View Full Code Here

     * @param pathToCsvFile
     * @return
     */
    public CsvWriter makeWriter(final String pathToCsvFile) {

        return new CsvWriter(pathToCsvFile);
    }
View Full Code Here

TOP

Related Classes of com.csvreader.CsvWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.