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

Last change on this file since 32 was 32, checked in by ftrautsch, 10 years ago

integrating decent into crosspare

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