List of usage examples for org.apache.commons.csv CSVRecord get
public String get(final String name)
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 . j a v a 2 s . c om }
From source file:net.javacrumbs.ccspring.common.CsvFileLogger.java
private static Message parseRecord(CSVRecord record) { return new Message(Message.Severity.valueOf(record.get(0)), record.get(1), Instant.parse(record.get(2))); }
From source file:net.javacrumbs.codecamp.boot.common.CsvFileLogger.java
private static Message parseRecord(CSVRecord record) { return new Message(Message.Severity.valueOf(record.get(0)), record.get(1), ZonedDateTime.parse(record.get(2))); }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.report.ConfusionMatrixTools.java
public static ConfusionMatrix tokenLevelPredictionsToConfusionMatrix(File predictionsFile) throws IOException { ConfusionMatrix cm = new ConfusionMatrix(); CSVParser csvParser = new CSVParser(new FileReader(predictionsFile), CSVFormat.DEFAULT.withCommentMarker('#')); for (CSVRecord csvRecord : csvParser) { // update confusion matrix cm.increaseValue(csvRecord.get(0), csvRecord.get(1)); }//from www. j av a 2 s. c o m return cm; }
From source file:com.twentyn.TargetMolecule.java
public static TargetMolecule fromCSVRecord(CSVRecord record) throws MolFormatException { String inchi = record.get("inchi"); String displayName = record.get("display_name"); String inchiKey = record.get("inchi_key"); String imageName = record.get("image_name"); Molecule mol = MolImporter.importMol(inchi); return new TargetMolecule(mol, inchi, displayName, inchiKey, imageName); }
From source file:br.edimarmanica.weir2.rule.Loader.java
/** * * @param rule//from w ww .jav a 2 s . c om * @param formatted valores formatados como na avaliao? * @return Map<PageId, Value> * */ public static Map<String, String> loadPageValues(File rule, boolean formatted) { Map<String, String> pageValues = new HashMap<>(); try (Reader in = new FileReader(rule.getAbsolutePath())) { try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL.withHeader())) { for (CSVRecord record : parser) { //para cada value String url = formatURL(record.get("URL")); String value = record.get("EXTRACTED VALUE"); if (formatted) { value = Formatter.formatValue(value); } if (!value.trim().isEmpty()) { pageValues.put(url, value); } } } } catch (FileNotFoundException ex) { Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex); } return pageValues; }
From source file:br.edimarmanica.weir2.rule.filter.RulesFilter.java
public static List<String> loadFilteredRules(Site site) { List<String> remainingRules = new ArrayList<>(); try (Reader in = new FileReader(new File(Paths.PATH_WEIR_V2 + "/" + site.getPath() + "/filter.csv"))) { try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL.withHeader())) { for (CSVRecord record : parser) { //para cada value remainingRules.add(record.get("RULE")); }//from ww w . j a va2 s . c o m } } catch (FileNotFoundException ex) { Logger.getLogger(RulesDataTypeController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RulesDataTypeController.class.getName()).log(Level.SEVERE, null, ex); } return remainingRules; }
From source file:de.upb.wdqa.wdvd.revisiontags.TagDownloader.java
/** * Reads one line of the csv file of the TagDownloader */// w w w . jav a 2 s . c om private static void parseRecord(CSVRecord record) { long revisionId = Long.parseLong(record.get(0)); // revision id String sha1Base16 = record.get(1); // sha1 //record.get(2); // size Set<DbTag> tags = new HashSet<DbTag>(); for (int i = 3; i < record.size(); i++) { String tagName = record.get(i); tags.add(tagFactory.getTag(tagName)); tagDistribution.addValue(tagName); } try { dataStore.putRevision(new DbRevisionImpl(revisionId, SHA1Converter.base16to36(sha1Base16), tags)); } catch (Exception e) { logger.error("", e); } }
From source file:ch.bfh.unicert.certimport.Main.java
/** * Create a certificate fot the given CSV record * * @param record the record to parse/* w w w .j ava2 s. c o m*/ * @throws InvalidNameException */ private static void createCertificate(CSVRecord record) throws InvalidNameException { int recordid = Integer.parseInt(record.get(0)); String pemCert = record.get(1); String institution = record.get(2); int revoked = Integer.parseInt(record.get(3)); if (revoked == 1) { System.out.println("Certficate " + recordid + " is revoked. Looking for next certificate..."); return; } String studyBranch = record.get(5); String uniqueId = record.get(6); String mail = record.get(8); CertificateFactory cf; X509Certificate cert; try { cf = CertificateFactory.getInstance("X.509"); cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(pemCert.getBytes())); } catch (CertificateException ex) { logger.log(Level.SEVERE, "Not able to read certificate for record {0}, exception: {1}", new Object[] { recordid, ex }); return; } DSAPublicKey pubKey = (DSAPublicKey) cert.getPublicKey(); String commonName = cert.getSubjectDN().getName(); LdapName ln = new LdapName(cert.getSubjectX500Principal().toString()); for (Rdn rdn : ln.getRdns()) { if (rdn.getType().equalsIgnoreCase("CN")) { commonName = (String) rdn.getValue(); break; } else if (rdn.getType().equalsIgnoreCase("UID")) { uniqueId = (String) rdn.getValue(); break; } else if (rdn.getType().equalsIgnoreCase("OU")) { studyBranch = (String) rdn.getValue(); break; } } IdentityData idData = new IdentityData(commonName, uniqueId, institution, studyBranch, null, null, null, null, null, "SwitchAAI", null); try { Certificate certificate = issuer.createClientCertificate(idData, keystorePath, pubKey, 10, "UniVote", new String[] { "Voter" }, uniBoardWSDLurl, uniBoardUrl, section); counter++; System.out.println("Certificate published for " + recordid + ". Count " + counter + " of 6424"); } catch (CertificateCreationException ex) { logger.log(Level.SEVERE, "Not able to create certificate for record {0}, exception: {1}", new Object[] { recordid, ex }); } }
From source file:de.upb.wdqa.wdvd.geolocation.GeolocationDatabase.java
/** * Reads one line of the csv file of the Geo Database *///from w ww. ja v a 2s . c om private static void parseRecord(CSVRecord record) { long startAdress = Long.parseLong(record.get(0)); long endAdress = Long.parseLong(record.get(1)); String countryCode = record.get(2); //String countryName = record.get(3); String continentCode = record.get(4); //String continentName = record.get(5); String timeZone = record.get(6); String regionCode = record.get(7); //String regionName = record.get(8); //String owner = record.get(9); String cityName = record.get(10); String countyName = record.get(11); //String latitude = record.get(12); //String longitude = record.get(13); GeoInformation geoInformation = new GeoInformation(startAdress, endAdress, countryCode, continentCode, timeZone, regionCode, cityName, countyName); treeMap.put(geoInformation.getStartAdress(), geoInformation); }