ARFFVectorIterable implements Iterable<Vector> { @Override public Iterator<Vector> iterator() { return new ARFFIterator(buff, model); } ARFFVectorIterable(File file, ARFFModel model);  ARFFVectorIterable(File file, Charset encoding, ARFFModel model);  ARFFVectorIterable(String arff, ARFFModel model);  ARFFVectorIterable(Reader reader, ARFFModel model); @Override Iterator<Vector> iterator(); ARFFModel getModel();  }
@Test public void testDense() throws Exception { Iterable<Vector> iterable = readModelFromResource("sample-dense.arff"); Vector firstVector = iterable.iterator().next(); assertEquals(1.0, firstVector.get(0), 0); assertEquals(65.0, firstVector.get(1), 0); assertEquals(1.0, firstVector.get(3), 0); assertEquals(1.0, firstVector.get(4), 0); int count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof DenseVector); count++; } assertEquals(5, count); }
@Test public void testSparse() throws Exception { Iterable<Vector> iterable = readModelFromResource("sample-sparse.arff"); Vector firstVector = iterable.iterator().next(); assertEquals(23.1, firstVector.get(1), 0); assertEquals(3.23, firstVector.get(2), 0); assertEquals(1.2, firstVector.get(3), 0); int count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof RandomAccessSparseVector); count++; } assertEquals(9, count); }
@Test public void testDate() throws Exception { ARFFVectorIterable iterable = readModelFromResource("date.arff"); Iterator<Vector> iter = iterable.iterator(); Vector firstVector = iter.next(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); Date date = format.parse("2001-07-04T12:08:56"); long result = date.getTime(); assertEquals(result, firstVector.get(1), 0); format = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z", Locale.ENGLISH); date = format.parse("2001.07.04 AD at 12:08:56 PDT"); result = date.getTime(); assertEquals(result, firstVector.get(2), 0); format = new SimpleDateFormat("EEE, MMM d, ''yy", Locale.ENGLISH); date = format.parse("Wed, Jul 4, '01,4 0:08 PM, PDT"); result = date.getTime(); assertEquals(result, firstVector.get(3), 0); format = new SimpleDateFormat("K:mm a, z", Locale.ENGLISH); date = format.parse("0:08 PM, PDT"); result = date.getTime(); assertEquals(result, firstVector.get(4), 0); format = new SimpleDateFormat("yyyyy.MMMMM.dd GGG hh:mm aaa", Locale.ENGLISH); date = format.parse("02001.July.04 AD 12:08 PM"); result = date.getTime(); assertEquals(result, firstVector.get(5), 0); format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH); date = format.parse("Wed, 4 Jul 2001 12:08:56 -0700"); result = date.getTime(); assertEquals(result, firstVector.get(6), 0); }
@Test public void testDense() throws Exception { ARFFModel model = new MapBackedARFFModel(); Iterable<Vector> iterable = new ARFFVectorIterable(SAMPLE_DENSE_ARFF, model); Vector firstVector = iterable.iterator().next(); assertEquals(1.0, firstVector.get(0), 0); assertEquals(65.0, firstVector.get(1), 0); assertEquals(1.0, firstVector.get(3), 0); assertEquals(1.0, firstVector.get(4), 0); int count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof DenseVector); count++; } assertEquals(5, count); }
@Test public void testSparse() throws Exception { ARFFModel model = new MapBackedARFFModel(); Iterable<Vector> iterable = new ARFFVectorIterable(SAMPLE_SPARSE_ARFF, model); Vector firstVector = iterable.iterator().next(); assertEquals(23.1, firstVector.get(1), 0); assertEquals(3.23, firstVector.get(2), 0); assertEquals(1.2, firstVector.get(3), 0); int count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof RandomAccessSparseVector); count++; } assertEquals(9, count); }