Skip to content

Commit 1f2019e

Browse files
committed
Add new and update existing command options
1 parent eb7b02a commit 1f2019e

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/cli/CliRunner.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class CliRunner implements Callable<Integer> {
2525
@CommandLine.Option(names = {"-f", "--feature"}, description = {"Select one or more feature sets: all, code, doc-auto or doc-manual"})
2626
private List<String> featureSet = Collections.singletonList("code");
2727

28-
@CommandLine.Option(names = {"-l", "--learning"}, description = {"Learning modes: manual, auto"})
29-
private String learningMode = "manual";
28+
@CommandLine.Option(names = {"-l", "--learning"}, description = {"Learning modes: meka, weka, ml-plan"})
29+
private String learningMode = "meka";
3030

3131
@CommandLine.Option(names = {"-s", "--srm"}, description = {"SRM: all, source, sink, sanitizer, authentication, relevant"})
3232
private List<String> srmClasses = Collections.singletonList("all");
@@ -46,6 +46,13 @@ public class CliRunner implements Callable<Integer> {
4646
@CommandLine.Option(names = {"-sp", "--training-split"}, description = {"Percentage for training"})
4747
private double split = 0.7;
4848

49+
@CommandLine.Option(names = {"-p", "--phase"}, description = {"Phase: validate, predict"})
50+
private String phase = "predict";
51+
52+
@CommandLine.Option(names = {"-pt", "--prediction-threshold"}, description = {"Threshold for predicting categories"})
53+
private double predictionThreshold = 0.5;
54+
55+
4956
@Override
5057
public Integer call() throws Exception {
5158

@@ -60,7 +67,9 @@ public Integer call() throws Exception {
6067
exportArffData,
6168
isDocumented,
6269
iterations,
63-
split);
70+
split,
71+
phase);
72+
options.setPredictionThreshold(predictionThreshold);
6473

6574
return new SwanCli().run(options);
6675
}

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/cli/SwanCli.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Integer run(SwanOptions options) throws Exception {
3131
}
3232

3333
if(options.getSrmClasses().contains("all")){
34-
options.setSrmClasses(Arrays.asList("source", "sink", "sanitizer", "authentication", "relevant"));
34+
options.setSrmClasses(Arrays.asList("source", "sink", "sanitizer", "authentication"));
3535
}
3636

3737
if(options.getCweClasses().contains("all")){

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/cli/SwanOptions.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ public class SwanOptions {
2222
private boolean isDocumented;
2323
private int iterations;
2424
private double trainTestSplit;
25+
private String phase;
26+
private double predictionThreshold;
27+
28+
public SwanOptions(String testDataDir, String trainDataDir, String datasetJson, String outputDir,
29+
List<String> featureSet, String learningMode, List<String> srmClasses,
30+
List<String> cweClasses, boolean exportArffData, boolean isDocumented,
31+
int iterations, double trainTestSplit, String phase) {
32+
this.testDataDir = testDataDir;
33+
this.trainDataDir = trainDataDir;
34+
this.datasetJson = datasetJson;
35+
this.outputDir = outputDir;
36+
this.featureSet = featureSet;
37+
this.learningMode = learningMode;
38+
this.srmClasses = srmClasses;
39+
this.cweClasses = cweClasses;
40+
this.exportArffData = exportArffData;
41+
this.isDocumented = isDocumented;
42+
this.iterations = iterations;
43+
this.trainTestSplit = trainTestSplit;
44+
this.phase = phase;
45+
}
2546

2647
public SwanOptions(String testDataDir, String trainDataDir, String datasetJson, String outputDir,
2748
List<String> featureSet, String learningMode, List<String> srmClasses, List<String> cweClasses,
@@ -140,6 +161,22 @@ public void setTrainTestSplit(double trainTestSplit) {
140161
this.trainTestSplit = trainTestSplit;
141162
}
142163

164+
public String getPhase() {
165+
return phase;
166+
}
167+
168+
public void setPhase(String phase) {
169+
this.phase = phase;
170+
}
171+
172+
public double getPredictionThreshold() {
173+
return predictionThreshold;
174+
}
175+
176+
public void setPredictionThreshold(double predictionThreshold) {
177+
this.predictionThreshold = predictionThreshold;
178+
}
179+
143180
@Override
144181
public String toString() {
145182
return "SwanOptions{" +

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,21 @@
3131
public class ModelEvaluator {
3232

3333
public enum Mode {
34-
MANUAL,
35-
AUTOMATIC
34+
WEKA,
35+
MEKA,
36+
MLPLAN
37+
}
38+
39+
public enum Phase {
40+
VALIDATE,
41+
PREDICT
3642
}
3743

3844
private FeaturesHandler features;
3945
private SwanOptions options;
4046
private static final Logger logger = LoggerFactory.getLogger(ModelEvaluator.class);
4147

42-
public ModelEvaluator(FeaturesHandler features, SwanOptions options) {
48+
public ModelEvaluator(FeaturesHandler features, SwanOptions options, Set<Method> methods) {
4349
this.features = features;
4450
this.options = options;
4551
}
@@ -49,8 +55,7 @@ public ModelEvaluator(FeaturesHandler features, SwanOptions options) {
4955
*
5056
* @return Hashmap containing the name of the classifier and it's F-Measure
5157
*/
52-
public HashMap<String, HashMap<String, String>> trainModel() {
53-
58+
public void trainModel() {
5459

5560
switch (Mode.valueOf(options.getLearningMode().toUpperCase())) {
5661

0 commit comments

Comments
 (0)