Skip to content

Commit a52ef3d

Browse files
oshandooshando
oshando
authored and
oshando
committed
Refactor project directory
1 parent 5b213d7 commit a52ef3d

File tree

148 files changed

+474
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+474
-458
lines changed
File renamed without changes.

core/src/main/java/de/fraunhofer/iem/swan/data/Category.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/data/Category.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,18 @@ public static Category getCategoryForCWE(String cweName) {
4949
return c;
5050
return null;
5151
}
52+
53+
public static Category fromText(String text) {
54+
55+
for(Category cat: Category.values()){
56+
if(cat.name().equalsIgnoreCase(text)){
57+
return cat;
58+
}
59+
}
60+
61+
throw new IllegalArgumentException(String.format(
62+
"There is no category with name '%s'",
63+
text
64+
));
65+
}
5266
}

core/src/main/java/de/fraunhofer/iem/swan/data/XMLParser.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/data/XMLParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.fraunhofer.iem.swan.data;
22

3-
import javafx.util.Pair;
3+
import org.apache.commons.lang3.tuple.Pair;
44
import org.jdom2.Document;
55
import org.jdom2.Element;
66
import org.jdom2.Namespace;

core/src/main/java/de/fraunhofer/iem/swan/features/InstancesHandler.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features/InstancesHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void createInstances(Set<Method> trainingSet,
7575
instances = addSwanDocInstances(instances,trainingSet, docFeatures, categories, instanceSet);
7676
break;
7777
}
78-
7978
//exportInstances(trainInstances, categories);
8079
}
8180

core/src/main/java/de/fraunhofer/iem/swan/features/code/FeatureHandler.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features/code/FeatureHandler.java

Lines changed: 207 additions & 416 deletions
Large diffs are not rendered by default.

core/src/main/java/de/fraunhofer/iem/swan/features/doc/nlp/DocCommentVector.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features/doc/nlp/DocCommentVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void main(String[] args) {
4343
//Export method and class doc comments
4444

4545
Parser parser = new Parser();
46-
parser.parse("/data-set-with-doc-comments.json");
46+
parser.parse("/swan-dataset.json");
4747

4848
// for(Method method: parser.getMethods()){
4949
// if(method.getJavadoc().getMethodComment().length()>0)

core/src/main/java/de/fraunhofer/iem/swan/io/dataset/Writer.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/io/dataset/Writer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import de.fraunhofer.iem.swan.data.Constants;
55
import de.fraunhofer.iem.swan.data.Method;
66
import de.fraunhofer.iem.swan.data.XMLParser;
7-
import javafx.util.Pair;
7+
import org.apache.commons.lang3.tuple.Pair;
88
import org.apache.commons.io.FileUtils;
99
import org.json.simple.JSONArray;
1010
import org.json.simple.JSONObject;
@@ -256,13 +256,13 @@ public void writeResultsQwelXML(Set<Method> methods, String outputFile) {
256256

257257
if (method.getCategoriesClassified().toString().contains(Constants.SOURCE)) {
258258
sourcesList.append("/" + counter + " ");
259-
methodList.put("m" + counter, new Pair(Constants.SOURCE, method.getTrimmedSignature()));
259+
methodList.put("m" + counter, Pair.of(Constants.SOURCE, method.getTrimmedSignature()));
260260
counter++;
261261
}
262262

263263
if (method.getCategoriesClassified().toString().contains(Constants.SINK)) {
264264
sinksList.append("/" + counter + " ");
265-
methodList.put("m" + counter, new Pair(Constants.SINK, method.getTrimmedSignature()));
265+
methodList.put("m" + counter, Pair.of(Constants.SINK, method.getTrimmedSignature()));
266266
counter++;
267267
}
268268
}

core/src/main/java/de/fraunhofer/iem/swan/io/doc/DocletExecutor.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/io/doc/DocletExecutor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.fraunhofer.iem.swan.io.doc;
22

3-
import com.sun.tools.javadoc.Main;
3+
//import com.sun.tools.javadoc.Main;
4+
//import jdk.javadoc.doclet.StandardDoclet;
45

56
/**
67
* @author Oshando Johnson on 03.06.20
@@ -45,7 +46,7 @@ public void runDoclet(String sourcePath, String packages, String outputPath) {
4546
"-subpackages", packages
4647
};
4748
System.out.println();
48-
Main.execute(docletParams);
49+
//Main.execute(docletParams);
4950
}
5051

5152
public void runDoclet(String sourcePath, String packages) {
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:element name="ssldoclet" type="ssldocletType"/>
4+
<xs:complexType name="ClassType">
5+
<xs:simpleContent>
6+
<xs:extension base="xs:string">
7+
<xs:attribute type="xs:string" name="final"/>
8+
<xs:attribute type="xs:string" name="line"/>
9+
<xs:attribute type="xs:string" name="serializable"/>
10+
</xs:extension>
11+
</xs:simpleContent>
12+
</xs:complexType>
13+
<xs:complexType name="InterfaceType">
14+
<xs:simpleContent>
15+
<xs:extension base="xs:string">
16+
<xs:attribute type="xs:string" name="final"/>
17+
<xs:attribute type="xs:string" name="qualifiedType"/>
18+
<xs:attribute type="xs:string" name="serializable"/>
19+
<xs:attribute type="xs:string" name="type"/>
20+
<xs:attribute type="xs:string" name="superclass"/>
21+
<xs:attribute type="xs:string" name="superclassFullType"/>
22+
</xs:extension>
23+
</xs:simpleContent>
24+
</xs:complexType>
25+
<xs:complexType name="Interface_BlockType">
26+
<xs:sequence>
27+
<xs:element type="xs:string" name="Implements_Comment"/>
28+
<xs:element type="InterfaceType" name="Interface"/>
29+
</xs:sequence>
30+
</xs:complexType>
31+
<xs:complexType name="ExtendsType">
32+
<xs:simpleContent>
33+
<xs:extension base="xs:string">
34+
<xs:attribute type="xs:string" name="final"/>
35+
<xs:attribute type="xs:string" name="qualifiedType"/>
36+
<xs:attribute type="xs:string" name="serializable"/>
37+
<xs:attribute type="xs:string" name="superclass"/>
38+
<xs:attribute type="xs:string" name="superclassFullType"/>
39+
<xs:attribute type="xs:string" name="type"/>
40+
</xs:extension>
41+
</xs:simpleContent>
42+
</xs:complexType>
43+
<xs:complexType name="Extends_BlockType">
44+
<xs:sequence>
45+
<xs:element type="xs:string" name="Extends_Comment"/>
46+
<xs:element type="ExtendsType" name="Extends"/>
47+
</xs:sequence>
48+
</xs:complexType>
49+
<xs:complexType name="Class_CommentType">
50+
<xs:simpleContent>
51+
<xs:extension base="xs:string">
52+
<xs:attribute type="xs:string" name="line"/>
53+
</xs:extension>
54+
</xs:simpleContent>
55+
</xs:complexType>
56+
<xs:complexType name="Class_Comment_BlockType">
57+
<xs:sequence>
58+
<xs:element type="Class_CommentType" name="Class_Comment"/>
59+
</xs:sequence>
60+
</xs:complexType>
61+
<xs:complexType name="ConstructorType">
62+
<xs:simpleContent>
63+
<xs:extension base="xs:string">
64+
<xs:attribute type="xs:string" name="final"/>
65+
<xs:attribute type="xs:string" name="interface"/>
66+
<xs:attribute type="xs:string" name="line"/>
67+
<xs:attribute type="xs:string" name="modifier"/>
68+
<xs:attribute type="xs:string" name="signature"/>
69+
<xs:attribute type="xs:string" name="static"/>
70+
<xs:attribute type="xs:string" name="synchronized"/>
71+
<xs:attribute type="xs:string" name="synthetic"/>
72+
<xs:attribute type="xs:string" name="visibility"/>
73+
</xs:extension>
74+
</xs:simpleContent>
75+
</xs:complexType>
76+
<xs:complexType name="Constructor_CommentType">
77+
<xs:simpleContent>
78+
<xs:extension base="xs:string">
79+
<xs:attribute type="xs:string" name="line"/>
80+
</xs:extension>
81+
</xs:simpleContent>
82+
</xs:complexType>
83+
<xs:complexType name="Constructor_Comment_BlockType">
84+
<xs:sequence>
85+
<xs:element type="Constructor_CommentType" name="Constructor_Comment"/>
86+
</xs:sequence>
87+
</xs:complexType>
88+
<xs:complexType name="Constructor_BlockType">
89+
<xs:sequence>
90+
<xs:element type="ConstructorType" name="Constructor"/>
91+
<xs:element type="Constructor_Comment_BlockType" name="Constructor_Comment_Block"/>
92+
</xs:sequence>
93+
</xs:complexType>
94+
<xs:complexType name="ConstructorsType">
95+
<xs:sequence>
96+
<xs:element type="Constructor_BlockType" name="Constructor_Block"/>
97+
</xs:sequence>
98+
</xs:complexType>
99+
<xs:complexType name="MethodType">
100+
<xs:simpleContent>
101+
<xs:extension base="xs:string">
102+
<xs:attribute type="xs:string" name="abstract" use="optional"/>
103+
<xs:attribute type="xs:string" name="final" use="optional"/>
104+
<xs:attribute type="xs:string" name="interface" use="optional"/>
105+
<xs:attribute type="xs:string" name="line" use="optional"/>
106+
<xs:attribute type="xs:string" name="modifier" use="optional"/>
107+
<xs:attribute type="xs:string" name="signature" use="optional"/>
108+
<xs:attribute type="xs:string" name="static" use="optional"/>
109+
<xs:attribute type="xs:string" name="synchronized" use="optional"/>
110+
<xs:attribute type="xs:string" name="synthetic" use="optional"/>
111+
<xs:attribute type="xs:string" name="visibility" use="optional"/>
112+
</xs:extension>
113+
</xs:simpleContent>
114+
</xs:complexType>
115+
<xs:complexType name="Method_CommentType">
116+
<xs:simpleContent>
117+
<xs:extension base="xs:string">
118+
<xs:attribute type="xs:string" name="line" use="optional"/>
119+
</xs:extension>
120+
</xs:simpleContent>
121+
</xs:complexType>
122+
<xs:complexType name="Method_Comment_BlockType">
123+
<xs:sequence>
124+
<xs:element type="Method_CommentType" name="Method_Comment"/>
125+
</xs:sequence>
126+
</xs:complexType>
127+
<xs:complexType name="Return_BlockType">
128+
<xs:sequence>
129+
<xs:element type="xs:string" name="Return"/>
130+
<xs:element type="xs:string" name="Return_Comment" minOccurs="0"/>
131+
</xs:sequence>
132+
</xs:complexType>
133+
<xs:complexType name="Method_BlockType">
134+
<xs:sequence>
135+
<xs:element type="MethodType" name="Method"/>
136+
<xs:element type="Method_Comment_BlockType" name="Method_Comment_Block"/>
137+
<xs:element type="Return_BlockType" name="Return_Block"/>
138+
</xs:sequence>
139+
</xs:complexType>
140+
<xs:complexType name="MethodsType">
141+
<xs:sequence>
142+
<xs:element type="Method_BlockType" name="Method_Block" maxOccurs="unbounded" minOccurs="0"/>
143+
</xs:sequence>
144+
</xs:complexType>
145+
<xs:complexType name="Class_BlockType">
146+
<xs:sequence>
147+
<xs:element type="ClassType" name="Class"/>
148+
<xs:element type="Interface_BlockType" name="Interface_Block"/>
149+
<xs:element type="Extends_BlockType" name="Extends_Block"/>
150+
<xs:element type="Class_Comment_BlockType" name="Class_Comment_Block"/>
151+
<xs:element type="ConstructorsType" name="Constructors"/>
152+
<xs:element type="MethodsType" name="Methods"/>
153+
</xs:sequence>
154+
</xs:complexType>
155+
<xs:complexType name="Package_BlockType">
156+
<xs:sequence>
157+
<xs:element type="xs:string" name="Package"/>
158+
<xs:element type="Class_BlockType" name="Class_Block"/>
159+
</xs:sequence>
160+
</xs:complexType>
161+
<xs:complexType name="ssldocletType">
162+
<xs:sequence>
163+
<xs:element type="Package_BlockType" name="Package_Block"/>
164+
</xs:sequence>
165+
<xs:attribute type="xs:string" name="creation"/>
166+
<xs:attribute type="xs:string" name="source"/>
167+
<xs:attribute type="xs:string" name="version"/>
168+
</xs:complexType>
169+
</xs:schema>

core/src/main/java/de/fraunhofer/iem/swan/model/Learner.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/model/Learner.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import de.fraunhofer.iem.swan.features.InstancesHandler;
44
import de.fraunhofer.iem.swan.io.dataset.Writer;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57
import weka.classifiers.Classifier;
68
import weka.classifiers.bayes.BayesNet;
79
import weka.classifiers.bayes.NaiveBayes;
@@ -39,10 +41,9 @@ public enum EVAL_MODE {
3941
}
4042

4143
private final int CROSS_EVALUATE_ITERATIONS = 10;
42-
private final Writer writer;
44+
private static final Logger logger = LoggerFactory.getLogger(Learner.class);
4345

4446
public Learner(Writer writer) {
45-
this.writer = writer;
4647

4748
}
4849

@@ -124,12 +125,12 @@ public void outputFMeasure(LinkedHashMap<String, HashMap<String, String>> fMeasu
124125
String value = fMeasure.keySet().toArray()[0].toString();
125126

126127
for (Object srm : fMeasure.get(value).keySet()) {
127-
System.out.println("---" + srm.toString() + "---");
128+
logger.info("Classification complete for {}", srm.toString());
128129
for (String c : fMeasure.keySet()) {
129130

130-
String measures = fMeasure.get(c).get(srm.toString()).toString();
131+
String measures = fMeasure.get(c).get(srm.toString());
131132
measures = measures.replace(".", ",").substring(0, measures.lastIndexOf(";"));
132-
System.out.println(measures);
133+
logger.info("{} classification results using {}: {}", srm, c, measures);
133134
}
134135
}
135136
}

core/src/main/java/de/fraunhofer/iem/swan/model/MLPlanExecutor.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/model/MLPlanExecutor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ public HashMap<String, String> evaluateDataset(InstancesHandler instancesHandler
101101
//optimizedClassifier.fit(split.get(0));
102102

103103

104-
String trainPath = "/Users/oshando/Projects/thesis/03-code/swan/swan_core/swan-out/mlplan/train-methods-dataset.arff";
104+
String trainPath = "swan/swan_core/swan-out/mlplan/train-methods-dataset.arff";
105105
ArffDatasetAdapter.serializeDataset(new File(trainPath), split.get(0));
106106
ArffLoader trainLoader = new ArffLoader();
107107
trainLoader.setFile(new File(trainPath));
108108
Instances trainInstances = trainLoader.getDataSet();
109109
trainInstances.setClassIndex(trainInstances.numAttributes() - 1);
110110

111111

112-
String testPath = "/Users/oshando/Projects/thesis/03-code/swan/swan_core/swan-out/mlplan/test-methods-dataset.arff";
112+
String testPath = "swan/swan_core/swan-out/mlplan/test-methods-dataset.arff";
113113
ArffDatasetAdapter.serializeDataset(new File(testPath), split.get(1));
114114
ArffLoader testLoader = new ArffLoader();
115115
testLoader.setFile(new File(testPath));
@@ -154,7 +154,7 @@ public HashMap<String, String> evaluateDataset(InstancesHandler instancesHandler
154154

155155
public void evaluateDataset(InstancesHandler instancesHandler, int k) {
156156

157-
//arffFilePath = "/Users/oshando/Projects/thesis/03-code/swan/swan_core/src/main/resources/waveform.arff";
157+
//arffFilePath = "swan/swan_core/src/main/resources/waveform.arff";
158158
String arffFilePath = Util.exportInstancesToArff(instancesHandler.getInstances());
159159

160160
String mClass = Util.getClassName(instancesHandler.getInstances());
@@ -188,7 +188,7 @@ public void evaluateDataset(InstancesHandler instancesHandler, int k) {
188188

189189
// System.out.println(attribute.getName());
190190
}
191-
ArffDatasetAdapter.serializeDataset(new File("/Users/oshando/Projects/thesis/03-code/swan/swan_core/swan-out/mlplan/methods-dataset.arff"), split.get(1));
191+
ArffDatasetAdapter.serializeDataset(new File("swan/swan_core/swan-out/mlplan/methods-dataset.arff"), split.get(1));
192192

193193

194194
for (int x = 0; x < split.get(1).size(); x++) {
@@ -261,7 +261,7 @@ public Classifier getClassifier(ILabeledDataset<?> trainingSet) {
261261

262262
public static void maihn(String[] args) {
263263

264-
String file = "/Users/oshando/Projects/thesis/03-code/swan/swan_core/src/main/resources/waveform.arff";
264+
String file = "swan/swan_core/src/main/resources/waveform.arff";
265265

266266
MLPlanExecutor mlPlan = new MLPlanExecutor();
267267
// mlPlan.evaluateDataset(file, "sdfs");

core/src/main/java/de/fraunhofer/iem/swan/model/ModelEvaluator.java renamed to swan-pipeline/src/main/java/de/fraunhofer/iem/swan/model/ModelEvaluator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.fraunhofer.iem.swan.model;
22

33

4-
import de.fraunhofer.iem.swan.Main;
4+
import de.fraunhofer.iem.swan.SwanPipeline;
55
import de.fraunhofer.iem.swan.features.InstancesHandler;
66
import de.fraunhofer.iem.swan.util.Util;
77
import weka.classifiers.Classifier;
@@ -123,7 +123,7 @@ public void evaluate(Classifier classifier, Instances trainInstances, Instances
123123

124124
eval.evaluateModel(classifier, testInstances, abstractOutput);
125125

126-
System.out.println(eval.toClassDetailsString());
126+
//System.out.println(eval.toClassDetailsString());
127127

128128
String[] predictions = abstractOutput.getBuffer().toString().split("\n");
129129

@@ -136,7 +136,7 @@ public void evaluate(Classifier classifier, Instances trainInstances, Instances
136136
|| entry[2].contains("auth")) {
137137

138138
String method = entry[5].replace("'", "");
139-
Main.predictions.get(Integer.toString(iteration)).add(method);
139+
SwanPipeline.predictions.get(Integer.toString(iteration)).add(method);
140140
}
141141
}
142142

0 commit comments

Comments
 (0)