List of usage examples for org.apache.commons.csv CSVRecord get
public String get(final String name)
From source file:com.ibm.watson.app.qaclassifier.tools.PopulateAnswerStore.java
/** * Reads in the answer input file and creates a POJO for each answer it finds. If the answer has no value * it is skipped.//from w w w . j a va2s .co m * * @return AnswerStore - full POJO of the answer store read from the file */ private static List<ManagedAnswer> readAnswerInput(String content) { List<ManagedAnswer> store = null; // read the CVS of label to canonical question first try (StringReader reader = new StringReader(content); CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL);) { // read in the csv file and get the records List<CSVRecord> records = parser.getRecords(); // now we can create the answer store because we have read the records store = new ArrayList<ManagedAnswer>(); for (CSVRecord r : records) { // order is: LabelId, CanonicalQuestion // create the answer pojo ManagedAnswer answer = new ManagedAnswer(); answer.setClassName(r.get(0)); answer.setCanonicalQuestion(r.get(1)); answer.setType(TypeEnum.TEXT); // add to the managed answers list store.add(answer); } } catch (Exception e) { e.printStackTrace(); } return store; }
From source file:edu.caltech.ipac.firefly.server.util.DsvToDataGroup.java
static DataObject parseRow(DataGroup source, CSVRecord line) { DataType[] headers = source.getDataDefinitions(); if (line != null && line.size() > 0) { DataObject row = new DataObject(source); String val; for (int i = 0; i < headers.length; i++) { DataType type = headers[i];/*from ww w .ja v a 2s . c o m*/ val = StringUtils.isEmpty(line.get(i)) ? null : line.get(i).trim(); if (!type.isKnownType()) { IpacTableUtil.guessDataType(type, val); } row.setFormattedData(type, val); row.setDataElement(type, type.convertStringToData(val)); if (val != null && val.length() > type.getMaxDataWidth()) { type.setMaxDataWidth(val.length()); } if (type.getFormatInfo().isDefault()) { IpacTableUtil.guessFormatInfo(type, val); } } return row; } return null; }
From source file:net.iaeste.iws.core.transformers.CSVTransformer.java
static void transformStudyLevels(final Map<String, String> errors, final Verifiable obj, final OfferFields field, final CSVRecord record) { final Set<StudyLevel> value = EnumSet.noneOf(StudyLevel.class); final Boolean beginning = convertBoolean(record.get(STUDY_COMPLETED_BEGINNING.getField())); final Boolean middle = convertBoolean(record.get(STUDY_COMPLETED_MIDDLE.getField())); final Boolean end = convertBoolean(record.get(STUDY_COMPLETED_END.getField())); if (!beginning && !middle && !end) { errors.put(field.getField(), "No StudyLevel defined."); } else {/* w ww .j ava 2 s . c o m*/ if (beginning) { value.add(StudyLevel.B); } if (middle) { value.add(StudyLevel.M); } if (end) { value.add(StudyLevel.E); } } invokeMethodOnObject(errors, obj, field, value); }
From source file:com.denkbares.semanticcore.utils.ResultTableModel.java
public static ResultTableModel fromCSV(String csv) throws IOException { try (CSVParser parser = CSVFormat.DEFAULT.withHeader().parse(new StringReader(csv))) { // read the header Map<String, Integer> headerMap = parser.getHeaderMap(); List<String> variables = headerMap.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getValue)) .map(Map.Entry::getKey).collect(Collectors.toList()); // read the rows List<TableRow> rows = new LinkedList<>(); for (final CSVRecord record : parser) { SimpleTableRow row = new SimpleTableRow(); for (String variable : variables) { String value = record.get(variable); if (value != null) { row.addValue(variable, new LiteralImpl(value)); }//from ww w . j a va 2 s . c o m } rows.add(row); } // and return the parsed table return new ResultTableModel(rows, variables); } }
From source file:net.sourceforge.ganttproject.io.GanttCSVOpen.java
private static RecordGroup createResourceRecordGroup(final HumanResourceManager resourceManager) { return resourceManager == null ? null : new RecordGroup(Sets.newHashSet(getFieldNames(ResourceFields.values()))) { @Override/* w w w . j ava 2 s . c o m*/ public void setHeader(List<String> header) { super.setHeader(header); createCustomProperties(getCustomFields(), resourceManager.getCustomPropertyManager()); } @Override protected void process(CSVRecord record) { assert record.size() > 0; HumanResource hr = resourceManager.newResourceBuilder() .withName(record.get(ResourceFields.NAME.toString())) .withID(record.get(ResourceFields.ID.toString())) .withEmail(record.get(ResourceFields.EMAIL.toString())) .withPhone(record.get(ResourceFields.PHONE.toString())) .withRole(record.get(ResourceFields.ROLE.toString())).build(); for (String customField : getCustomFields()) { String value = record.get(customField); if (value != null) { hr.addCustomProperty(resourceManager.getCustomPropertyManager() .getCustomPropertyDefinition(customField), value); } } } }; }
From source file:com.siemens.sw360.commonIO.ConvertRecord.java
public static List<Obligation> convertObligation(List<CSVRecord> records) { List<Obligation> list = new ArrayList<>(records.size()); for (CSVRecord record : records) { String id = record.get(0); String name = record.get(1); Obligation obligation = new Obligation().setObligationId(Integer.parseInt(id)).setName(name); list.add(obligation);/* w ww.j a v a 2 s. c o m*/ } return list; }
From source file:com.siemens.sw360.commonIO.ConvertRecord.java
public static Map<String, Set<Integer>> convertRelationalTable(List<CSVRecord> records) { Map<String, Set<Integer>> map = new HashMap<>(records.size()); for (CSVRecord record : records) { String mainId = record.get(0); int otherId = Integer.parseInt(record.get(1)); if (map.containsKey(mainId)) { map.get(mainId).add(otherId); } else {//from w ww.java 2s. co m Set<Integer> ids = new HashSet<>(); ids.add(otherId); map.put(mainId, ids); } } return map; }
From source file:com.siemens.sw360.commonIO.ConvertRecord.java
public static List<Todo> convertTodos(List<CSVRecord> records) { List<Todo> list = new ArrayList<>(records.size()); for (CSVRecord record : records) { String id = record.get(0); String text = record.get(1); Todo todo = new Todo().setTodoId(Integer.parseInt(id)).setText(text); // Parse boolean values String developmentString = record.get(2); if (!"NULL".equals(developmentString)) { boolean development = parseBoolean(developmentString); todo.setDevelopement(development); }// w ww . ja v a 2s. c o m String distributionString = record.get(3); if (!"NULL".equals(distributionString)) { boolean distribution = parseBoolean(distributionString); todo.setDistribution(distribution); } list.add(todo); } return list; }
From source file:com.siemens.sw360.commonIO.ConvertRecord.java
public static List<RiskCategory> convertRiskCategories(List<CSVRecord> records) { ArrayList<RiskCategory> list = new ArrayList<>(records.size()); for (CSVRecord record : records) { int id = Integer.parseInt(record.get(0)); String text = record.get(1); RiskCategory category = new RiskCategory().setRiskCategoryId(id).setText(text); list.add(category);//w w w . jav a2 s . c om } return list; }
From source file:com.siemens.sw360.commonIO.ConvertRecord.java
public static List<LicenseType> convertLicenseTypes(List<CSVRecord> records) { List<LicenseType> list = new ArrayList<>(records.size()); for (CSVRecord record : records) { int id = Integer.parseInt(record.get(0)); String text = record.get(1); LicenseType type = new LicenseType().setLicenseTypeId(id).setLicenseType(text); list.add(type);// w w w. ja v a 2 s . c o m } return list; }