本文整理汇总了Java中org.apache.commons.csv.CSVRecord.get方法的典型用法代码示例。如果您正苦于以下问题:Java CSVRecord.get方法的具体用法?Java CSVRecord.get怎么用?Java CSVRecord.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.csv.CSVRecord
的用法示例。
在下文中一共展示了CSVRecord.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public List<TagPair> parse() throws IOException {
CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
ArrayList<TagPair> tagPairs = new ArrayList<>(AVG_ITEMS);
for (CSVRecord record : parser ){
TagPair pair = new TagPair();
Integer tagSlotId = new Integer(record.get("id"));
Integer tagNumber = new Integer(record.get("etiqueta"));
pair.setTagSlotId(tagSlotId);
Optional<Tag> optionalTag = tagList.stream().filter(isEqualToTagNumber(tagNumber)).findFirst();
if (optionalTag.isPresent()){
Tag tag = optionalTag.get();
pair.setTag(tag);
tagPairs.add(pair);
}else {
log.debug("Attempt to get invalid tag with number: "+tagNumber);
}
}
return tagPairs;
}
示例2: accept
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
@Override
public void accept(CSVRecord theRecord) {
String code = theRecord.get("LOINC_NUM");
if (isNotBlank(code)) {
String longCommonName = theRecord.get("LONG_COMMON_NAME");
String shortName = theRecord.get("SHORTNAME");
String consumerName = theRecord.get("CONSUMER_NAME");
String display = firstNonBlank(longCommonName, shortName, consumerName);
ConceptEntity concept = new ConceptEntity(myCodeSystemVersion, code);
concept.setDisplay(display);
Validate.isTrue(!myCode2Concept.containsKey(code));
myCode2Concept.put(code, concept);
}
}
示例3: parseLevels
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public Integer[] parseLevels() throws BuenOjoCSVParserException, IOException{
CSVRecord record = getRecords().get(0);
String levels = record.get(PhotoLocationLandscapeLevelsCSVColumns.levels.ordinal());
//Matcher m = Pattern.compile("(\\d*):(\\d*)").matcher(levels);
String[] m = levels.split(":");
if (m==null) {
throw new BuenOjoCSVParserException("el formato del nivel es incorrecto: "+levels);
}
Integer[] n = new Integer[PhotoLocationLevelComponents.count.ordinal()];
int lower = PhotoLocationLevelComponents.lowerLevel.ordinal();
int higher = PhotoLocationLevelComponents.higherLevel.ordinal();
n[lower] = new Integer(m[lower]);
n[higher] = new Integer(m[higher]);
return n;
}
示例4: getUniqueFields
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
private static String[] getUniqueFields(File inFile) throws IOException {
CSVParser parser = new CSVParser(new BufferedReader(new FileReader(inFile)),
CSVFormat.EXCEL.withNullString(NULL_STRING));
// first record used as header
CSVRecord header = parser.iterator().next();
List<String> uniqueFields = new ArrayList<String>();
for(int i = 0; i < header.size(); i++) {
String col = header.get(i);
if (!uniqueFields.contains(col)) {
// we can add it directly
uniqueFields.add(col);
} else {
// disambiguate by appending index
uniqueFields.add(col + "_" + i);
}
}
return uniqueFields.toArray(new String[0]);
}
示例5: next
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
@Override
public String next()
{
CSVRecord record = inner.next();
StringWriter json = new StringWriter();
try {
JsonGenerator gen = jsonFactory.createJsonGenerator(json);
gen.writeStartObject();
for (CSVHeaderMap.Entry entry : headerMap.entries()) {
String name = entry.getName();
String value = record.get(entry.getIndex());
gen.writeFieldName(name);
entry.getWriter().write(gen, value);
}
gen.writeEndObject();
gen.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
return json.toString();
}
示例6: read
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public HdrData read(String filename) throws IOException {
Reader in = new FileReader(filename);
HdrData ret = new HdrData();
List<Double> value = ret.getValue();
List<Double> percentile = ret.getPercentile();
Iterable<CSVRecord> records = CSVFormat.RFC4180
.withCommentMarker('#')
.withFirstRecordAsHeader()
.parse(in);
for (CSVRecord record : records) {
String valueStr = record.get(0);
String percentileStr = record.get(1);
logger.debug("Value: {}", valueStr);
logger.debug("Percentile: {}", percentileStr);
value.add(Double.parseDouble(valueStr));
percentile.add(Double.parseDouble(percentileStr) * 100);
}
return ret;
}
示例7: processElement
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
String rawInput = null;
InputContent iContent = null;
try {
rawInput = c.element();
if (rawInput == null)
throw new Exception("ParseCSVFile: null raw content");
FileIndexerPipelineOptions options = c.getPipelineOptions().as(FileIndexerPipelineOptions.class);
Integer textColumnIdx = options.getTextColumnIdx();
Integer collectionItemIdIdx = options.getCollectionItemIdIdx();
InputStreamReader isr = new InputStreamReader(IOUtils.toInputStream(rawInput,StandardCharsets.UTF_8.name()));
Iterable<CSVRecord> records = CSVFormat.DEFAULT
.withFirstRecordAsHeader()
.parse(isr);
for (CSVRecord record : records) {
String text = record.get(textColumnIdx);
String documentCollectionId = IndexerPipelineUtils.DOC_COL_ID_CSV_FILE;
String collectionItemId = record.get(collectionItemIdIdx);
InputContent ic = new InputContent(
null /*url*/, null /*pubTime*/, null /*title*/, null /*author*/, null /*language*/,
text, documentCollectionId, collectionItemId, 0 /*skipIndexing*/);
c.output(ic);
}
} catch (Exception e) {
LOG.warn(e.getMessage());
}
}
示例8: parseAndInject
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public void parseAndInject(PhotoLocationExercise exercise, InputStreamSource inputStreamSource) throws BuenOjoCSVParserException, IOException{
CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(inputStreamSource.getInputStream()));
List<CSVRecord> records = parser.getRecords();
if (records.size() > 1) {
throw new BuenOjoCSVParserException("El archivo contiene más de un ejercicio");
}
if (records.size() == 0) {
throw new BuenOjoCSVParserException("El archivo de ejericio es inválido");
}
CSVRecord record = records.get(0);
String name = record.get(MetadataColumns.name);
String description = record.get(MetadataColumns.description);
String difficulty = record.get(MetadataColumns.difficulty);
String seconds = record.get(MetadataColumns.seconds);
String totalScore = record.get(MetadataColumns.totalScore.ordinal());
String imageName = record.get(MetadataColumns.imageName.ordinal());
exercise.setDescription(description);
exercise.setName(name);
exercise.setDifficulty(difficultyFromString(difficulty));
exercise.setTotalTimeInSeconds(new Integer(seconds));
exercise.setTotalScore(new Float(totalScore));
exercise.setExtraPhotosCount(3);
List<PhotoLocationImage> imgs = photoLocationImageRepository.findAll();
Optional<PhotoLocationImage> opt = imgs.stream().filter(p -> p.getImage().getName().equals(imageName)).collect(Collectors.toList()).stream().findFirst();
if (!opt.isPresent()){
throw new BuenOjoCSVParserException("la imagen '"+imageName+"' no existe en la base de datos");
}
PhotoLocationImage img = opt.get();
img.setKeywords(exercise.getLandscapeKeywords());
photoLocationImageRepository.save(img);
exercise.setTerrainPhoto(img);
}
示例9: createTagPool
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
private List<TagPool> createTagPool(CSVParser parser) throws BuenOjoCSVParserException{
ArrayList<TagPool> list = new ArrayList<>();
for (CSVRecord record : parser) {
String name = record.get(TagPoolColumn.TAG.ordinal()).toString();
Tag tag = tagMap.get(name);
for (int i = TagPoolColumn.SIMILAR_1.ordinal(); (i <record.size()) && i <= TagPoolColumn.SIMILAR_3.ordinal(); i++) {
String similarTagName = record.get(i);
if (similarTagName != null && !StringUtils.isAnyEmpty(similarTagName)){
Tag similarTag = tagMap.get(similarTagName);
if (similarTag != null){
TagPool tagPool = new TagPool();
tagPool.setTag(tag);
tagPool.setSimilarTag(similarTag);
tagPool.setSimilarity(i);
list.add(tagPool);
} else {
throw new BuenOjoCSVParserException("no se pudo obtener la etiqueta con nombre: '"+similarTagName+"'");
}
}
}
}
return list;
}
示例10: init
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public static void init ()
{
mKeywordToResponse = new HashMap<>();
String[] files = {"data/zombot-responses-en.csv","data/zombot-responses-bo.csv","data/zombot-responses-zh.csv"};
int idx = 0;
for (String queryFile : files) {
try {
FileReader fr = (new FileReader(new File(queryFile)));
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(fr);
for (CSVRecord record : records) {
System.out.println(record.get(0));
BotResponse br = new BotResponse();
br.keyword = record.get(0);
br.title = record.get(1);
br.response = record.get(2);
try {
if (record.get(3) != null && record.get(3).length() > 0)
br.date = sdf.parse(record.get(3));
}
catch (Exception e)
{
System.out.println("error parsing date: " + e.getMessage());
}
mKeywordToResponse.put(br.keyword + ' ' + br.title + ' ' + (idx++), br);
}
} catch (Exception ioe) {
ioe.printStackTrace();
}
}
}
示例11: getRecordByAction
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
private CSVRecord getRecordByAction(String actionName) {
if (!actionName.isEmpty()) {
for (CSVRecord record : stepMapTemplate.getRecords()) {
String action = record.get("Step");
if (action.equalsIgnoreCase(actionName)) {
return record;
}
}
}
return null;
}
示例12: loadFileinTable
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public static void loadFileinTable(File file, JTable table) {
if (file.exists()) {
try (Reader in = new FileReader(file)) {
CSVParser parser = CSVFormat.EXCEL.withHeader().withSkipHeaderRecord().withIgnoreEmptyLines().parse(in);
if (!parser.getHeaderMap().isEmpty()) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
for (String columnHeader : parser.getHeaderMap().keySet()) {
if (!columnHeader.trim().isEmpty()) {
model.addColumn(columnHeader);
}
}
List<CSVRecord> records = parser.getRecords();
for (CSVRecord record : records) {
Object[] row = new Object[record.size()];
for (int i = 0; i < record.size(); i++) {
row[i] = record.get(i);
}
model.addRow(row);
}
}
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
} else {
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
}
}
示例13: accept
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
@Override
public void accept(CSVRecord theRecord) {
Patient patient = patientMap.get(theRecord.get("PATIENT_ID"));
if (patient == null) {
patient = new Patient();
patient.setId(theRecord.get("PATIENT_ID"));
patientMap.put(patient.getId(),patient);
resources.add(patient);
}
if (!theRecord.get("SYSTEM_ID").isEmpty() && !theRecord.get("value").isEmpty()) {
switch (theRecord.get("SYSTEM_ID")) {
case "1001":
patient.addIdentifier()
.setSystem("https://fhir.leedsth.nhs.uk/Id/pas-number")
.setValue(theRecord.get("value"));
break;
case "1":
patient.addIdentifier()
.setSystem(CareConnectSystem.NHSNumber)
.setValue(theRecord.get("value"));
break;
}
}
// PATIENT_IDENTIFIER_ID,identifierUse,listOrder,,,
}
示例14: parse
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public List<ExerciseTip> parse() throws BuenOjoCSVParserException{
ArrayList<ExerciseTip> tipList = new ArrayList<>();
CSVParser parser = null;
List<CSVRecord> recordList =null;
List<Tag> tagList = tagRepository.findByCourseOrderByNumber(this.course);
HashMap<String,Tag> tagMap = new HashMap<>(tagList.size());
for (Tag tag : tagList) {
tagMap.put(tag.getName(), tag);
}
try {
parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
recordList = parser.getRecords();
} catch (IOException e) {
log.debug("Error parsing tips:"+e.getMessage());
throw new BuenOjoCSVParserException(e.getMessage());
}
for (CSVRecord csvRecord : recordList) {
ExerciseTip tip = new ExerciseTip();
String tipDetail = csvRecord.get(TIP_HEADER);
String region = csvRecord.get(REGION_HEADER);
String tagName = csvRecord.get(TAG_HEADER);
String imageType = csvRecord.get(IMAGE_TYPE);
String photoArrayString = csvRecord.get(PHOTOS_HEADER);
tip.setDetail(tipDetail);
EnumSet<Region> regions = stringToRegions(region);
tip.setRegions(regions);
Tag theTag = tagMap.get(tagName);
if (theTag == null ) throw new BuenOjoCSVParserException("Could not find tag with name: ["+tagName+"]");
tip.setTag(theTag);
EnumSet<SatelliteImageType> imageTypeSet = typeFromDescription(imageType.trim());
tip.setImageTypes(imageTypeSet);
for (String name : stringToImageNames(photoArrayString)) {
if (!name.isEmpty()) {
String sanitizedName = name.trim();
ImageResource img = imageRepository.findOneByName(sanitizedName);
if (img==null) throw new BuenOjoCSVParserException("Could not find image with name: ["+sanitizedName+"]");
tip.getImages().add(img);
}
}
tipList.add(tip);
}
return tipList;
}
示例15: accept
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
@Override
public void accept(CSVRecord theRecord) {
Set<String> ignoredTypes = new HashSet<String>();
ignoredTypes.add("Method (attribute)");
ignoredTypes.add("Direct device (attribute)");
ignoredTypes.add("Has focus (attribute)");
ignoredTypes.add("Access instrument");
ignoredTypes.add("Procedure site (attribute)");
ignoredTypes.add("Causative agent (attribute)");
ignoredTypes.add("Course (attribute)");
ignoredTypes.add("Finding site (attribute)");
ignoredTypes.add("Has definitional manifestation (attribute)");
String sourceId = theRecord.get("sourceId");
String destinationId = theRecord.get("destinationId");
String typeId = theRecord.get("typeId");
boolean active = "1".equals(theRecord.get("active"));
ConceptEntity typeConcept = myCode2concept.get(typeId);
ConceptEntity sourceConcept = myCode2concept.get(sourceId);
ConceptEntity targetConcept = myCode2concept.get(destinationId);
if (sourceConcept != null && targetConcept != null && typeConcept != null) {
if (typeConcept.getDisplay().equals("Is a (attribute)")) {
ConceptParentChildLink.RelationshipTypeEnum relationshipType = ConceptParentChildLink.RelationshipTypeEnum.ISA;
if (!sourceId.equals(destinationId)) {
if (active) {
ConceptParentChildLink link = new ConceptParentChildLink();
link.setChild(sourceConcept);
link.setParent(targetConcept);
link.setRelationshipType(relationshipType);
link.setCodeSystem(myCodeSystemVersion);
targetConcept.addChild(sourceConcept, relationshipType);
} else {
// not active, so we're removing any existing links
for (ConceptParentChildLink next : new ArrayList<ConceptParentChildLink>(targetConcept.getChildren())) {
if (next.getRelationshipType() == relationshipType) {
if (next.getChild().getCode().equals(sourceConcept.getCode())) {
next.getParent().getChildren().remove(next);
next.getChild().getParents().remove(next);
}
}
}
}
}
} else if (ignoredTypes.contains(typeConcept.getDisplay())) {
// ignore
} else {
// ourLog.warn("Unknown relationship type: {}/{}", typeId, typeConcept.getDisplay());
}
}
}