本文整理匯總了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();
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
示例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);
}
示例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;
}
示例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()); }
}
示例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()); }
}
示例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;
}
示例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);
}
}
示例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;
}
}