当前位置: 首页>>代码示例>>Java>>正文


Java CSVParser.getRecords方法代码示例

本文整理汇总了Java中org.apache.commons.csv.CSVParser.getRecords方法的典型用法代码示例。如果您正苦于以下问题:Java CSVParser.getRecords方法的具体用法?Java CSVParser.getRecords怎么用?Java CSVParser.getRecords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.csv.CSVParser的用法示例。


在下文中一共展示了CSVParser.getRecords方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public List<PhotoLocationSightPair> parse () throws IOException, BuenOjoCSVParserException {
	CSVParser parser =  CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
	
	
	List<CSVRecord> records = parser.getRecords();
	if (records.size() == 0 ) {
		throw new BuenOjoCSVParserException("El archivos de miras no contiene registros");
	}
	ArrayList<PhotoLocationSightPair> sightPairs = new ArrayList<>(records.size());
	for (CSVRecord record : records) {
		
		PhotoLocationSightPair sight = new PhotoLocationSightPair();
		sight.setNumber(new Integer(record.get(PhotoLocationSightPairCSVColumn.id)));
		sight.setSatelliteX(new Integer(record.get(PhotoLocationSightPairCSVColumn.satCol)));
		sight.setSatelliteY(new Integer(record.get(PhotoLocationSightPairCSVColumn.satRow)));
		sight.setSatelliteTolerance(new Integer(record.get(PhotoLocationSightPairCSVColumn.satTolerancia)));
		sight.setTerrainX(new Integer(record.get(PhotoLocationSightPairCSVColumn.terCol)));
		sight.setTerrainY(new Integer(record.get(PhotoLocationSightPairCSVColumn.terRow)));
		sight.setTerrainTolerance(new Integer(record.get(PhotoLocationSightPairCSVColumn.terTolerancia)));
		
		sightPairs.add(sight);
		
	}
	return sightPairs;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:26,代码来源:PhotoLocationSightPairCSVParser.java

示例2: parse

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public PhotoLocationBeacon parse() throws IOException, BuenOjoCSVParserException {
	
	CSVParser parser =  CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
	List<CSVRecord> records = parser.getRecords();
	if (records.size() > 1) {
		throw new BuenOjoCSVParserException("El archivo contiene más de un indicador");
	}
	if (records.size() == 0) {
		throw new BuenOjoCSVParserException("El archivo de indicador es inválido");
	}
	
	CSVRecord record = records.get(0);
	PhotoLocationBeacon beacon = new PhotoLocationBeacon();
	beacon.setX(new Integer(record.get(PhotoLocationBeaconCSVColumns.col.ordinal())));
	beacon.setY(new Integer(record.get(PhotoLocationBeaconCSVColumns.row.ordinal())));
	beacon.setTolerance(new Integer(record.get(PhotoLocationBeaconCSVColumns.tolerance.ordinal())));
	
	return beacon;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:20,代码来源:PhotoLocationBeaconCSVParser.java

示例3: setupUtils

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
protected void setupUtils() throws Exception {
    CSVFormat format = CSVFormat.DEFAULT;
    String fileLocation = config.getFileLocation();
    URL url;
    try {
        url = new URL(fileLocation);
    } catch (MalformedURLException e) {
        File file;
        if (!(file = new File(fileLocation)).exists()) {
            log.error("File does not exist: ", fileLocation);
        }
        url = file.toURI().toURL();
    }

    InputStreamReader isr = new InputStreamReader(
            downloadUtils.fetchInputStream(url, getProvider().getLabel(), ".csv"));
    CSVParser csvFileParser = new CSVParser(isr, format);
    csvRecords = csvFileParser.getRecords();
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:20,代码来源:GeneralCSVImporter.java

示例4: testReaderFromURL

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
@SuppressWarnings("resource")
// @Test
public void testReaderFromURL() throws UIMAException, IOException {
	CSVParser reader = new CSVParser(new FileReader(new File(csvFilename)),
			CSVFormat.TDF.withHeader((String) null));
	List<CSVRecord> records = reader.getRecords();

	description = CollectionReaderFactory.createReaderDescription(TextgridTEIUrlReader.class,
			TextgridTEIUrlReader.PARAM_INPUT, csvFilename, TextgridTEIUrlReader.PARAM_LANGUAGE, "de");
	JCasIterator iter = SimplePipeline
			.iteratePipeline(description, AnalysisEngineFactory.createEngineDescription(XmiWriter.class,
					XmiWriter.PARAM_TARGET_LOCATION, "target/doc/", XmiWriter.PARAM_USE_DOCUMENT_ID, true))
			.iterator();

	JCas jcas;
	CSVRecord gold;
	int recordIndex = 0;

	while (iter.hasNext()) {
		jcas = iter.next();
		gold = records.get(recordIndex++);
		checkSanity(jcas);
		checkGold(jcas, gold);
	}

}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:27,代码来源:TestTextgridTEIFileReader.java

示例5: getResponse

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
/**
 * Retrieves the answers of responseID for the survey identified by surveyID
 * 
 * @param surveyID
 *            identifier of the survey
 * @param responseID
 *            identifier of the response
 * @return the answers of responseID for the survey identified by surveyID
 * @throws ClientProtocolException
 * @throws IOException
 */
public Hashtable<String, String> getResponse(int surveyID, int responseID)
		throws ClientProtocolException, IOException {
	String sessionKey = getSessionKey();
	String responses = exportResponseByResponseID(sessionKey, surveyID,
			responseID);

	CSVParser csvParser = CSVParser.parse(responses, CSVFormat.RFC4180);
	List<CSVRecord> csvRecordsList = csvParser.getRecords();
	CSVRecord csvQuestions = csvRecordsList.get(0);
	CSVRecord csvAnswers = csvRecordsList.get(1);

	Iterator<String> iterQuestion = csvQuestions.iterator();
	Iterator<String> iterAnswer = csvAnswers.iterator();

	Hashtable<String, String> questionAnswerDictionary = new Hashtable<String, String>();
	while (iterQuestion.hasNext()) {
		String question = iterQuestion.next();
		String answer = iterAnswer.next();
		if (!isIgnoredKey(question))
			questionAnswerDictionary.put(formatQuestion(question),
					formatAnswer(answer));

	}
	return questionAnswerDictionary;
}
 
开发者ID:RISCOSS,项目名称:riscoss-data-collector,代码行数:37,代码来源:LimeSurveyClient.java

示例6: loadTableFromCSV

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static Table loadTableFromCSV(String projectName, String tableName,
		String csvFilePath, Attribute idAttrib, List<Attribute> attributes)
				throws IOException{	
	FileReader r = new FileReader(csvFilePath);
	CSVParser parser = new CSVParser(r,CSVFormat.DEFAULT);
	List<CSVRecord> records = parser.getRecords();
	r.close();

	List<Tuple> tuples = new ArrayList<Tuple>();
	int size = records.size();
	// System.out.println("No. of tuples: " + size);
	for(int i = 0; i < size; i++){
		CSVRecord rec = records.get(i);
		Map<Attribute,Object> attrValMap = new HashMap<Attribute,Object>();
		for(int j = 0; j < attributes.size(); j++){
			Attribute a = attributes.get(j);
			String value = rec.get(j);
			attrValMap.put(a, a.convertValueToObject(value));
			//System.out.println("i: " + i + ", j: "+ j);
		}
		tuples.add(new Tuple(attrValMap));
	}
	// System.out.println("Size of tuples: " + tuples.size());
	return new Table(tableName, idAttrib, attributes, tuples, projectName);
}
 
开发者ID:saikatgomes,项目名称:CS784-Data_Integration,代码行数:26,代码来源:CSVLoader.java

示例7: read

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static Table read(String projectName, String tableName,
    String csvFilePath, Attribute idAttrib, List<Attribute> attributes)
        throws IOException {
  FileReader r = new FileReader(csvFilePath);
  CSVParser parser = new CSVParser(r);
  List<CSVRecord> records = parser.getRecords();
  r.close();
  
  List<Item> items = new ArrayList<Item>();
  for(int i=1; i< records.size(); i++){
    CSVRecord rec = records.get(i);
    Map<Attribute,Object> attrValMap = new HashMap<Attribute,Object>();
    for(int j=0; j<attributes.size(); j++){
      Attribute a = attributes.get(j);
      String value = rec.get(j);
      attrValMap.put(a, value);
    }
    items.add(new Item(attrValMap));
  }
  return new Table(tableName,idAttrib,attributes,items,projectName);
}
 
开发者ID:saikatgomes,项目名称:CS784-Data_Integration,代码行数:22,代码来源:CSVUtils.java

示例8: loadFunctions

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static List<Function> loadFunctions(String csvFunctionFilePath) throws IOException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
	List<Function> functions = new ArrayList<Function>();
	try {
		FileReader r = new FileReader(csvFunctionFilePath);
		CSVParser parser = new CSVParser(r);
		List<CSVRecord> records = parser.getRecords();
		r.close();
		int size = records.size(); 
		for(int i = 1; i < size; i++){
			CSVRecord rec = records.get(i);
			String functionName = rec.get(0).trim();
			String functionDescription = rec.get(1).trim();
			String className = rec.get(2).trim();
			Class<?> functionClass = Class.forName(className);
			Constructor<?> constructor = functionClass.getConstructor(String.class, String.class);
			Function function = (Function) constructor.newInstance(functionName, functionDescription);
			functions.add(function);
		}
	}
	catch(FileNotFoundException fnfe) {
		System.out.println("File not found: " + fnfe.getMessage());
	}

	// System.out.println("No. of functions: " + functions.size());
	return functions;
}
 
开发者ID:saikatgomes,项目名称:CS784-Data_Integration,代码行数:27,代码来源:CSVUtils.java

示例9: readRules

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static List<Rule> readRules(Project project, String table1Name,
		String table2Name, String csvRuleFilePath) throws IOException{
	List<Rule> rules = new ArrayList<Rule>();
	try {
		FileReader r = new FileReader(csvRuleFilePath);
		CSVParser parser = new CSVParser(r);
		List<CSVRecord> records = parser.getRecords();
		r.close();

		int size = records.size(); 
		for(int i = 1; i < size; i++){
			CSVRecord rec = records.get(i);
			String ruleName = rec.get(0).trim();
			String ruleString = rec.get(1).trim();
			List<Term> terms = ParsingUtils.parseRule(project, ruleString);
			Rule rule = new Rule(ruleName, project.getName(), table1Name,
					table2Name, terms); 
			rules.add(rule);
		}
	}
	catch(FileNotFoundException fnfe) {
		System.out.println("File not found: " + fnfe.getMessage());
	}
	// System.out.println("No. of rules: " + rules.size());
	return rules;
}
 
开发者ID:saikatgomes,项目名称:CS784-Data_Integration,代码行数:27,代码来源:CSVUtils.java

示例10: csv2meld

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static void csv2meld(CSVParser reader, Function<String, String> headerExtractor, Function<String, Object> valueExtractor, MeldWriter writer) throws IOException, ReconException {
    ReconTable table = writer.addTable("csv", Iterables.toArray(Iterables.transform(reader.getHeaderMap().keySet(), headerExtractor), String.class));
    writer.finalizeDefinitions();
    writer.flush();
    List<CSVRecord> rows = reader.getRecords();
    for (String column : reader.getHeaderMap().keySet()) {
        List<Object> values = new ArrayList<Object>(rows.size());
        for (CSVRecord row : rows) {
            String entry = row.get(column);
            values.add(valueExtractor.apply(entry));
        }
        table.setSignal(headerExtractor.apply(column), values.toArray());
        writer.flush();
    }
    writer.close();
}
 
开发者ID:harmanpa,项目名称:jrecon,代码行数:17,代码来源:Meld.java

示例11: parseAndInject

import org.apache.commons.csv.CSVParser; //导入方法依赖的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);
			
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:38,代码来源:PhotoLocationLoader.java

示例12: getRecords

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
private List<CSVRecord> getRecords () throws BuenOjoCSVParserException, IOException{
	CSVParser parser =  CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
	
	List<CSVRecord> records = parser.getRecords();
	if (records.size()==0) {
		throw new BuenOjoCSVParserException("El archivo no contiene palabras clave");
	}
	if (records.size()>1) {
		throw new BuenOjoCSVParserException("El archivo contiene mas de un registro de palabras clave");
	}	
	return records;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:13,代码来源:PhotoLocationLandscapeLevelsCSVParser.java

示例13: loadFileinTable

import org.apache.commons.csv.CSVParser; //导入方法依赖的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());
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:28,代码来源:FileUtils.java

示例14: getRecords

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static List<CSVRecord> getRecords(File file) {
    if (file.exists()) {
        try (Reader in = new FileReader(file)) {
            CSVParser parser = CSVFormat.EXCEL.withHeader().withSkipHeaderRecord().withIgnoreEmptyLines().parse(in);
            if (!parser.getHeaderMap().isEmpty()) {
                return parser.getRecords();
            }
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    } else {
        LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
    }
    return new ArrayList<>();
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:16,代码来源:FileUtils.java

示例15: getCSVHParser

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static CSVHParser getCSVHParser(File file) {
    if (file.exists()) {
        try (Reader in = new FileReader(file)) {
            CSVParser parser = CSVFormat.EXCEL.withHeader().withSkipHeaderRecord().withIgnoreEmptyLines().parse(in);
            if (!parser.getHeaderMap().isEmpty()) {
                return new CSVHParser(parser.getHeaderMap(), parser.getRecords());
            }
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    } else {
        LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
    }
    return null;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:16,代码来源:FileUtils.java


注:本文中的org.apache.commons.csv.CSVParser.getRecords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。