當前位置: 首頁>>代碼示例>>Java>>正文


Java CSVParser.iterator方法代碼示例

本文整理匯總了Java中org.apache.commons.csv.CSVParser.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVParser.iterator方法的具體用法?Java CSVParser.iterator怎麽用?Java CSVParser.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.csv.CSVParser的用法示例。


在下文中一共展示了CSVParser.iterator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initParser

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
protected void initParser(InputSplit inSplit) throws IOException,
    InterruptedException {
    fileIn = openFile(inSplit, true);
    if (fileIn == null) {
        return;
    }
    instream = new InputStreamReader(fileIn, encoding);

    bytesRead = 0;
    fileLen = inSplit.getLength();
    if (uriName == null) {
        generateId = conf.getBoolean(CONF_INPUT_GENERATE_URI, false);
        if (generateId) {
            idGen = new IdGenerator(file.toUri().getPath() + "-"
                + ((FileSplit) inSplit).getStart());
        } else {
            uriId = 0;
        }
    }
    parser = new CSVParser(instream, CSVParserFormatter.
    		getFormat(delimiter, encapsulator, true,
    				true));
    parserIterator = parser.iterator();
}
 
開發者ID:marklogic,項目名稱:marklogic-contentpump,代碼行數:25,代碼來源:DelimitedTextReader.java

示例2: startRevisionProcessing

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
@Override
public void startRevisionProcessing() {
	logger.debug("Starting...");
	try {
		BufferedReader csvReader;

		csvReader = new BufferedReader(
		new InputStreamReader(
		new BZip2CompressorInputStream(
		new BufferedInputStream(
		new FileInputStream(geolocationFeatureFile))), "UTF-8"));

		csvParser = new CSVParser(csvReader,
				CSVFormat.RFC4180.withHeader());
		iterator = csvParser.iterator();
	
		processor.startRevisionProcessing();
	
	} catch (IOException e) {
		logger.error("", e);
	}
}
 
開發者ID:heindorf,項目名稱:cikm16-wdvd-feature-extraction,代碼行數:23,代碼來源:GeolocationFeatureProcessor.java

示例3: startReading

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
/**
 *	Initializes the label reader.
 */
public void startReading() {
	try {
		BufferedReader csvReader = new BufferedReader(
				new InputStreamReader(labelsStream, "UTF-8"), BUFFER_SIZE);

		csvParser = new CSVParser(csvReader,
				CSVFormat.RFC4180.withHeader(FILE_HEADER));
		iterator = csvParser.iterator();

		CSVRecord headerRecord = iterator.next();

		for (int i = 0; i < FILE_HEADER.length; i++) {
			if (!FILE_HEADER[i].equals(headerRecord.get(i))) {
				throw new IOException(
						"The header of the CSV file is wrong.");
			}
		}
	} catch (IOException e) {
		logger.error("", e);
		finishReading();
	}
}
 
開發者ID:heindorf,項目名稱:cikm16-wdvd-feature-extraction,代碼行數:26,代碼來源:CorpusLabelReader.java

示例4: loadAnnotatedSample

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
public void loadAnnotatedSample(String sID, File file)
{
    String fn = file.getName();
    System.out.println("Loading result file: " + fn);
    try {
        List<EnrichmentAnnotation> sample = getSample(sID);

        CSVParser parser = CSVParser.parse(file, Charset.forName("UTF-8")
                                         , CSVFormat.EXCEL);

        Iterator<CSVRecord> iter = parser.iterator();
        if ( iter.hasNext() ) { iter.next(); }

        while (iter.hasNext()) { loadAnnotation(sID, sample, iter.next()); }
    }
    catch (IOException e) {
        System.err.println("Error loading file: " + fn);
    }
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:20,代碼來源:EnrichmentSamplesAssembler.java

示例5: CsvRecordReader

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
public CsvRecordReader(Reader reader, CSVFormat format, long length, boolean strict) throws IOException {
  this.length = length;
  this.strict = strict;
  parser = new CSVParser(reader, format);
  iterator = parser.iterator();
  if (parser.getHeaderMap() == null) {
    colLength = null;
  } else {
    colLength = parser.getHeaderMap().size();
  }
}
 
開發者ID:datascienceinc,項目名稱:cascading.csv,代碼行數:12,代碼來源:CsvRecordReader.java

示例6: createIterator

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
private void createIterator() {
  try {
    final InputStream in = parent.getInputStream();
    requestParser = new CSVParser(new InputStreamReader(in, format.getEncoding()),
        format.getCsvFormat());
    iterator = requestParser.iterator();
  } catch (final IOException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:penzance,項目名稱:canvas-data-tools,代碼行數:11,代碼來源:DelimitedTableReader.java

示例7: init

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
@Override
public void init() throws Exception {
  final Reader reader = new FileReader(_fileName);
  _parser = new CSVParser(reader, getFormat());

  _iterator = _parser.iterator();
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:8,代碼來源:CSVRecordReader.java

示例8: getRows

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
@Override
public RowSet getRows(String baseQuery,
                      Map<String, String> preds,
                      int limit,
                      int offset) throws Exception{

    filename = conf.getString(MacroBaseConf.CSV_INPUT_FILE);
    Compression compression = conf.getCsvCompression();

    if (compression == Compression.GZIP) {
        InputStream fileStream = new FileInputStream(filename);
        InputStream gzipStream = new GZIPInputStream(fileStream);
        Reader decoder = new InputStreamReader(gzipStream);
        csvParser = new CSVParser(decoder, CSVFormat.DEFAULT.withHeader());
    } else {
        File csvFile = new File(conf.getString(MacroBaseConf.CSV_INPUT_FILE));
        csvParser = CSVParser.parse(csvFile, Charset.defaultCharset(), CSVFormat.DEFAULT.withHeader());
    }
    schema = csvParser.getHeaderMap();
    Iterator<CSVRecord> rawIterator = csvParser.iterator();
    int rowCount = 0;

    List<RowSet.Row> rows = Lists.newArrayList();
    while (rawIterator.hasNext() && rowCount < limit) {
        CSVRecord record = rawIterator.next();
        List<ColumnValue> columnValues = Lists.newArrayList();

        if (includeRow(record, preds)) {
            for (Map.Entry<String, Integer> se : schema.entrySet()) {
                columnValues.add(new ColumnValue(se.getKey(),record.get(se.getValue())));
            }

            rows.add(new RowSet.Row(columnValues));
            rowCount++;
        }
    }
     return new RowSet(rows);
}
 
開發者ID:stanford-futuredata,項目名稱:macrobase,代碼行數:39,代碼來源:CSVIngester.java

示例9: select

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
private Collection<String> select(CSVParser parser, Collection<String> col)
{
    Iterator<CSVRecord> iter = parser.iterator();
    if ( iter.hasNext() ) { iter.next(); }

    while ( iter.hasNext() ) { select(iter.next(), col); }

    return col;
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:10,代碼來源:AmbiguitySelection.java

示例10: load

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
public void load(File file)
{
    System.out.println("Loading cache: " + file.getName());
    try {
        CSVParser parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.EXCEL);
        Iterator<CSVRecord> iter = parser.iterator();
        while ( iter.hasNext() )
        {
            CSVRecord record = iter.next();
            addToCache(record.get(0), record.get(1));
        }
    }
    catch (IOException e) { System.err.println("Error loading file: " + file.getName()); }
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:15,代碼來源:CorefCache.java

示例11: load

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
public void load(String annotator, File file) throws IOException
{
    System.out.println("loading annotations from: " + annotator);

    CSVParser p = CSVParser.parse(file, Charset.forName("UTF-8")
                                , CSVFormat.EXCEL);

    Iterator<CSVRecord> iter = p.iterator();
    if ( iter.hasNext() ) { iter.next(); }

    while ( iter.hasNext() ) { parseAnnotation(annotator, iter.next()); }
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:13,代碼來源:AgreementRatings.java

示例12: loadEnrichments

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
public static Collection<EnrichmentResult> loadEnrichments(
        String set, File f, Collection<EnrichmentResult> results)
{
    System.out.println("Loading result file: " + f.getName());
    try {
        CSVParser parser = CSVParser.parse(f, Charset.forName("UTF-8"), CSVFormat.EXCEL);
        Iterator<CSVRecord> iter = parser.iterator();
        while ( iter.hasNext() ) { loadResult(set, iter.next(), results); }
    }
    catch (IOException e) { System.err.println("Error loading file: " + f.getName()); }
    return results;
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:13,代碼來源:ResultUtils.java

示例13: CsvSourceIterator

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
public CsvSourceIterator(DataSource source, URL sourceUrl, CSVFormat csvFormat, MetricRegistry registry) throws SourceAdapterException {
	super(source, sourceUrl, registry);
	try {
		CSVParser parser = CSVParser.parse(sourceUrl, Charset.forName("UTF-8"), csvFormat);
		csvIterator = parser.iterator();
		firstRecord = csvIterator.next();
	} catch (IOException ioe) {
		throw new SourceAdapterException(ioe);
	}
}
 
開發者ID:jvalue,項目名稱:open-data-service,代碼行數:11,代碼來源:CsvSourceAdapter.java

示例14: loadCorrectedInstancesFromCSV

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
public static Map<String, CorrectedInstance> loadCorrectedInstancesFromCSV()
            throws IOException
    {
        Map<String, CorrectedInstance> result = new TreeMap<>();
        // read corrections
        List<String> fileNames = Arrays.asList("mturk/annotation-task/97-post-validation.csv",
                "mturk/annotation-task/97-post-validation2.csv");
        for (String fileName : fileNames) {
            CSVParser csvParser = CSVParser
                    .parse(new File(fileName), Charset.forName("utf-8"), CSVFormat.RFC4180);

            Iterator<CSVRecord> iterator = csvParser.iterator();

            while (iterator.hasNext()) {
                CSVRecord firstLine = iterator.next();
                CSVRecord secondLine = iterator.next();
                CSVRecord thirdLine = iterator.next();

                String id = firstLine.get(0);
                boolean skipRecord = "x".equals(firstLine.get(1)) || firstLine.get(1).isEmpty();

                if (!skipRecord) {
                    int correctLabel = Integer.valueOf(firstLine.get(1));

                    //                String[] split = secondLine.get(2).split("\\W", 2);
                    //                System.out.println(Arrays.toString(split));
                    int secondLineLabel = Integer.valueOf(secondLine.get(2).split("\\W", 2)[0]);
                    String secondLineText = secondLine.get(2).split("\\W", 2)[1];

                    int thirdLineLabel = Integer.valueOf(thirdLine.get(2).split("\\W", 2)[0]);
                    String thirdLineText = thirdLine.get(2).split("\\W", 2)[1];

                    System.out.println(correctLabel);
                    System.out.println(secondLineLabel + ", " + secondLineText);
                    System.out.println(thirdLineLabel + ", " + thirdLineText);

                    String originalWarrant;
                    String alternativeWarrant;
                    if (correctLabel == secondLineLabel) {
                        originalWarrant = secondLineText;
                        alternativeWarrant = thirdLineText;
                    }
                    else {
                        originalWarrant = thirdLineText;
                        alternativeWarrant = secondLineText;
                    }

                    CorrectedInstance correctedInstance = new CorrectedInstance(originalWarrant,
                            alternativeWarrant);
//                    System.out.println(correctedInstance);

                    result.put(id, correctedInstance);
                }
            }

            System.out.println(result.size());
        }
        return result;
    }
 
開發者ID:UKPLab,項目名稱:argument-reasoning-comprehension-task,代碼行數:60,代碼來源:Step8bTaskValidationGoldAnnotator.java

示例15: nextKeyValueInZip

import org.apache.commons.csv.CSVParser; //導入方法依賴的package包/類
private boolean nextKeyValueInZip() throws IOException, InterruptedException{
    ZipInputStream zis = (ZipInputStream) zipIn;
    while (true) {
        currZipEntry = zis.getNextEntry();
        if (currZipEntry == null) {
            break;
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("ZipEntry: " + currZipEntry.getName());
        }
        if (currZipEntry.getSize() == 0) {
            continue;
        }
        subId = currZipEntry.getName();
        if (encoding == null) {
            instream = new InputStreamReader(zis);
        } else {
            instream = new InputStreamReader(zis, encoding);
        }
        parser = new CSVParser(instream, CSVParserFormatter.
    		getFormat(delimiter, encapsulator, true,
    				true));
        parserIterator = parser.iterator();
        // clear metadata
        fields = null;
        if (super.nextKeyValue()) {
            // current delim txt has next
            return true;
        }
        // continue read next zip entry if any
    }
    // end of zip
    if (iterator != null && iterator.hasNext()) {
        close();
        initStream(iterator.next());
        return nextKeyValueInZip();
    } else {
        hasNext = false;
        return false;
    }
}
 
開發者ID:marklogic,項目名稱:marklogic-contentpump,代碼行數:42,代碼來源:CompressedDelimitedTextReader.java


注:本文中的org.apache.commons.csv.CSVParser.iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。