ARFFVectorIterable implements Iterable<Vector> { public ARFFModel getModel() { return 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 testNonNumeric() throws Exception { MapBackedARFFModel model = new MapBackedARFFModel(); ARFFVectorIterable iterable = new ARFFVectorIterable(NON_NUMERIC_ARFF, model); int count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof RandomAccessSparseVector); count++; } assertEquals(10, count); Map<String, Map<String, Integer>> nominalMap = iterable.getModel().getNominalMap(); assertNotNull(nominalMap); assertEquals(1, nominalMap.size()); Map<String, Integer> noms = nominalMap.get("bar"); assertNotNull("nominals for bar are null", noms); assertEquals(2, noms.size()); Map<Integer, ARFFType> integerARFFTypeMap = model.getTypeMap(); assertNotNull("Type map null", integerARFFTypeMap); assertEquals(5, integerARFFTypeMap.size()); Map<String, Long> words = model.getWords(); assertNotNull("words null", words); assertEquals(10, words.size()); Map<Integer, DateFormat> integerDateFormatMap = model.getDateMap(); assertNotNull("date format null", integerDateFormatMap); assertEquals(1, integerDateFormatMap.size()); }
@Test public void testMultipleNoms() throws Exception { MapBackedARFFModel model = new MapBackedARFFModel(); ARFFVectorIterable iterable = new ARFFVectorIterable(NON_NUMERIC_ARFF, model); int count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof RandomAccessSparseVector); count++; } assertEquals(10, count); Map<String, Map<String, Integer>> nominalMap = iterable.getModel().getNominalMap(); assertNotNull(nominalMap); assertEquals(1, nominalMap.size()); Map<String, Integer> noms = nominalMap.get("bar"); assertNotNull("nominals for bar are null", noms); assertEquals(2, noms.size()); Map<Integer, ARFFType> integerARFFTypeMap = model.getTypeMap(); assertNotNull("Type map null", integerARFFTypeMap); assertEquals(5, integerARFFTypeMap.size()); Map<String, Long> words = model.getWords(); assertNotNull("words null", words); assertEquals(10, words.size()); Map<Integer, DateFormat> integerDateFormatMap = model.getDateMap(); assertNotNull("date format null", integerDateFormatMap); assertEquals(1, integerDateFormatMap.size()); model = new MapBackedARFFModel(model.getWords(), model.getWordCount(), model.getNominalMap()); iterable = new ARFFVectorIterable(NON_NUMERIC_ARFF2, model); count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof RandomAccessSparseVector); count++; } nominalMap = model.getNominalMap(); assertNotNull(nominalMap); assertEquals(2, nominalMap.size()); noms = nominalMap.get("test"); assertNotNull("nominals for bar are null", noms); assertEquals(2, noms.size()); }
@Test public void testMultipleNoms() throws Exception { MapBackedARFFModel model = new MapBackedARFFModel(); ARFFVectorIterable iterable = new ARFFVectorIterable(NON_NUMERIC_ARFF, model); int count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof RandomAccessSparseVector); count++; } assertEquals(10, count); Map<String,Map<String,Integer>> nominalMap = iterable.getModel().getNominalMap(); assertNotNull(nominalMap); assertEquals(1, nominalMap.size()); Map<String,Integer> noms = nominalMap.get("bar"); assertNotNull("nominals for bar are null", noms); assertEquals(2, noms.size()); Map<Integer,ARFFType> integerARFFTypeMap = model.getTypeMap(); assertNotNull("Type map null", integerARFFTypeMap); assertEquals(5, integerARFFTypeMap.size()); Map<String,Long> words = model.getWords(); assertNotNull("words null", words); assertEquals(10, words.size()); Map<Integer,DateFormat> integerDateFormatMap = model.getDateMap(); assertNotNull("date format null", integerDateFormatMap); assertEquals(1, integerDateFormatMap.size()); model = new MapBackedARFFModel(model.getWords(), model.getWordCount(), model.getNominalMap()); iterable = new ARFFVectorIterable(NON_NUMERIC_ARFF2, model); count = 0; for (Vector vector : iterable) { assertTrue("Vector is not dense", vector instanceof RandomAccessSparseVector); count++; } nominalMap = model.getNominalMap(); assertNotNull(nominalMap); assertEquals(2, nominalMap.size()); noms = nominalMap.get("test"); assertNotNull("nominals for bar are null", noms); assertEquals(2, noms.size()); }