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