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

Last change on this file since 70 was 41, checked in by sherbold, 9 years ago
  • formatted code and added copyrights
  • Property svn:mime-type set to text/plain
File size: 1.9 KB
Line 
1// Copyright 2015 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.cpdp.loader;
16
17import java.io.BufferedReader;
18import java.io.File;
19import java.io.FileReader;
20import java.io.IOException;
21
22import weka.core.Instances;
23
24/**
25 * Loads ARFF files and chooses the last attribute as class attribute.
26 *
27 * @author Steffen Herbold
28 */
29public class ARFFLoader implements SingleVersionLoader {
30
31    /*
32     * (non-Javadoc)
33     *
34     * @see de.ugoe.cs.cpdp.loader.SingleVersionLoader#load(java.io.File)
35     */
36    @Override
37    public Instances load(File file) {
38        BufferedReader reader;
39        Instances data;
40        try {
41            reader = new BufferedReader(new FileReader(file));
42            data = new Instances(reader);
43            reader.close();
44        }
45        catch (IOException e) {
46            throw new RuntimeException("error reading file: " + file.getName(), e);
47        }
48
49        // setting class attribute
50        data.setClassIndex(data.numAttributes() - 1);
51
52        return data;
53    }
54
55    /*
56     * (non-Javadoc)
57     *
58     * @see de.ugoe.cs.cpdp.loader.SingleVersionLoader#filenameFilter(java.lang.String )
59     */
60    @Override
61    public boolean filenameFilter(String filename) {
62        return filename.endsWith(".arff");
63    }
64
65}
Note: See TracBrowser for help on using the repository browser.