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


Java CSVRecord.iterator方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:kenshoo,项目名称:file-format-streaming-converter,代码行数:13,代码来源:XlsxToCsvConverterTest.java

示例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);
    }
	}
 
开发者ID:tag42git,项目名称:CsvTupler,代码行数:79,代码来源:CsvTupler.java


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