List of usage examples for org.apache.commons.csv CSVRecord get
public String get(final String name)
From source file:com.siemens.sw360.importer.ComponentAttachmentCSVRecordBuilder.java
ComponentAttachmentCSVRecordBuilder(CSVRecord record) { //parse CSV Record int i = 0;/*from www .ja va2 s . com*/ componentName = record.get(i++); releaseName = record.get(i++); releaseVersion = record.get(i++); attachmentContentId = record.get(i++); filename = record.get(i++); attachmentType = record.get(i++); comment = record.get(i++); createdOn = record.get(i++); createdBy = record.get(i); }
From source file:biz.itcons.wsdm.hw2_2.NaiveBayes.java
/** * Fills NaiveBayes with data for classification. * * @param file a CSV file with documents that are classified. * @param classifierPos a position in CSV file where classification is * stored (zero based indexing)//from w w w . j a v a 2 s . com * @param documentPos a position in CSV file where document body is stored * (zero based indexing) * @throws FileNotFoundException * @throws IOException */ public void trainingDataSet(String file, int classifierPos, int documentPos) throws FileNotFoundException, IOException { try (Reader in = new FileReader(file)) { LOGGER.debug("Opening training data set: " + file); globalTrainingCount = 0; for (CSVRecord record : CSVFormat.EXCEL.parse(in)) { String classifier = record.get(classifierPos); globalTrainingCount++; if (parsedEntries.containsKey(classifier)) { parsedEntries.get(classifier).addDocument(record.get(documentPos)); } else { ClassificationItem ci = new ClassificationItem(classifier); ci.addDocument(record.get(documentPos)); parsedEntries.put(classifier, ci); } } LOGGER.trace("Read " + globalTrainingCount + " from training set"); } }
From source file:cinematicketsim.MovieClassParser.java
public ArrayList<Movie> loadMovies(String filename) { ArrayList<Movie> movieList = new ArrayList<Movie>(); try {/*w w w . j a v a 2 s . co m*/ File f = new File(filename); filename = f.getCanonicalPath(); } catch (Exception e) { e.printStackTrace(); } FileResource file = new FileResource(filename); CSVParser parser = file.getCSVParser(); for (CSVRecord record : parser) { String movieId = record.get("id"); String movieTitle = record.get("title"); String movieYear = record.get("year"); String movieCountry = record.get("country"); String movieGenre = record.get("genre"); String movieDirector = record.get("director"); int movieMinutes = Integer.parseInt(record.get("minutes")); String moviePoster = record.get("poster"); Movie movie = new Movie(movieId, movieTitle, movieYear, movieGenre, movieDirector, movieCountry, moviePoster, movieMinutes); movieList.add(movie); } for (Movie temp : movieList) { String movieId = temp.getID(); String movieTitle = temp.getTitle(); idToMovies.put(movieId, movieTitle); } return movieList; }
From source file:br.edimarmanica.trinity.intrasitemapping.manual.OffsetToRule.java
public void execute() { readMappings();/*from w w w . j a va 2 s . c o m*/ File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset"); for (File offset : dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".csv"); } })) { try (Reader in = new FileReader(offset)) { try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) { for (CSVRecord record : parser) { String page = record.get(0); if (pages.contains(page)) { continue; } else { pages.add(page); } List<String> dataRecord = new ArrayList<>(); for (Attribute attr : site.getDomain().getAttributes()) { try { int group = mappings.get(offset.getName()).get(attr.getAttributeID()); if (group != -1) { dataRecord.add(record.get(group)); } else { dataRecord.add(""); } } catch (Exception ex) { dataRecord.add(""); } } print(page, dataRecord); } } } catch (FileNotFoundException ex) { Logger.getLogger(Mapping.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Mapping.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:cinematicketsim.MovieClassParser.java
public ArrayList<Movie> getMovie(String filename, String name) { ArrayList<Movie> movieList = new ArrayList<Movie>(); try {//from ww w . j a v a2 s . c o m File f = new File(filename); filename = f.getCanonicalPath(); } catch (Exception e) { e.printStackTrace(); } FileResource file = new FileResource(filename); CSVParser parser = file.getCSVParser(); for (CSVRecord record : parser) { String movieId = record.get("id"); String movieTitle = record.get("title"); String movieYear = record.get("year"); String movieCountry = record.get("country"); String movieGenre = record.get("genre"); String movieDirector = record.get("director"); int movieMinutes = Integer.parseInt(record.get("minutes")); String moviePoster = record.get("poster"); Movie movie = new Movie(movieId, movieTitle, movieYear, movieGenre, movieDirector, movieCountry, moviePoster, movieMinutes); movieList.add(movie); } ArrayList<Movie> movieSearch = new ArrayList<Movie>(); String smallName = name.toLowerCase(); for (Movie temp : movieList) { String tempName = temp.getTitle(); String lowerTempName = tempName.toLowerCase(); if (lowerTempName.equals(smallName)) { movieSearch.add(temp); } } return movieSearch; }
From source file:com.garethahealy.quotalimitsgenerator.cli.parsers.DefaultCLIParser.java
private Map<String, Pair<Integer, Integer>> parseLines(String instanceTypeCsv) throws IOException, URISyntaxException, ParseException { InputStreamReader inputStreamReader; if (instanceTypeCsv.equalsIgnoreCase("classpath")) { inputStreamReader = new InputStreamReader( getClass().getClassLoader().getResourceAsStream("instancetypes.csv"), Charset.forName("UTF-8")); } else {/*from www . j av a2 s .c o m*/ URI uri = new URI(instanceTypeCsv); inputStreamReader = new InputStreamReader(new FileInputStream(new File(uri)), Charset.forName("UTF-8")); } CSVParser parser = null; List<CSVRecord> lines = null; try { parser = CSVFormat.DEFAULT.parse(new BufferedReader(inputStreamReader)); lines = parser.getRecords(); } finally { inputStreamReader.close(); if (parser != null) { parser.close(); } } if (lines == null || lines.size() <= 0) { throw new ParseException("instance-type-csv data is empty"); } Map<String, Pair<Integer, Integer>> linesMap = new HashMap<String, Pair<Integer, Integer>>(); for (CSVRecord current : lines) { linesMap.put(current.get(1), new ImmutablePair<Integer, Integer>(Integer.parseInt(current.get(2)), Integer.parseInt(current.get(3)))); } return linesMap; }
From source file:edu.emory.cci.aiw.i2b2etl.ksb.ValueSetSupport.java
void parseId(String id) throws ParseException { try (CSVParser csvParser = CSVParser.parse(id, CSV_FORMAT)) { List<CSVRecord> records = csvParser.getRecords(); if (records.size() != 1) { return; }//from w w w . j a va 2 s.c om CSVRecord record = records.get(0); if (record.size() != 2) { return; } this.declaringPropId = record.get(0); this.propertyName = record.get(1); } catch (IOException invalid) { throw new ParseException("Invalid value set id " + id, 0); } }
From source file:de.upb.wdqa.wdvd.processors.decorators.GeolocationFeatureProcessor.java
private GeoInformation getGeoInformationForRevision(long revisionId, CSVRecord csvRevision) { long csvRevisionId = Long.parseLong(csvRevision.get("revisionId")); if (revisionId != csvRevisionId) { logger.error("geolocation feature file is out of sync"); }//from w ww . ja va 2s . com // not contained in feature file (only in geolocation database) long startAddress = -1; long endAddress = -1; String userCountry = getValue(csvRevision, "userCountry"); String userContinentCode = getValue(csvRevision, "userContinent"); String userTimeZone = getValue(csvRevision, "userTimeZone"); String userRegionCode = getValue(csvRevision, "userRegion"); String userCityName = getValue(csvRevision, "userCity"); String userCountyName = getValue(csvRevision, "userCounty"); GeoInformation result; if (userCountry != null || userContinentCode != null || userTimeZone != null || userRegionCode != null || userCityName != null || userCountyName != null) { result = new GeoInformation(startAddress, endAddress, userCountry, userContinentCode, userTimeZone, userRegionCode, userCityName, userCountyName); } else { result = null; } return result; }
From source file:edu.uiowa.icts.bluebutton.dao.LoincCodeCategoryHome.java
@Override public void importCSV(InputStream fileInputStream) throws IOException { Reader in = new BufferedReader(new InputStreamReader(fileInputStream)); Iterable<CSVRecord> records = CSVFormat.EXCEL .withHeader("PATH_TO_ROOT", "SEQUENCE", "IMMEDIATE_PARENT", "CODE", "CODE_TEXT") .withSkipHeaderRecord(true).parse(in); Map<String, String> codeTextMap = new HashMap<String, String>(); for (CSVRecord record : records) { LoincCodeCategory lcc = new LoincCodeCategory(); lcc.setLoincCode(record.get("CODE")); lcc.setName(record.get("CODE_TEXT")); codeTextMap.put(record.get("CODE"), record.get("CODE_TEXT")); if (!record.get("PATH_TO_ROOT").equals("")) { String[] rootName = record.get("PATH_TO_ROOT").split("\\."); lcc.setRootCategoryName(codeTextMap.get(rootName[0])); if (rootName.length > 1) { lcc.setSubrootCategoryName(codeTextMap.get(rootName[1])); }/* w ww . j av a2 s. c om*/ } this.sessionFactory.getCurrentSession().save(lcc); } }
From source file:ColdestWeather.ColdestWeather.java
public double averageTemperatureInFile(CSVParser parser) { double averageTemp = 0; int numDays = 0; for (CSVRecord currentRow : parser) { double currentTemp = Double.parseDouble(currentRow.get("TemperatureF")); averageTemp += currentTemp;//from ww w .j a va 2 s .c o m numDays += 1; } return averageTemp / numDays; }