Example usage for org.apache.commons.csv CSVRecord get

List of usage examples for org.apache.commons.csv CSVRecord get

Introduction

In this page you can find the example usage for org.apache.commons.csv CSVRecord get.

Prototype

public String get(final String name) 

Source Link

Document

Returns a value by name.

Usage

From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.report.TokenLevelBatchCrossValidationReport.java

protected void reportOnlyMacroFM() throws IOException {
    File aggregatedCSVFile = new File(
            getContext().getStorageLocation(Constants.TEST_TASK_OUTPUT_KEY, StorageService.AccessMode.READONLY),
            TokenLevelEvaluationReport.TOKEN_LEVEL_PREDICTIONS_CSV);

    // load the CSV
    CSVParser csvParser = new CSVParser(new FileReader(aggregatedCSVFile),
            CSVFormat.DEFAULT.withCommentMarker('#'));

    // compute confusion matrix
    ConfusionMatrix cm = new ConfusionMatrix();

    // and add the all rows
    for (CSVRecord csvRecord : csvParser) {
        // first item is the gold label
        String gold = csvRecord.get(0);
        // second item is the predicted label
        String predicted = csvRecord.get(1);

        cm.increaseValue(gold, predicted);
    }//from  ww  w. j  a  v  a2 s. c  om

    File evaluationFile = new File(getContext().getStorageLocation(Constants.TEST_TASK_OUTPUT_KEY,
            StorageService.AccessMode.READWRITE), RESULT_SUMMARY);

    ReportTools.printFMeasuresToFile(cm, evaluationFile);
}

From source file:com.ibm.g11n.pipeline.example.MultiBundleCSVFilter.java

@Override
public void merge(InputStream baseStream, OutputStream outStream, Map<String, LanguageBundle> languageBundles,
        FilterOptions options) throws IOException, ResourceFilterException {
    // create key-value map for each bundle
    Map<String, Map<String, String>> kvMaps = new HashMap<String, Map<String, String>>();
    for (Entry<String, LanguageBundle> bundleEntry : languageBundles.entrySet()) {
        LanguageBundle languageBundle = bundleEntry.getValue();
        Map<String, String> kvMap = new HashMap<String, String>();
        for (ResourceString resString : languageBundle.getResourceStrings()) {
            kvMap.put(resString.getKey(), resString.getValue());
        }/*www.ja v  a  2s .  c  om*/
        kvMaps.put(bundleEntry.getKey(), kvMap);
    }

    CSVParser parser = CSVParser.parse(baseStream, StandardCharsets.UTF_8,
            CSVFormat.RFC4180.withHeader("module", "key", "value").withSkipHeaderRecord(true));
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8));
    CSVPrinter printer = CSVFormat.RFC4180.withHeader("module", "key", "value").print(writer);
    for (CSVRecord record : parser) {
        String module = record.get(0);
        String key = record.get(1);
        String value = record.get(2);
        Map<String, String> moduleKVMap = kvMaps.get(module);
        if (moduleKVMap != null) {
            String trValue = moduleKVMap.get(key);
            if (trValue != null) {
                value = trValue;
            }
        }
        printer.printRecord(module, key, value);
    }
    printer.flush();
}

From source file:com.ctt.entity.Transaction.java

public Transaction(CSVRecord record) {
    try {//from ww w  . j  a va  2 s . c  o m
        System.out.println(record.get(0));
        String[] rr = record.get(0).split(";");

        System.out.println("0" + rr[0]);

        this.type_repayment = rr[0];

        this.type_id = rr[1];
        this.client_id = rr[2];
        this.value_transaction = Double.parseDouble(rr[3]);
        this.value_repayment = Double.parseDouble(rr[4]);
        this.tax = Double.parseDouble(rr[5]);
        this.type_tax = rr[6];
        this.code_bank = rr[7];
        this.card_number = rr[8];
        this.type_card = rr[9];

        this.isCreditCardTransaction = rr[10];

        this.dues = Integer.parseInt(rr[11]);

        if (rr.length >= 13)
            this.observations = rr[12];

    } catch (NumberFormatException ex) {
        Main.appendLog("Error: INIT TRANSACTION " + ex.getMessage());
    }

}

From source file:br.edimarmanica.trinity.intrasitemapping.manual.OffsetToRule.java

private void readMappings() {
    try (Reader in = new FileReader(Paths.PATH_TRINITY + site.getPath() + "/mappings.csv")) {
        try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL.withHeader())) {
            for (CSVRecord record : parser) {

                if (mappings.containsKey(record.get("OFFSET"))) {
                    mappings.get(record.get("OFFSET")).put(record.get("ATTRIBUTE"),
                            Integer.parseInt(record.get("GROUP")));
                } else {
                    Map<String, Integer> map = new HashMap<>();
                    map.put(record.get("ATTRIBUTE"), Integer.parseInt(record.get("GROUP")));
                    mappings.put(record.get("OFFSET"), map);
                }/*from   w  w w . ja v  a  2 s . c o  m*/
            }
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(OffsetToRule.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(OffsetToRule.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:br.edimarmanica.trinity.check.CheckOffsetRule.java

public void execute() {

    File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset");

    List<List<String>> offset = new ArrayList<>(); //cada arquivo  um offset

    try (Reader in = new FileReader(dir.getAbsoluteFile() + "/result_" + indexOffset + ".csv")) {
        try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) {
            int nrRegistro = 0;
            for (CSVRecord record : parser) {
                if (nrRegistro >= nrRegistros) {
                    break;
                }/* w w  w .j  a  v  a2 s. co  m*/

                System.out.println(record.get(0) + ";" + record.get(indexRule));
                nrRegistro++;
            }
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(CheckOffsetRule.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(CheckOffsetRule.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.itemanalysis.jmetrik.data.Scorer.java

private void readScoringFile(String fileName) throws IOException {
    File f = new File(fileName);
    CSVParser parser = null;/*from   ww w .j  av  a 2s.  com*/
    Reader reader = null;
    GenericItemScoring itemScoring = null;
    SpecialDataCodes specialCodes = null;
    String name = "";
    String option = "";
    int score = 0;
    try {
        reader = new InputStreamReader(new BOMInputStream(new FileInputStream(f)), "UTF-8");
        parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());

        for (CSVRecord csvRecord : parser) {
            name = csvRecord.get("name");
            option = csvRecord.get("option");
            score = Integer.parseInt(csvRecord.get("score"));

            itemScoring = new GenericItemScoring(name);
            itemScoring.addCategory(option, score);

            specialCodes = new SpecialDataCodes();

            if (csvRecord.isMapped("missing"))
                specialCodes.setMissingDataCode(csvRecord.get("missing"));
            if (csvRecord.isMapped("missing score"))
                specialCodes.setMissingDataScore(Integer.parseInt(csvRecord.get("missing score")));

            if (csvRecord.isMapped("notreached"))
                specialCodes.setMissingDataCode(csvRecord.get("notreached"));
            if (csvRecord.isMapped("notreached score"))
                specialCodes.setMissingDataScore(Integer.parseInt(csvRecord.get("notreached score")));

            if (csvRecord.isMapped("omitted"))
                specialCodes.setMissingDataCode(csvRecord.get("omitted"));
            if (csvRecord.isMapped("omitted score"))
                specialCodes.setMissingDataScore(Integer.parseInt(csvRecord.get("omitted score")));

            scoring.put(name, itemScoring);
        }
    } catch (IOException ex) {
        throw (ex);
    } finally {
        parser.close();
        reader.close();
    }

}

From source file:com.univocity.articles.csvcomparison.parser.CommonsCsvParser.java

@Override
public List<String[]> parseRows(File input) throws Exception {
    CSVFormat format = CSVFormat.RFC4180;
    CSVParser parser = CSVParser.parse(input, getEncoding(), format);

    List<String[]> rows = new ArrayList<String[]>();

    for (CSVRecord record : parser) {
        String[] row = new String[record.size()];
        for (int i = 0; i < row.length; i++) {
            row[i] = record.get(i);
        }//w ww.  j a  va2s.  c o m
        rows.add(row);
    }
    return rows;
}

From source file:de.speexx.jira.jan.service.issue.IssueCoreFieldConfigLoader.java

boolean fetchIgnore(final CSVRecord record) {
    assert record != null;

    final String ignore = record.get(IGNORE_HEADER);
    return Boolean.parseBoolean(ignore);
}

From source file:com.willwinder.universalgcodesender.utils.GrblLookups.java

public GrblLookups(String prefix) {
    String filename = prefix + "_" + Localization.loadedLocale() + ".csv";

    URL u = GrblLookups.class.getResource(pathFor(filename));
    if (u == null) {
        filename = prefix + "_en_US.csv";
    }/*from www .  ja v  a2s  .  c  o m*/

    try {
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(GrblLookups.class.getResourceAsStream(pathFor(filename))))) {
            Iterable<CSVRecord> records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(reader);
            for (CSVRecord record : records) {
                List<String> list = Lists.newArrayList(record.iterator());
                lookups.put(record.get(0), list.toArray(new String[0]));
            }
        }
    } catch (IOException ex) {
        System.out.println("Unable to load GRBL resources.");
        ex.printStackTrace();
    }
}

From source file:ColdestWeather.ColdestWeather.java

public double averageTemperatureWithHighHumidityInFile(CSVParser parser, int humidity) {
    double averageTemp = 0;
    int numDays = 0;
    for (CSVRecord currentRow : parser) {
        if (currentRow.get("Humidity") != "N/A") {
            int currentHumidity = Integer.parseInt(currentRow.get("Humidity"));
            if (currentHumidity >= humidity) {
                double currentTemp = Double.parseDouble(currentRow.get("TemperatureF"));
                averageTemp += currentTemp;
                numDays += 1;/*from w ww  .  j a  v  a 2s  .  c  o  m*/
            }
        }
    }
    if (numDays == 0) {
        System.out.println("No temperatures with that humidity");
    }
    return averageTemp / numDays;
}