List of usage examples for org.apache.commons.csv CSVFormat DEFAULT
CSVFormat DEFAULT
To view the source code for org.apache.commons.csv CSVFormat DEFAULT.
Click Source Link
From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingRouteDetailsDirectory.java
private static void parseRoutesFile(final Store<RouteIdKey, RouteDetails> store, final Reader routeReader) throws InterruptedException, IOException { final CSVParser routeParser = new CSVParser(routeReader, CSVFormat.DEFAULT.withHeader()); final List<CSVRecord> routeRecords = routeParser.getRecords(); for (final CSVRecord record : routeRecords) { String routeId = record.get("route_id"); String routeShortName = record.get("route_short_name"); String routeLongName = record.get("route_long_name"); populateRouteDetail(routeId, routeShortName, routeLongName, store); }//ww w .java 2 s . co m }
From source file:com.github.terma.fastselect.benchmark.PlayerFactoryApacheDrill.java
public PlayerFactoryApacheDrill() throws IOException, ClassNotFoundException { Class.forName("org.apache.drill.jdbc.Driver"); if (!dataPresent) { Writer appendable = new FileWriter(csvFile); csvPrinter = CSVFormat.DEFAULT.print(appendable); }/*from w w w.j a v a2 s . co m*/ }
From source file:io.ecarf.core.compress.callback.CommonsCsvCallback.java
@Override public void setOutput(Appendable out) throws IOException { this.printer = new CSVPrinter(out, CSVFormat.DEFAULT); }
From source file:com.streamsets.pipeline.lib.csv.TestOverrunCsvParser.java
private void testLimit(int limit, int lineLength) throws Exception { System.setProperty(OverrunReader.READ_LIMIT_SYS_PROP, "" + limit); String csv = "a," + Strings.repeat("b", lineLength) + ",c"; OverrunCsvParser parser = new OverrunCsvParser(new StringReader(csv), CSVFormat.DEFAULT, -1); Assert.assertNotNull(parser.read()); }
From source file:javalibs.CSVExtractor.java
/** * Writes the CSV to the path specified in the c'tor. Returns the absolute path to * the output CSV file/*ww w . j ava 2 s .c o m*/ * @return The absolute path to the output CSV file */ public String writeCSV() { BufferedWriter bw = null; CSVPrinter printer = null; try { bw = Files.newBufferedWriter(Paths.get(this.outCSV)); printer = new CSVPrinter(bw, CSVFormat.DEFAULT.withHeader(this.orderedExtractionCols)); } catch (IOException e) { log_.die(e); } log_.require(bw != null, "BufferedWriter cannot be null"); log_.require(printer != null, "CSVPrinter cannot be null"); for (CSVRecord rec : this.inRecords) { List<String> writerCells = new ArrayList<>(); for (String col : this.headersInOrder) { if (!this.extractionCols.contains(col)) continue; String colVal = null; try { colVal = rec.get(col); } catch (IllegalArgumentException e) { log_.err("Could not find column: " + col); log_.die(e); } writerCells.add(colVal); } try { printer.printRecord(writerCells.toArray()); } catch (IOException e) { log_.die(e); } } try { printer.flush(); } catch (IOException e) { log_.die(e); } return new File(this.outCSV).getAbsolutePath(); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.EvalHelper.java
/** * Reads predicted and gold data from predictions CSV file and fills&returns the confusion matrix * * @param csvPredictions predictions (gold; predicted) * @return matrix/*from ww w . jav a2 s.co m*/ */ public static ConfusionMatrix createConfusionMatrixFromCSVPredictions(File csvPredictions) throws IOException { CSVParser csvParser = new CSVParser(new FileReader(csvPredictions), CSVFormat.DEFAULT.withCommentMarker('#')); ConfusionMatrix result = new ConfusionMatrix(); for (CSVRecord csvRecord : csvParser) { // copy record // update confusion matrix result.increaseValue(csvRecord.get(0), csvRecord.get(1)); } return result; }
From source file:com.streamsets.pipeline.lib.csv.TestCsvParser.java
@Test public void testParserNoHeaders() throws Exception { CsvParser parser = new CsvParser(getReader("TestCsvParser-default.csv"), CSVFormat.DEFAULT, -1); Assert.assertArrayEquals(null, parser.getHeaders()); }
From source file:edu.emory.mathcs.nlp.zzz.CSVSentiment.java
public void categorize(String inputFile) throws Exception { CSVParser parser = new CSVParser(IOUtils.createBufferedReader(inputFile), CSVFormat.DEFAULT); List<CSVRecord> records = parser.getRecords(); List<NLPNode[]> document; String outputDir;// w ww .ja v a 2 s. c o m PrintStream fout; CSVRecord record; System.out.println(inputFile); for (int i = 0; i < records.size(); i++) { if (i == 0) continue; record = records.get(i); document = decode.decodeDocument(record.get(6)); document.get(0)[1].putFeat("sent", record.get(0)); outputDir = inputFile.substring(0, inputFile.length() - 4); fout = IOUtils.createBufferedPrintStream( outputDir + "/" + FileUtils.getBaseName(outputDir) + "_" + i + ".nlp"); for (NLPNode[] nodes : document) fout.println(decode.toString(nodes) + "\n"); fout.close(); } parser.close(); }
From source file:com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.TrainingDataUtilsTest.java
/** * Test conversion from CSV to training data. *//*from www . j a v a 2 s.c om*/ @Test public void testToTrainingData() { File file = new File("src/test/resources/weather_data_train.csv"); List<TrainingData> trainingData = TrainingDataUtils.fromCSV(file, CSVFormat.DEFAULT); Assert.assertNotNull(trainingData); Assert.assertNotEquals(0, trainingData.size()); }
From source file:com.graphaware.importer.data.access.CsvDataReader.java
/** * {@inheritDoc}//w w w . j a v a 2s. c om */ @Override public void read(String connectionString, String hint) { if (records != null) { throw new IllegalStateException("Previous reader hasn't been closed"); } try { in = new FileReader(connectionString); records = CSVFormat.DEFAULT.withDelimiter(delimiter).withQuote(quote).withHeader().parse(in).iterator(); } catch (Exception e) { throw new RuntimeException(e); } }