source: trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/AbstractFolderLoader.java

Last change on this file was 142, checked in by atrautsch, 8 years ago

heterogenous experiments

  • Property svn:mime-type set to text/plain
File size: 4.1 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.File;
18import java.util.ArrayList;
19import java.util.LinkedList;
20import java.util.List;
21
22import weka.core.Attribute;
23import weka.core.Instances;
24
25import de.ugoe.cs.cpdp.versions.SoftwareVersion;
26
27/**
28 * Abstract class for loading data from a folder. The subfolders of a defined folder define the
29 * projects, the file contained in the subfolder are the versions of a project.
30 *
31 * @author Steffen Herbold
32 */
33public abstract class AbstractFolderLoader implements IVersionLoader {
34
35    /**
36     * Path of the data.
37     */
38    protected String path = "";
39   
40    /**
41     * @see de.ugoe.cs.cpdp.loader.IVersionLoader#setLocation(java.lang.String)
42     */
43    @Override
44    public void setLocation(String location) {
45        path = location;
46    }
47
48    /*
49     * @see de.ugoe.cs.cpdp.loader.IVersionLoader#load()
50     */
51    @Override
52    public List<SoftwareVersion> load() {
53        final List<SoftwareVersion> versions = new LinkedList<SoftwareVersion>();
54
55        final File dataDir = new File(path);
56        final SingleVersionLoader instancesLoader = getSingleLoader();
57        if (dataDir.listFiles() == null) {
58            return versions;
59        }
60        String datasetName = dataDir.getName();
61       
62        for (File projectDir : dataDir.listFiles()) {
63            if (projectDir.isDirectory()) {
64                String projectName = projectDir.getName();
65                if (projectDir.listFiles() != null) {
66                    for (File versionFile : projectDir.listFiles()) {
67                        if (versionFile.isFile() &&
68                            instancesLoader.filenameFilter(versionFile.getName()))
69                        {
70                            Instances data = instancesLoader.load(versionFile);
71                            String versionName = data.relationName();
72                            List<Double> efforts = getEfforts(data);
73                            versions
74                                .add(new SoftwareVersion(datasetName, projectName, versionName, data, efforts));
75                        }
76                    }
77                }
78            }
79        }
80        return versions;
81    }
82
83    /**
84     * <p>
85     * Sets the efforts for the instances
86     * </p>
87     *
88     * @param data
89     *            the data
90     * @return
91     */
92    private List<Double> getEfforts(Instances data) {
93        // attribute in the JURECZKO data and default
94        Attribute effortAtt = data.attribute("loc");
95        if (effortAtt == null) {
96            // attribute in the NASA/SOFTMINE/MDP data
97            effortAtt = data.attribute("LOC_EXECUTABLE");
98        }
99        if (effortAtt == null) {
100            // attribute in the AEEEM data
101            effortAtt = data.attribute("numberOfLinesOfCode");
102        }
103        if (effortAtt == null) {
104            // attribute in the RELINK data
105            effortAtt = data.attribute("CountLineCodeExe");
106        }
107        if (effortAtt == null) {
108            return null;
109        }
110        List<Double> efforts = new ArrayList<>(data.size());
111        for (int i = 0; i < data.size(); i++) {
112            efforts.add(data.get(i).value(effortAtt));
113        }
114        return efforts;
115    }
116
117    /**
118     * Returns the concrete {@link SingleVersionLoader} to be used with this folder loader.
119     *
120     * @return the version loader
121     */
122    abstract protected SingleVersionLoader getSingleLoader();
123}
Note: See TracBrowser for help on using the repository browser.