1 public void loadData(String path) throws IOException
2 {
3 BufferedReader br = new BufferedReader(new FileReader(new File(path)));
4 String line = br.readLine();
5 while (line != null)
6 {
7 String[] segs = line.split("\\s");
8 String label = segs[0];
9 List<String> fieldList = new ArrayList<String>();
10 for (int i = 1; i < segs.length; ++i)
11 {
12 fieldList.add(segs[i]);
13 Feature feature = new Feature(label, segs[i]);
14 int index = featureList.indexOf(feature);
15 if (index == -1)
16 {
17 featureList.add(feature);
18 featureCountList.add(1);
19 }
20 else
21 {
22 featureCountList.set(index, featureCountList.get(index) + 1);
23 }
24 }
25 if (fieldList.size() > C) C = fieldList.size();
26 Instance instance = new Instance(label, fieldList);
27 instanceList.add(instance);
28 if (labels.indexOf(label) == -1) labels.add(label);
29 line = br.readLine();
30 }
31 }