1 | package de.ugoe.cs.cpdp.loader;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.util.LinkedList;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import weka.core.Instances;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.cpdp.versions.SoftwareVersion;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Implements the {@link AbstractFolderLoader}
|
---|
13 | *
|
---|
14 | * @author Fabian Trautsch
|
---|
15 | */
|
---|
16 | public 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 | }
|
---|