List of usage examples for org.apache.commons.csv CSVRecord isMapped
public boolean isMapped(final String name)
From source file:com.hack23.cia.service.external.vdem.impl.VdemServiceImpl.java
/** * Adds the question data to list.//from w ww. j ava 2 s .c om * * @param list * the list * @param record * the record * @param countryName * the country name * @param countryId * the country id * @param countryTextId * the country text id * @param year * the year * @param gapStart * the gap start * @param gapEnd * the gap end * @param codingEnd * the coding end * @param cowCode * the cow code * @param question * the question */ private static void addQuestionDataToList(final List<CountryQuestionData> list, final CSVRecord record, final String countryName, final String countryId, final String countryTextId, final String year, final String gapStart, final String gapEnd, final String codingEnd, final String cowCode, final Question question) { if (question.getQuestionId() != null) { if (record.isMapped(question.getTag())) { try { final String questionValue = record.get(question.getTag()); if (questionValue != null && StringUtils.hasText(questionValue)) { final CountryQuestionData countryQuestionData = new CountryQuestionData(); final CountryQuestionDataEmbeddedId embeddedId = new CountryQuestionDataEmbeddedId(); embeddedId.setCountryName(countryName); embeddedId.setCountryId(countryId); embeddedId.setIndicatorId(question.getTag()); embeddedId.setYear(Integer.parseInt(year)); embeddedId.setCountryId(countryId); countryQuestionData.setEmbeddedId(embeddedId); countryQuestionData.setCountryTextId(countryTextId); countryQuestionData.setGapstart(gapStart); countryQuestionData.setGapend(gapEnd); countryQuestionData.setCodingend(codingEnd); countryQuestionData.setCowCode(cowCode); countryQuestionData.setQuestionValue(questionValue.trim()); list.add(countryQuestionData); } } catch (final RuntimeException e) { LOGGER.warn("Missing value for:" + question.getTag(), e); } } } }
From source file:biz.ganttproject.impex.csv.RecordGroup.java
protected String getOrNull(CSVRecord record, String columnName) { if (!record.isMapped(columnName)) { return null; }/*from w w w .j a v a2 s .c o m*/ return record.get(columnName); }
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 www . j a va 2 s .c o m*/ 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:no.uio.medicine.virsurveillance.parsers.CSVsGBDdata.java
public void parse(String deathFolder) throws IOException { File f = new File(deathFolder); Runtime runtime = Runtime.getRuntime(); if (f.isDirectory()) { String[] filesInDir = f.list(); for (String fil : filesInDir) { if (fil.endsWith(".zip")) { ZipFile zipFile = new ZipFile(deathFolder + "/" + fil); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { System.out.println( "Used memory: " + (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024) + " Free memory: " + (runtime.freeMemory()) / (1024 * 1024)); ZipEntry entry = entries.nextElement(); InputStream stream = zipFile.getInputStream(entry); BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8")); CSVParser parser = CSVFormat.RFC4180.withDelimiter(',').withIgnoreEmptyLines().withHeader() .parse(br);//from ww w. ja v a 2 s. co m List<CSVRecord> records = parser.getRecords(); System.out.println("Reading records: " + zipFile.getName() + "/" + entry); /*for (int i=0;i<records.size();i++) { CSVRecord csvRecord = records.get(i);*/ for (CSVRecord csvRecord : records) { if (csvRecord.isMapped("age_group_id")) { //age group 22 corresponds to all ages if (csvRecord.get("age_group_id").equalsIgnoreCase("22")) { String location = null; String year = null; String sex = null; String cause = null; String number = null; String metric = null; if (csvRecord.isMapped("location_code")) { location = csvRecord.get("location_code"); } if (csvRecord.isMapped("year")) { year = csvRecord.get("year"); } if (csvRecord.isMapped("sex_id")) { //1=male, 2 = female if (csvRecord.get("sex_id").equalsIgnoreCase(("1"))) { sex = "m"; } else if (csvRecord.get("sex_id").equalsIgnoreCase("2")) { sex = "f"; } } if (csvRecord.isMapped("cause_name")) { cause = csvRecord.get("cause_name"); } if (csvRecord.isMapped("mean")) { number = csvRecord.get("mean"); } if (csvRecord.isMapped("metric") && csvRecord.isMapped("unit")) { metric = csvRecord.get("metric") + "-" + csvRecord.get("unit"); } if (location != null && year != null && sex != null && cause != null && number != null && metric != null) { try { sqlM.addSanitaryIssueToCountry(location, year, sex, cause, metric, number); } catch (SQLException ex) { Logger.getLogger(CSVsGBDdata.class.getName()).log(Level.SEVERE, null, ex); } } } } } parser.close(); stream.close(); br.close(); } zipFile.close(); } } } else { System.out.println("Not a directory"); } }
From source file:no.uio.medicine.virsurveillance.parsers.CSVVirusNames.java
public ArrayList<String> getVirusNames(String inputVirusFile) throws FileNotFoundException, IOException { ArrayList<String> viruses = new ArrayList<>(); BufferedReader reader = new BufferedReader(new FileReader(inputVirusFile)); CSVParser parser = CSVFormat.RFC4180.withDelimiter(';').withIgnoreEmptyLines().withHeader().parse(reader); for (CSVRecord csvRecord : parser) { if (csvRecord.isMapped("Virus Name")) { String currentVirus = csvRecord.get("Virus Name").replace(" virus", "").replace("", "%%"); viruses.add(currentVirus);// www. java 2s . com } } return viruses; }
From source file:no.uio.medicine.virsurveillance.parsers.CsvWosParser.java
public void parse(String inputPath) { try {/*from www . j a v a2s. c o m*/ int year = 2014;//default value BufferedReader reader = new BufferedReader(new FileReader(inputPath)); String line = reader.readLine(); // Read the first/current line. try { if (line.contains("Selected JCR Year:")) { String[] splitedLine = line.split("Selected JCR Year:"); year = Integer.parseInt(splitedLine[1].split(" ")[1]); } } catch (Exception e) { System.out.println("Journal Citation year selected by default: " + year); Logger.getLogger(CsvWosParser.class.getName()).log(Level.WARNING, "Journal Citation year selected by default: " + year, e); } CSVParser parser = CSVFormat.RFC4180.withDelimiter(',').withIgnoreEmptyLines().withHeader() .parse(reader); for (CSVRecord csvRecord : parser) { if (!csvRecord.get("Rank").contains("Copyright")) { PubmedJournal journal = new PubmedJournal( csvRecord.get("Full Journal Title").replaceAll("\\(.*?\\) ?", "")); if (csvRecord.isMapped("JCR Abbreviated Title")) { journal.setJournalShortName(csvRecord.get("JCR Abbreviated Title")); } try { journal.setYearImpactFactor(year, Float.parseFloat(csvRecord.get("Journal Impact Factor"))); } catch (Exception e) { System.out.println("Impact factor " + csvRecord.get("Journal Impact Factor") + " for " + csvRecord.get("Full Journal Title")); journal.setYearImpactFactor(year, -1); } this.journals.add(journal); this.currentBatchSize++; currentBatchSize++; if (this.currentBatchSize >= this.batchSize) { currentBatchSize = 0; for (PubmedJournal pm : journals) { this.sqlM.updateJournal(pm, true); } this.journals = new ArrayList<>(); } } } for (PubmedJournal pm : journals) { this.sqlM.updateJournal(pm, true); } this.journals = new ArrayList<>(); } catch (FileNotFoundException ex) { Logger.getLogger(CsvWosParser.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CsvWosParser.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(CsvWosParser.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:no.uio.medicine.virsurveillance.parserTests.SaxTest.java
private static ArrayList<String> getDataFromVirusCSV(String inputVirusFile) throws FileNotFoundException, IOException { ArrayList<String> viruses = new ArrayList<>(); BufferedReader reader = new BufferedReader(new FileReader(inputVirusFile)); CSVParser parser = CSVFormat.RFC4180.withDelimiter(';').withIgnoreEmptyLines().withHeader().parse(reader); for (CSVRecord csvRecord : parser) { if (csvRecord.isMapped("Virus Name")) { String currentVirus = csvRecord.get("Virus Name").replace(" virus", "").replace("", "%%"); viruses.add(currentVirus);//w w w . ja va 2 s .c o m } } return viruses; }
From source file:norbert.mynemo.dataimport.scraping.CkMapping.java
/** * Returns <code>true</code> if the mapping can be created from the given parameters. Returns * <code>false</code> otherwise. *//* w w w . j a va 2 s . c o m*/ public static boolean isValid(CSVRecord record) { return record.isConsistent() && record.isMapped(CK_MOVIE_HEADER) && record.isMapped(IMDB_MOVIE_HEADER); }
From source file:norbert.mynemo.dataimport.scraping.CkRating.java
/** * Returns <code>true</code> if the rating can be created from the given parameters. Returns * <code>false</code> otherwise. *///from w w w.jav a2s . c o m public static boolean isValid(CSVRecord record) { return record != null && record.isConsistent() && record.isMapped(USER_HEADER) && record.isMapped(MOVIE_HEADER) && record.isMapped(VALUE_HEADER); }