source: trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/ARFFLoader.java @ 27

Last change on this file since 27 was 6, checked in by sherbold, 10 years ago
  • improved Javadocs and exception handling
  • added getName() to ITrainingStrategy
  • Property svn:mime-type set to text/plain
File size: 1.1 KB
Line 
1package de.ugoe.cs.cpdp.loader;
2
3import java.io.BufferedReader;
4import java.io.File;
5import java.io.FileReader;
6import java.io.IOException;
7
8import weka.core.Instances;
9
10/**
11 * Loads ARFF files and chooses the last attribute as class attribute.
12 *
13 * @author Steffen Herbold
14 */
15public class ARFFLoader implements SingleVersionLoader {
16
17        /*
18         * (non-Javadoc)
19         *
20         * @see de.ugoe.cs.cpdp.loader.SingleVersionLoader#load(java.io.File)
21         */
22        @Override
23        public Instances load(File file) {
24                BufferedReader reader;
25                Instances data;
26                try {
27                        reader = new BufferedReader(new FileReader(file));
28                        data = new Instances(reader);
29                        reader.close();
30                } catch (IOException e) {
31                        throw new RuntimeException("error reading file: " + file.getName(), e);
32                }
33
34                // setting class attribute
35                data.setClassIndex(data.numAttributes() - 1);
36
37                return data;
38        }
39
40        /*
41         * (non-Javadoc)
42         *
43         * @see
44         * de.ugoe.cs.cpdp.loader.SingleVersionLoader#filenameFilter(java.lang.String
45         * )
46         */
47        @Override
48        public boolean filenameFilter(String filename) {
49                return filename.endsWith(".arff");
50        }
51
52}
Note: See TracBrowser for help on using the repository browser.