当前位置: 首页>>代码示例>>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;未经允许,请勿转载。