本文整理汇总了Java中org.datavec.api.records.reader.impl.csv.CSVRecordReader.reset方法的典型用法代码示例。如果您正苦于以下问题:Java CSVRecordReader.reset方法的具体用法?Java CSVRecordReader.reset怎么用?Java CSVRecordReader.reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.datavec.api.records.reader.impl.csv.CSVRecordReader
的用法示例。
在下文中一共展示了CSVRecordReader.reset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReset
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testReset() throws Exception {
CSVRecordReader rr = new CSVRecordReader(0, ',');
rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));
int nResets = 5;
for (int i = 0; i < nResets; i++) {
int lineCount = 0;
while (rr.hasNext()) {
List<Writable> line = rr.next();
assertEquals(5, line.size());
lineCount++;
}
assertFalse(rr.hasNext());
assertEquals(150, lineCount);
rr.reset();
}
}
示例2: testResetWithSkipLines
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testResetWithSkipLines() throws Exception {
CSVRecordReader rr = new CSVRecordReader(10, ',');
rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));
int lineCount = 0;
while (rr.hasNext()) {
rr.next();
++lineCount;
}
assertEquals(140, lineCount);
rr.reset();
lineCount = 0;
while (rr.hasNext()) {
rr.next();
++lineCount;
}
assertEquals(140, lineCount);
}
示例3: testCsvSkipAllLines
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testCsvSkipAllLines() throws IOException, InterruptedException {
final int numLines = 4;
final List<Writable> lineList = Arrays.asList((Writable) new IntWritable(numLines - 1),
(Writable) new Text("one"), (Writable) new Text("two"), (Writable) new Text("three"));
String header = ",one,two,three";
List<String> lines = new ArrayList<>();
for (int i = 0; i < numLines; i++)
lines.add(Integer.toString(i) + header);
File tempFile = File.createTempFile("csvSkipLines", ".csv");
FileUtils.writeLines(tempFile, lines);
CSVRecordReader rr = new CSVRecordReader(numLines, ',');
rr.initialize(new FileSplit(tempFile));
rr.reset();
assertTrue(!rr.hasNext());
rr.next();
}
示例4: testCsvSkipAllButOneLine
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testCsvSkipAllButOneLine() throws IOException, InterruptedException {
final int numLines = 4;
final List<Writable> lineList = Arrays.<Writable>asList(new Text(Integer.toString(numLines - 1)),
new Text("one"), new Text("two"), new Text("three"));
String header = ",one,two,three";
List<String> lines = new ArrayList<>();
for (int i = 0; i < numLines; i++)
lines.add(Integer.toString(i) + header);
File tempFile = File.createTempFile("csvSkipLines", ".csv");
FileUtils.writeLines(tempFile, lines);
CSVRecordReader rr = new CSVRecordReader(numLines - 1, ',');
rr.initialize(new FileSplit(tempFile));
rr.reset();
assertTrue(rr.hasNext());
assertEquals(rr.next(), lineList);
}
示例5: testStreamReset
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testStreamReset() throws Exception {
CSVRecordReader rr = new CSVRecordReader(0, ',');
rr.initialize(new InputStreamInputSplit(new ClassPathResource("iris.dat").getInputStream()));
int count = 0;
while(rr.hasNext()){
assertNotNull(rr.next());
count++;
}
assertEquals(150, count);
assertFalse(rr.resetSupported());
try{
rr.reset();
fail("Expected exception");
} catch (Exception e){
e.printStackTrace();
}
}
示例6: testMeta
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testMeta() throws Exception {
CSVRecordReader rr = new CSVRecordReader(0, ',');
rr.initialize(new FileSplit(new ClassPathResource("iris.dat").getFile()));
int lineCount = 0;
List<RecordMetaData> metaList = new ArrayList<>();
List<List<Writable>> writables = new ArrayList<>();
while (rr.hasNext()) {
Record r = rr.nextRecord();
assertEquals(5, r.getRecord().size());
lineCount++;
RecordMetaData meta = r.getMetaData();
// System.out.println(r.getRecord() + "\t" + meta.getLocation() + "\t" + meta.getURI());
metaList.add(meta);
writables.add(r.getRecord());
}
assertFalse(rr.hasNext());
assertEquals(150, lineCount);
rr.reset();
System.out.println("\n\n\n--------------------------------");
List<Record> contents = rr.loadFromMetaData(metaList);
assertEquals(150, contents.size());
// for(Record r : contents ){
// System.out.println(r);
// }
List<RecordMetaData> meta2 = new ArrayList<>();
meta2.add(metaList.get(100));
meta2.add(metaList.get(90));
meta2.add(metaList.get(80));
meta2.add(metaList.get(70));
meta2.add(metaList.get(60));
List<Record> contents2 = rr.loadFromMetaData(meta2);
assertEquals(writables.get(100), contents2.get(0).getRecord());
assertEquals(writables.get(90), contents2.get(1).getRecord());
assertEquals(writables.get(80), contents2.get(2).getRecord());
assertEquals(writables.get(70), contents2.get(3).getRecord());
assertEquals(writables.get(60), contents2.get(4).getRecord());
}