當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。