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
RevLine 
[86]1// Copyright 2015 Georg-August-Universität Göttingen, Germany
[41]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
[2]15package de.ugoe.cs.cpdp.loader;
16
17import java.io.File;
[132]18import java.util.ArrayList;
[2]19import java.util.LinkedList;
20import java.util.List;
21
[132]22import weka.core.Attribute;
[2]23import weka.core.Instances;
24
25import de.ugoe.cs.cpdp.versions.SoftwareVersion;
26
[4]27/**
[41]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.
[4]30 *
31 * @author Steffen Herbold
32 */
[2]33public abstract class AbstractFolderLoader implements IVersionLoader {
34
[41]35    /**
36     * Path of the data.
37     */
38    protected String path = "";
[142]39   
[41]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    }
[4]47
[135]48    /*
[41]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>();
[4]54
[41]55        final File dataDir = new File(path);
56        final SingleVersionLoader instancesLoader = getSingleLoader();
[74]57        if (dataDir.listFiles() == null) {
58            return versions;
59        }
[142]60        String datasetName = dataDir.getName();
61       
[41]62        for (File projectDir : dataDir.listFiles()) {
63            if (projectDir.isDirectory()) {
64                String projectName = projectDir.getName();
[74]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);
[83]71                            String versionName = data.relationName();
[135]72                            List<Double> efforts = getEfforts(data);
73                            versions
[142]74                                .add(new SoftwareVersion(datasetName, projectName, versionName, data, efforts));
[74]75                        }
[41]76                    }
77                }
78            }
79        }
80        return versions;
81    }
[135]82
83    /**
84     * <p>
85     * Sets the efforts for the instances
86     * </p>
87     *
88     * @param data
89     *            the data
90     * @return
91     */
[132]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        }
[135]107        if (effortAtt == null) {
[132]108            return null;
109        }
110        List<Double> efforts = new ArrayList<>(data.size());
[135]111        for (int i = 0; i < data.size(); i++) {
[132]112            efforts.add(data.get(i).value(effortAtt));
113        }
114        return efforts;
115    }
[4]116
[41]117    /**
118     * Returns the concrete {@link SingleVersionLoader} to be used with this folder loader.
119     *
[135]120     * @return the version loader
[41]121     */
122    abstract protected SingleVersionLoader getSingleLoader();
[2]123}
Note: See TracBrowser for help on using the repository browser.