[135] | 1 |
|
---|
[119] | 2 | package de.ugoe.cs.cpdp.loader;
|
---|
| 3 |
|
---|
| 4 | import java.io.BufferedReader;
|
---|
| 5 | import java.io.File;
|
---|
| 6 | import java.io.FileReader;
|
---|
| 7 | import java.io.IOException;
|
---|
| 8 | import java.util.HashSet;
|
---|
| 9 | import java.util.Set;
|
---|
| 10 |
|
---|
| 11 | import weka.core.Instances;
|
---|
| 12 |
|
---|
[135] | 13 | /**
|
---|
| 14 | * <p>
|
---|
| 15 | * Loads data from the RELINK data set.
|
---|
| 16 | * </p>
|
---|
| 17 | *
|
---|
| 18 | * @author Steffen Herbold
|
---|
| 19 | */
|
---|
[119] | 20 | public class RelinkLoader implements SingleVersionLoader {
|
---|
| 21 |
|
---|
| 22 | @Override
|
---|
| 23 | public Instances load(File file) {
|
---|
| 24 | BufferedReader reader;
|
---|
| 25 | Instances tmpData;
|
---|
| 26 | try {
|
---|
| 27 | reader = new BufferedReader(new FileReader(file));
|
---|
| 28 | tmpData = new Instances(reader);
|
---|
| 29 | reader.close();
|
---|
| 30 | }
|
---|
| 31 | catch (IOException e) {
|
---|
| 32 | throw new RuntimeException("error reading file: " + file.getName(), e);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | Set<String> attrNames = new HashSet<>();
|
---|
| 36 | attrNames.add("AvgCyclomatic");
|
---|
| 37 | attrNames.add("AvgCyclomaticModified");
|
---|
| 38 | attrNames.add("AvgCyclomaticStrict");
|
---|
| 39 | attrNames.add("AvgEssential");
|
---|
| 40 | attrNames.add("AvgLine");
|
---|
| 41 | attrNames.add("AvgLineBlank");
|
---|
| 42 | attrNames.add("AvgLineCode");
|
---|
| 43 | attrNames.add("AvgLineComment");
|
---|
| 44 | attrNames.add("CountClassBase");
|
---|
| 45 | attrNames.add("CountClassCoupled");
|
---|
| 46 | attrNames.add("CountClassDerived");
|
---|
| 47 | attrNames.add("CountDeclClassMethod");
|
---|
| 48 | attrNames.add("CountDeclClassVariable");
|
---|
| 49 | attrNames.add("CountDeclInstanceMethod");
|
---|
| 50 | attrNames.add("CountDeclInstanceVariable");
|
---|
| 51 | attrNames.add("CountDeclMethod");
|
---|
| 52 | attrNames.add("CountDeclMethodAll");
|
---|
| 53 | attrNames.add("CountDeclMethodPrivate");
|
---|
| 54 | attrNames.add("CountDeclMethodProtected");
|
---|
| 55 | attrNames.add("CountDeclMethodPublic");
|
---|
| 56 | attrNames.add("CountLine");
|
---|
| 57 | attrNames.add("CountLineBlank");
|
---|
| 58 | attrNames.add("CountLineCode");
|
---|
| 59 | attrNames.add("CountLineCodeDecl");
|
---|
| 60 | attrNames.add("CountLineCodeExe");
|
---|
| 61 | attrNames.add("CountLineComment");
|
---|
| 62 | attrNames.add("CountSemicolon");
|
---|
| 63 | attrNames.add("CountStmt");
|
---|
| 64 | attrNames.add("CountStmtDecl");
|
---|
| 65 | attrNames.add("CountStmtExe");
|
---|
| 66 | attrNames.add("MaxCyclomatic");
|
---|
| 67 | attrNames.add("MaxCyclomaticModified");
|
---|
| 68 | attrNames.add("MaxCyclomaticStrict");
|
---|
| 69 | attrNames.add("MaxInheritanceTree");
|
---|
| 70 | attrNames.add("PercentLackOfCohesion");
|
---|
| 71 | attrNames.add("RatioCommentToCode");
|
---|
| 72 | attrNames.add("SumCyclomatic");
|
---|
| 73 | attrNames.add("SumCyclomaticModified");
|
---|
| 74 | attrNames.add("SumCyclomaticStrict");
|
---|
| 75 | attrNames.add("SumEssential");
|
---|
| 76 | attrNames.add("isDefective");
|
---|
[135] | 77 |
|
---|
| 78 | for (int j = tmpData.numAttributes() - 1; j >= 0; j--) {
|
---|
| 79 | if (!attrNames.contains(tmpData.attribute(j).name())) {
|
---|
[119] | 80 | tmpData.deleteAttributeAt(j);
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
[135] | 83 |
|
---|
[119] | 84 | // setting class attribute
|
---|
| 85 | tmpData.setClassIndex(tmpData.numAttributes() - 1);
|
---|
| 86 |
|
---|
| 87 | return tmpData;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | @Override
|
---|
| 91 | public boolean filenameFilter(String file) {
|
---|
| 92 | return file.endsWith(".arff");
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | }
|
---|