[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 |
|
---|
[32] | 15 | package de.ugoe.cs.cpdp.loader;
|
---|
| 16 |
|
---|
| 17 | import java.io.File;
|
---|
| 18 | import java.util.LinkedList;
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
| 21 | import weka.core.Instances;
|
---|
| 22 |
|
---|
| 23 | import de.ugoe.cs.cpdp.versions.SoftwareVersion;
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * Implements the {@link AbstractFolderLoader}
|
---|
| 27 | *
|
---|
| 28 | * @author Fabian Trautsch
|
---|
| 29 | */
|
---|
| 30 | public class DecentFolderLoader extends AbstractFolderLoader {
|
---|
| 31 |
|
---|
[41] | 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 | }
|
---|
[32] | 41 |
|
---|
[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>();
|
---|
[32] | 48 |
|
---|
[41] | 49 | final File dataDir = new File(path);
|
---|
| 50 | final SingleVersionLoader instancesLoader = getSingleLoader();
|
---|
[32] | 51 |
|
---|
[41] | 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 | */
|
---|
[74] | 66 | if (dataDir.listFiles() == null) {
|
---|
| 67 | return versions;
|
---|
| 68 | }
|
---|
[41] | 69 | for (File projectDir : dataDir.listFiles()) {
|
---|
| 70 | if (projectDir.isDirectory()) {
|
---|
| 71 | projectName = projectDir.getName();
|
---|
[74] | 72 | if (projectDir.listFiles() != null) {
|
---|
| 73 | for (File versionFile : projectDir.listFiles()) {
|
---|
| 74 | loadDataFromFile(versionFile, instancesLoader, projectName, versions);
|
---|
| 75 | }
|
---|
[41] | 76 | }
|
---|
| 77 | }
|
---|
| 78 | else {
|
---|
| 79 | loadDataFromFile(projectDir, instancesLoader, projectName, versions);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | return versions;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /**
|
---|
| 86 | * Loads data from a file and adds the instances from the load method to the versions List.
|
---|
| 87 | *
|
---|
| 88 | * @param versionFile
|
---|
| 89 | * file to load from
|
---|
| 90 | * @param instancesLoader
|
---|
| 91 | * loader that should be used
|
---|
| 92 | * @param projectName
|
---|
| 93 | * name of the project which was loaded
|
---|
| 94 | * @param versions
|
---|
| 95 | * list, where the weka instances are added to
|
---|
| 96 | */
|
---|
| 97 |
|
---|
| 98 | private void loadDataFromFile(File versionFile,
|
---|
| 99 | SingleVersionLoader instancesLoader,
|
---|
| 100 | String projectName,
|
---|
| 101 | List<SoftwareVersion> versions)
|
---|
| 102 | {
|
---|
| 103 | if (versionFile.isFile() && instancesLoader.filenameFilter(versionFile.getName())) {
|
---|
| 104 | String versionName = versionFile.getName();
|
---|
| 105 | Instances data = instancesLoader.load(versionFile);
|
---|
[132] | 106 | versions.add(new SoftwareVersion(projectName, versionName, data, null));
|
---|
[41] | 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[32] | 110 | }
|
---|