source: trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/DecentFolderLoader.java @ 69

Last change on this file since 69 was 41, checked in by sherbold, 9 years ago
  • formatted code and added copyrights
  • Property svn:mime-type set to text/plain
File size: 3.8 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.LinkedList;
19import java.util.List;
20
21import weka.core.Instances;
22
23import de.ugoe.cs.cpdp.versions.SoftwareVersion;
24
25/**
26 * Implements the {@link AbstractFolderLoader}
27 *
28 * @author Fabian Trautsch
29 */
30public class DecentFolderLoader extends AbstractFolderLoader {
31
32    /*
33     * (non-Javadoc)
34     *
35     * @see de.ugoe.cs.cpdp.loader.AbstractFolderLoader#getSingleLoader()
36     */
37    @Override
38    protected SingleVersionLoader getSingleLoader() {
39        return new DecentDataLoader();
40    }
41
42    /**
43     * @see de.ugoe.cs.cpdp.loader.IVersionLoader#load()
44     */
45    @Override
46    public List<SoftwareVersion> load() {
47        final List<SoftwareVersion> versions = new LinkedList<SoftwareVersion>();
48
49        final File dataDir = new File(path);
50        final SingleVersionLoader instancesLoader = getSingleLoader();
51
52        String projectName = dataDir.getName();
53
54        /*
55         * The following lines make it possible, that we can have two different possibilities to
56         * load data: 1) From one project (e.g. /decent/input/project1) 2) From more than one
57         * project (e.g. /decent/input/)
58         *
59         * Requirement is, that we have a folder structure like this:
60         * "/decent/input/project1/model.decent, /decent/input/project2/model.decent, ..."
61         *
62         * In the first one the "else" is executed, therefore it will just search the folder
63         * "project1" for a "model.decent" file. In the second one, it will look into each folder
64         * and searches for "model.decent" files.
65         */
66        for (File projectDir : dataDir.listFiles()) {
67            if (projectDir.isDirectory()) {
68                projectName = projectDir.getName();
69                for (File versionFile : projectDir.listFiles()) {
70                    loadDataFromFile(versionFile, instancesLoader, projectName, versions);
71                }
72            }
73            else {
74                loadDataFromFile(projectDir, instancesLoader, projectName, versions);
75            }
76        }
77        return versions;
78    }
79
80    /**
81     * Loads data from a file and adds the instances from the load method to the versions List.
82     *
83     * @param versionFile
84     *            file to load from
85     * @param instancesLoader
86     *            loader that should be used
87     * @param projectName
88     *            name of the project which was loaded
89     * @param versions
90     *            list, where the weka instances are added to
91     */
92
93    private void loadDataFromFile(File versionFile,
94                                  SingleVersionLoader instancesLoader,
95                                  String projectName,
96                                  List<SoftwareVersion> versions)
97    {
98        if (versionFile.isFile() && instancesLoader.filenameFilter(versionFile.getName())) {
99            String versionName = versionFile.getName();
100            Instances data = instancesLoader.load(versionFile);
101            versions.add(new SoftwareVersion(projectName, versionName, data));
102        }
103    }
104
105}
Note: See TracBrowser for help on using the repository browser.