Skip to content

Commit

Permalink
Update documentation and applying refactoring #1
Browse files Browse the repository at this point in the history
  • Loading branch information
uazadi committed Feb 28, 2018
1 parent 16a4a01 commit 5f4c91a
Show file tree
Hide file tree
Showing 228 changed files with 188,982 additions and 444 deletions.
File renamed without changes.
2 changes: 0 additions & 2 deletions WekaNose/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="jgoodies-forms-1.8.0.jar" sourcepath="jgoodies-forms-1.8.0-sources.jar"/>
<classpathentry kind="lib" path="miglayout15-swing.jar" sourcepath="miglayout-src.zip"/>
<classpathentry kind="lib" path="/home/umberto/Documents/WekaNose/lib/OUTLINE.jar"/>
<classpathentry kind="lib" path="/home/umberto/Documents/WekaNose/lib/JCodeOdor.jar"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
Binary file removed WekaNose/jgoodies-forms-1.8.0-sources.jar
Binary file not shown.
Binary file removed WekaNose/jgoodies-forms-1.8.0.jar
Binary file not shown.
Binary file removed WekaNose/miglayout-src.zip
Binary file not shown.
Binary file removed WekaNose/miglayout15-swing.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions WekaNose/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.jgoodies/jgoodies-forms -->
<dependency>
<groupId>com.jgoodies</groupId>
<artifactId>jgoodies-forms</artifactId>
<version>1.8.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.miglayout/miglayout-swing -->
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout-swing</artifactId>
<version>4.2</version>
</dependency>


</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package it.unimib.disco.essere.WekaNose.outline;
package it.unimib.disco.essere.WekaNose.MachineLearning;

import java.io.File;
import java.io.FileWriter;
import java.util.List;

import it.unimib.disco.essere.WekaNose.dfcm4j.DatasetLogger;
import it.unimib.disco.essere.load.LoaderProperties;
import it.unimib.disco.essere.WekaNose.utils.CustomLogger;
import it.unimib.disco.essere.core.InputParser;

public class MLAHandler {
Expand All @@ -17,22 +17,29 @@ public class MLAHandler {

public MLAHandler() {}

/**
* Initialize the Machine Learning Approach and load the configuration file if specified
* (https://github.com/UmbertoAzadi/OUTLINE)
* */
public MLAHandler(String pathProperties) throws Exception {
this.pathProperties = pathProperties;
LoaderProperties p = new LoaderProperties();
p.loadForClassification(pathProperties);
this.result_path = p.getPathForResult();
DatasetLogger.getInstance().info("Properties file found...", this);
CustomLogger.getInstance().info("Properties file found...", this);
}

/**
* Generate the training configuration file (https://github.com/UmbertoAzadi/OUTLINE)
* */
public void generateProperties(String datasetPath, List<String> classifiers) throws Exception {
try {
if(System.getProperty("os.name").toLowerCase().contains("win"))
path = datasetPath.substring(0, datasetPath.lastIndexOf('\\')).replace("\\", "/");
else
path = datasetPath.substring(0, datasetPath.lastIndexOf('/'));
this.pathProperties = path + "/dataset.properties";
DatasetLogger.getInstance().info("Creating properties file...", this);
CustomLogger.getInstance().info("Creating properties file...", this);
File file = new File(this.pathProperties);
FileWriter writer = new FileWriter(file, false);
writer.write("dataset = " + datasetPath.replace("\\", "/") + "\n");
Expand All @@ -47,16 +54,23 @@ public void generateProperties(String datasetPath, List<String> classifiers) thr
}

writer.close();
DatasetLogger.getInstance().info("Properties file created...", this);
CustomLogger.getInstance().info("Properties file created...", this);
}catch(Exception e) {
throw e;
}
}

/**
* This method preform a WEKA Experiment (https://weka.wikispaces.com/Using+the+Experiment+API) in order
* to provide a ranking of the Machine Learning Algorithms.
* It also save the human-readable results (when they are provided by the algorithms)
* and serialize the algorithms if the boolean variable "serialize" is true.
*
* */
public void runExperiment(String exptype, String splittype, int run, int fold, boolean serialize) throws Exception {


DatasetLogger.getInstance().info("Start the experiment...", this);
CustomLogger.getInstance().info("Start the experiment...", this);
String input = "-save -wekaExp "
+ "-exptype " + exptype
+ " -splittype " + splittype
Expand All @@ -70,7 +84,7 @@ public void runExperiment(String exptype, String splittype, int run, int fold, b
outline.start(new String[] {"-save", pathProperties});
if(serialize)
outline.start(new String[] {"-ser", pathProperties});
DatasetLogger.getInstance().info("Experiment terminated, the results were saved in: " + this.result_path, this);
CustomLogger.getInstance().info("Experiment terminated, the results were saved in: " + this.result_path, this);
} catch (Exception e) {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package it.unimib.disco.essere.WekaNose.dataset.creation;

import java.util.Arrays;

import it.unimib.disco.essere.WekaNose.exceptions.NotValidConditionException;

/**
* This class model an Advisor, i.e. a deterministic rule that gives
* a classification of a code element, telling if it is a code smell or not.
*
* The regular expression that describe an Advisor is: [METRIC]{1}_[VALID_LEVEL]{1}[VALID_SYMBOL]{1}[0-9]+
* For the metrics list see DatasetRow.java
*
* */
public class Advisor {

/** The symbol that can be use to specify the rule */
public static String[] VALID_SYMBOL = {"<", "<=", ">", ">=", "!=", "==", "between"};

/** The levels of the metrics that can be used to specify the rule */
public static String[] VALID_LEVEL = {"method", "class"};

/** The metric that is used to express the rule*/
private String metric;

/** The level of the metric that is used to express the rule*/
private String level;

/** The metric that is used to express the rule*/
private String symbol;

/** The threshold of the rule*/
private int threshold1;

/** The second threshold of the rule, that can be specified only if the symbol is "between" */
private int threshold2;

/**
* Check if all the required information needed to create an Advisor are consistent.
* This constructor allow to create a "between rules" by specifying the second threshold.
*
* @throws NotValidConditionException in case some of the information aren't valid.
*/
public Advisor(String metric, String level, String symbol, int threshold1, int threshold2) throws NotValidConditionException{

if(Arrays.asList(DatasetRow.METHOD_METRICS).contains(metric)
|| Arrays.asList(DatasetRow.CLASS_METRICS).contains(metric))
this.metric = metric;
else
throw new NotValidConditionException("the metric " + metric + " is not valid");

if(Arrays.asList(Advisor.VALID_LEVEL).contains(level))
this.level = level;
else
throw new NotValidConditionException("the level " + level + " is not valid");

if(Arrays.asList(Advisor.VALID_SYMBOL).contains(symbol))
this.symbol = (symbol.equals("!=")) ? "<>" : symbol;
else
throw new NotValidConditionException("the symbol " + symbol + " is not valid");

try {
this.threshold1 = threshold1;
this.threshold2 = (this.symbol.equals("between")) ? threshold2 : 0;
} catch(NumberFormatException e) {
throw new NotValidConditionException("one (or both) of the thresholdbers are not valid");
}
}

/**
* Check if all the required information needed to create an Advisor are consistent.
* This constructor allow to create all the rule except the one that involve the symbol "between".
*
* @throws NotValidConditionException in case some of the information aren't valid.
*/
public Advisor(String metric, String level, String symbol, int threshold1) throws NotValidConditionException{
this(metric, level, symbol, threshold1, 0);
}

public void setMetric(String metric) throws NotValidConditionException {
if(Arrays.asList(DatasetRow.METHOD_METRICS).contains(metric)
|| Arrays.asList(DatasetRow.CLASS_METRICS).contains(metric))
this.metric = metric;
else
throw new NotValidConditionException("the metric " + metric + " is not valid");
}

public void setLevel(String level) throws NotValidConditionException {
if(Arrays.asList(Advisor.VALID_LEVEL).contains(level))
this.level = level;
else
throw new NotValidConditionException("the level " + level + " is not valid");
}

public void setSymbol(String symbol) throws NotValidConditionException {
if(Arrays.asList(Advisor.VALID_SYMBOL).contains(symbol))
this.symbol = symbol;
else
throw new NotValidConditionException("the symbol " + symbol + " is not valid");
}

public void setThreshold1(int threshold1) {
this.threshold1 = threshold1;
}

public void setThreshold2(int threshold2) {
this.threshold2 = threshold2;
}

public String getMetric() {
return metric;
}

public String getLevel() {
return level;
}

public String getSymbol() {
return symbol;
}

public int getThreshold1() {
return threshold1;
}

public int getThreshold2() {
return threshold2;
}


/**
* Return Returns a String object representing the Advisor.
* For example: NOP == 5 become NOP_method_equal_5
* */
public String toString() {
String string = this.metric + "_" + this.level;

string = (symbol.equals("<")) ? string + "_less_" + threshold1 : string;
string = (symbol.equals("<=")) ? string + "_less_eq_" + threshold1 : string;
string = (symbol.equals(">")) ? string + "_greater_" + threshold1 : string;
string = (symbol.equals(">=")) ? string + "_greater_eq_" + threshold1 : string;
string = (symbol.equals("!=")) ? string + "_not_eq_" + threshold1 : string;
string = (symbol.equals("==")) ? string + "_equal_" + threshold1 : string;
string = (symbol.equals("between")) ? string + "_between_"+ threshold1 +"_"+ threshold2 : string;

return string;
}
}

0 comments on commit 5f4c91a

Please sign in to comment.