本文整理汇总了Java中org.datavec.api.records.reader.impl.csv.CSVRecordReader.next方法的典型用法代码示例。如果您正苦于以下问题:Java CSVRecordReader.next方法的具体用法?Java CSVRecordReader.next怎么用?Java CSVRecordReader.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.datavec.api.records.reader.impl.csv.CSVRecordReader
的用法示例。
在下文中一共展示了CSVRecordReader.next方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testWrite
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testWrite() throws Exception {
File tempFile = File.createTempFile("datavec", "writer");
tempFile.deleteOnExit();
CSVRecordWriter writer = new CSVRecordWriter(tempFile);
List<Writable> collection = new ArrayList<>();
collection.add(new Text("12"));
collection.add(new Text("13"));
collection.add(new Text("14"));
writer.write(collection);
CSVRecordReader reader = new CSVRecordReader(0);
reader.initialize(new FileSplit(tempFile));
int cnt = 0;
while (reader.hasNext()) {
List<Writable> line = new ArrayList<>(reader.next());
assertEquals(3, line.size());
assertEquals(12, line.get(0).toInt());
assertEquals(13, line.get(1).toInt());
assertEquals(14, line.get(2).toInt());
cnt++;
}
assertEquals(1, cnt);
}
示例5: testNext
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testNext() throws Exception {
CSVRecordReader reader = new CSVRecordReader();
reader.initialize(new StringSplit("1,1,8.0,,,,14.0,,,,15.0,,,,,,,,,,,,1"));
while (reader.hasNext()) {
List<Writable> vals = reader.next();
List<Writable> arr = new ArrayList<>(vals);
assertEquals("Entry count", 23, vals.size());
Text lastEntry = (Text) arr.get(arr.size() - 1);
assertEquals("Last entry garbage", 1, lastEntry.getLength());
}
}
示例6: testEmptyEntries
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testEmptyEntries() throws Exception {
CSVRecordReader reader = new CSVRecordReader();
reader.initialize(new StringSplit("1,1,8.0,,,,14.0,,,,15.0,,,,,,,,,,,,"));
while (reader.hasNext()) {
List<Writable> vals = reader.next();
assertEquals("Entry count", 23, vals.size());
}
}
示例7: testTabsAsSplit1
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testTabsAsSplit1() throws Exception {
CSVRecordReader reader = new CSVRecordReader(0, '\t');
reader.initialize(new FileSplit(new ClassPathResource("/tabbed.txt").getFile()));
while (reader.hasNext()) {
List<Writable> list = new ArrayList<>(reader.next());
assertEquals(2, list.size());
}
}
示例8: testPipesAsSplit
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testPipesAsSplit() throws Exception {
CSVRecordReader reader = new CSVRecordReader(0, '|');
reader.initialize(new FileSplit(new ClassPathResource("issue414.csv").getFile()));
int lineidx = 0;
List<Integer> sixthColumn = Arrays.asList(13, 95, 15, 25);
while (reader.hasNext()) {
List<Writable> list = new ArrayList<>(reader.next());
assertEquals(10, list.size());
assertEquals((long)sixthColumn.get(lineidx), list.get(5).toInt());
lineidx++;
}
}
示例9: testWithQuotes
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testWithQuotes() throws Exception {
CSVRecordReader reader = new CSVRecordReader(0, ',', '\"');
reader.initialize(new StringSplit("1,0,3,\"Braund, Mr. Owen Harris\",male,\"\"\"\""));
while (reader.hasNext()) {
List<Writable> vals = reader.next();
assertEquals("Entry count", 6, vals.size());
assertEquals("1", vals.get(0).toString());
assertEquals("0", vals.get(1).toString());
assertEquals("3", vals.get(2).toString());
assertEquals("Braund, Mr. Owen Harris", vals.get(3).toString());
assertEquals("male", vals.get(4).toString());
assertEquals("\"", vals.get(5).toString());
}
}
示例10: testRegex
import org.datavec.api.records.reader.impl.csv.CSVRecordReader; //导入方法依赖的package包/类
@Test
public void testRegex() throws Exception {
CSVRecordReader reader = new CSVRegexRecordReader(0, ",", null, new String[] {null, "(.+) (.+) (.+)"});
reader.initialize(new StringSplit("normal,1.2.3.4 space separator"));
while (reader.hasNext()) {
List<Writable> vals = reader.next();
assertEquals("Entry count", 4, vals.size());
assertEquals("normal", vals.get(0).toString());
assertEquals("1.2.3.4", vals.get(1).toString());
assertEquals("space", vals.get(2).toString());
assertEquals("separator", vals.get(3).toString());
}
}