DataLine { public void set(String dlstr) { DataSet dataset = DataSet.getDataSet(); StringTokenizer tokenizer = new StringTokenizer(dlstr, ","); List<String> tokens = new ArrayList<String>(); while (tokenizer.hasMoreTokens()) { tokens.add(tokenizer.nextToken()); } List<Integer> ignored = dataset.getIgnoredAttributes(); for (int index = ignored.size() - 1; index >= 0; index--) { tokens.remove(index); } for (int index = 0; index < dataset.getNbAttributes(); index++) { if (dataset.isNumerical(index)) { attributes[index] = Double.parseDouble(tokens.get(index)); } else { attributes[index] = dataset.valueIndex(index, tokens.get(index)); } } } DataLine();  DataLine(String dl); int getLabel(); double getAttribute(int index); void set(String dlstr);  }
@Test public void testSet() throws Exception { FileSystem fs = FileSystem.get(new Configuration()); Path inpath = fs.makeQualified(new Path(Resources.getResource("wdbc").toString())); DataSet dataset = FileInfoParser.parseFile(fs, inpath); DataSet.initialize(dataset); DataLine dl = new DataLine(); int labelpos = dataset.getLabelIndex(); dl.set(DATA[0]); assertEquals(dataset.valueIndex(labelpos, "M"), dl.getLabel()); dl.set(DATA[1]); assertEquals(dataset.valueIndex(labelpos, "B"), dl.getLabel()); dl.set(DATA[2]); assertEquals(dataset.valueIndex(labelpos, "M"), dl.getLabel()); }