Skip to content

Commit 5f0795a

Browse files
committed
Move export SRM list implementation
1 parent 94c7c1a commit 5f0795a

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/SwanPipeline.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import de.fraunhofer.iem.swan.io.dataset.SrmList;
88
import de.fraunhofer.iem.swan.io.dataset.SrmListUtils;
99
import de.fraunhofer.iem.swan.model.ModelEvaluator;
10+
import de.fraunhofer.iem.swan.model.engine.Meka;
1011
import de.fraunhofer.iem.swan.util.Util;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
@@ -55,12 +56,6 @@ public void run() throws IOException, InterruptedException {
5556
ModelEvaluator modelEvaluator = new ModelEvaluator(featuresHandler, options, testDataset.getMethods());
5657
modelEvaluator.trainModel();
5758

58-
//TODO export final list to JSON file
59-
String outputFile = options.getOutputDir() + File.separator + "swan-srm-cwe-list.json";
60-
ObjectMapper objectMapper = new ObjectMapper();
61-
objectMapper.writeValue(new File(outputFile), dataset);
62-
logger.info("SRM/CWE list exported to {}", outputFile);
63-
6459
long analysisTime = System.currentTimeMillis() - startAnalysisTime;
6560
logger.info("Total runtime {} minutes", analysisTime / 60000);
6661
}

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/data/Method.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ public Set<Category> getAllCategories() {
177177
return new HashSet<>();
178178
}
179179

180-
public void addCategoryClassified(Category category) {
181-
this.cwe.add(category);
180+
public void addCategory(Category category) {
181+
if (category.isCwe())
182+
cwe.add(category);
183+
else srm.add(category);
182184
}
183185

184186
// Inherited from SootMethodAndClass (from Soot Infoflow)

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/io/dataset/SrmList.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonIgnore;
44
import de.fraunhofer.iem.swan.data.Method;
55
import java.util.Set;
6+
import java.util.stream.Collectors;
67

78
/**
89
* Represents SRM JSON file.
@@ -35,4 +36,10 @@ public Set<Method> getMethods() {
3536
public void setMethods(Set<Method> methods) {
3637
this.methods = methods;
3738
}
39+
40+
public void removeUnclassifiedMethods() {
41+
42+
methods = methods.stream().filter(m -> m.getAllCategories().size() > 0)
43+
.collect(Collectors.toSet());
44+
}
3845
}

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/io/dataset/SrmListUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ public Type appliesInternal(Method method) {
9393
*/
9494
public static void exportFile(SrmList srmList, String file) throws IOException {
9595

96+
srmList.removeUnclassifiedMethods();
9697
ObjectMapper objectMapper = new ObjectMapper();
9798
objectMapper.writeValue(new File(file), srmList);
98-
logger.info("Collected {} methods from the training set.", srmList.getMethods().size());
99+
logger.info("{} methods exported to {}", srmList.getMethods().size(), file);
99100
}
100101

101102
public static void removeUndocumentedMethods(SrmList list) {

0 commit comments

Comments
 (0)