本文整理汇总了Java中org.apache.commons.csv.CSVRecord.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java CSVRecord.iterator方法的具体用法?Java CSVRecord.iterator怎么用?Java CSVRecord.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.csv.CSVRecord
的用法示例。
在下文中一共展示了CSVRecord.iterator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareCSVRecords
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
private void compareCSVRecords(CSVRecord actual, CSVRecord expected) {
Iterator<String> actualIterator = actual.iterator();
Iterator<String> expectedIterator = expected.iterator();
while (actualIterator.hasNext() && expectedIterator.hasNext()) {
String nextExpected = expectedIterator.next();
String nextActual = actualIterator.next();
assertThat(nextActual, is(nextExpected));
}
if (actualIterator.hasNext() || expectedIterator.hasNext()) {
fail("Records are not similar:\n" + actual + "\n" + expected);
}
}
示例2: run
import org.apache.commons.csv.CSVRecord; //导入方法依赖的package包/类
public void run(String[] args) {
try {
if (args.length != 4) {
System.out.println("Usage: java CsvTupler spreadsheet-file-in.csv mapping-file-in.ttl instance-ontology-in.owl.ttl instance-file-out.ttl");
return;
}
else {
argStrings = new ArrayList<String>();
for (int i=0; i<4; i++)
argStrings.add(args[i]);
}
Reader in = new FileReader(args[0]);
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in);
int row=0;
List<List<String>> rows = new ArrayList<List<String>>();
//System.out.println("---------- the spreadsheet ------------");
for (CSVRecord record : records) {
Iterator<String> iter = record.iterator();
int col=0;
List<String> column = new ArrayList<String>();
while (iter.hasNext()) {
String val = iter.next();;
//System.out.print("["+row+"]["+col+"]= "+val);
//if (iter.hasNext()) System.out.print(", ");
column.add(val);
col++;
}
rows.add(column);
//System.out.println("\n");
row++;
}
/*
System.out.println("---------- the spreadsheet *again* ------------");
for (int i=0; i<rows.size(); i++) {
List<String> aColumn = rows.get(i);
for (int j=0; j<aColumn.size(); j++) {
System.out.print("["+i+"]["+j+"]= "+aColumn.get(j));
if (j!=aColumn.size()-1) System.out.print(", ");
}
System.out.println("\n");
}
*/
String ontologyUri = "http://example.com/owl/csvtupler/map2sparql";
String ontologyNamespace = ontologyUri+"#";
OntModel map2sparqlModel = ModelFactory.createOntologyModel();
FileManager.get().readModel( map2sparqlModel, "../ontologies/map2sparql.owl.ttl" );
Model mappingModel = FileManager.get().loadModel(args[1], "http://example.com/owl/csvtupler/map2sparql",RDFLanguages.strLangTurtle);
String ontologyPrefix = "map2sparql";
ontology4instanceModel = ModelFactory.createOntologyModel();
FileManager.get().readModel( ontology4instanceModel, args[2] );
instanceModel = ModelFactory.createDefaultModel();
Node root = NodeFactory.createNodes(this, rows, mappingModel,
"SELECT ?node WHERE { ?node a <http://example.com/owl/csvtupler/map2sparql#Node>.}");
if (root==null) {
System.out.println("Couldn't build node tree. No root node has been set in "+args[1]);
return;
}
root.print(System.out, true);
construct(root);
instanceModel.write(Files.newBufferedWriter(Paths.get(args[3])),"Turtle");
} catch (Exception e) {
System.out.println("Can't write to instance file due to: "+e);
}
}