Commit 6c8d7d6f authored by Bruno López Trigo's avatar Bruno López Trigo

Finalizada versión beta de interface gráfica para datasets de exemplo

parent e62d5ba7
package brunolopez.expliclas.explainer;
import brunolopez.expliclas.exceptions.NotFoundEx;
import brunolopez.expliclas.models.Explanation;
import java.io.IOException;
public interface ExplainerManager {
Explanation getGlobalExplanation(String token, String dataset, String algorithm, String language) throws IOException;
Explanation getGlobalExplanation(String token, String dataset, String algorithm, String language) throws IOException, NotFoundEx;
}
package brunolopez.expliclas.explainer;
import brunolopez.expliclas.exceptions.NotFoundEx;
import brunolopez.expliclas.json.MapperJSON;
import brunolopez.expliclas.models.Explanation;
import brunolopez.expliclas.models.GlobalConfig;
......@@ -24,20 +25,23 @@ public class ExplainerManagerImpl implements ExplainerManager {
}
@Override
public Explanation getGlobalExplanation(String token, String dataset, String algorithm, String language) throws IOException {
public Explanation getGlobalExplanation(String token, String dataset, String algorithm, String language) throws IOException, NotFoundEx {
File config, global, log;
switch (language) {
case "en":
this.generator = new ClauseGeneratorEn();
if (token.isEmpty()) {
config = new File(this.BASE + dataset + "/" + dataset + ".json");
log = new File(this.BASE + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
} else {
config = new File(this.BASE + dataset + "/" + dataset + ".json");
log = new File(this.BASE + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
if(!config.exists()){
config = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + dataset + ".json");
log = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
}
if(!config.exists() || !log.exists()){
throw new NotFoundEx("Classifier not found");
}
global = new File(this.BASE + "global/config.json");
this.extractor = new InfoExtractor(this.mapper.readConfigJSON(config), log);
......@@ -46,14 +50,19 @@ public class ExplainerManagerImpl implements ExplainerManager {
break;
case "es":
this.generator = new ClauseGeneratorEs();
if (token.isEmpty()) {
config = new File(this.BASE + dataset + "/" + dataset + "-" + language + ".json");
log = new File(this.BASE + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
} else {
config = new File(this.BASE + dataset + "/" + dataset + "-" + language + ".json");
log = new File(this.BASE + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
if(!config.exists()){
config = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + dataset + "-" + language + ".json");
log = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
}
if(!config.exists() || !log.exists()){
throw new NotFoundEx("Classifier not found");
}
global = new File(this.BASE + "global/config-" + language + ".json");
this.extractor = new InfoExtractor(this.mapper.readConfigJSON(config), log);
......@@ -62,13 +71,18 @@ public class ExplainerManagerImpl implements ExplainerManager {
break;
case "gl":
this.generator = new ClauseGeneratorGl();
if (token.isEmpty()) {
config = new File(this.BASE + dataset + "/" + dataset + "-" + language + ".json");
log = new File(this.BASE + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
} else {
config = new File(this.BASE + dataset + "/" + dataset + "-" + language + ".json");
log = new File(this.BASE + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
if(!config.exists()){
config = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + dataset + "-" + language + ".json");
log = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + algorithm + "/" + dataset + ".arff." + algorithm + ".log.txt");
}
if(!config.exists() || !log.exists()){
throw new NotFoundEx("Classifier not found");
}
global = new File(this.BASE + "global/config-" + language + ".json");
......@@ -92,6 +106,7 @@ public class ExplainerManagerImpl implements ExplainerManager {
String dataset = this.extractor.getDatasetName();
ArrayList<String> conseqNames = this.extractor.getConsequentNames();
double globalPercentage = this.extractor.getGlobalPercentage();
explanation.setPrecision(globalPercentage);
double percentageConfused = this.extractor.getConfusedConseqPercentage();
int cycleSize = this.extractor.getCycleSize();
ArrayList<String> confusedConsequents = new ArrayList();
......
......@@ -3,6 +3,8 @@ package brunolopez.expliclas.models;
import java.util.ArrayList;
public class Explanation {
private Double precision;
private ArrayList<String> clauses;
public Explanation() {
......@@ -16,5 +18,13 @@ public class Explanation {
public void addClause(String clause){
this.clauses.add(clause);
}
public Double getPrecision() {
return precision;
}
public void setPrecision(Double precision) {
this.precision = precision;
}
}
package brunolopez.expliclas.services;
import brunolopez.expliclas.exceptions.NotFoundEx;
import brunolopez.expliclas.explainer.ExplainerManager;
import brunolopez.expliclas.explainer.ExplainerManagerImpl;
import brunolopez.expliclas.models.DatasetConfig;
......@@ -71,6 +72,8 @@ public class ExplainerService {
return Response.status(Response.Status.OK).entity(explanation).build();
} catch (IOException ex) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new SimpleMessage("Error reading config")).build();
} catch (NotFoundEx ex) {
return Response.status(Response.Status.NOT_FOUND).entity(new SimpleMessage(ex.getMessage())).build();
}
......
......@@ -4,30 +4,42 @@
"type": "numericAtt",
"id": "Strength",
"name": "Strength",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "Low",
"name": "session",
"interval": {
"left": 0.039,
"right": 0.07133333333333333
"left": 0.035,
"right": 0.0525
}
}, {
},
{
"type": "numericProp",
"name": "standard",
"interval": {
"left": 0.0525,
"right": 0.0675
}
},
{
"type": "numericProp",
"name": "Medium",
"name": "high",
"interval": {
"left": 0.07133333333333333,
"right": 0.10366666666666666
"left": 0.0675,
"right": 0.09
}
}, {
},
{
"type": "numericProp",
"name": "High",
"name": "very high",
"interval": {
"left": 0.10366666666666666,
"left": 0.09,
"right": 0.136
}
}],
}
],
"interval": {
"left": 0.039,
"left": 0.035,
"right": 0.136
},
"value": 0.0
......@@ -40,28 +52,48 @@
"type": "numericAtt",
"id": "Color",
"name": "Color",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "Low",
"name": "pale",
"interval": {
"left": 0.0,
"right": 15.0
"left": 0,
"right": 3
}
}, {
},
{
"type": "numericProp",
"name": "Medium",
"name": "straw",
"interval": {
"left": 15.0,
"right": 30.0
"left": 3,
"right": 7.5
}
}, {
},
{
"type": "numericProp",
"name": "High",
"name": "amber",
"interval": {
"left": 30.0,
"right": 45.0
"left": 7.5,
"right": 19
}
},
{
"type": "numericProp",
"name": "brown",
"interval": {
"left": 19,
"right": 29
}
}],
},
{
"type": "numericProp",
"name": "black",
"interval": {
"left": 29,
"right": 45
}
}
],
"interval": {
"left": 0.0,
"right": 45.0
......@@ -76,30 +108,42 @@
"type": "numericAtt",
"id": "Bitterness",
"name": "Bitterness",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "Low",
"name": "low",
"interval": {
"left": 8.0,
"right": 88.66666666666667
"left": 7,
"right": 21
}
}, {
},
{
"type": "numericProp",
"name": "Medium",
"name": "low-medium",
"interval": {
"left": 88.66666666666667,
"right": 169.33333333333334
"left": 21,
"right": 32.5
}
}, {
},
{
"type": "numericProp",
"name": "High",
"name": "medium-high",
"interval": {
"left": 169.33333333333334,
"right": 250.0
"left": 32.5,
"right": 47.5
}
}],
},
{
"type": "numericProp",
"name": "high",
"interval": {
"left": 47.5,
"right": 250
}
}
],
"interval": {
"left": 8.0,
"left": 7.0,
"right": 250.0
},
"value": 0.0
......@@ -131,28 +175,48 @@
"type": "numericAtt",
"id": "Color",
"name": "Color",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "Low",
"name": "pale",
"interval": {
"left": 0.0,
"right": 15.0
"left": 0,
"right": 3
}
}, {
},
{
"type": "numericProp",
"name": "Medium",
"name": "straw",
"interval": {
"left": 15.0,
"right": 30.0
"left": 3,
"right": 7.5
}
}, {
},
{
"type": "numericProp",
"name": "High",
"name": "amber",
"interval": {
"left": 30.0,
"right": 45.0
"left": 7.5,
"right": 19
}
}],
},
{
"type": "numericProp",
"name": "brown",
"interval": {
"left": 19,
"right": 29
}
},
{
"type": "numericProp",
"name": "black",
"interval": {
"left": 29,
"right": 45
}
}
],
"interval": {
"left": 0.0,
"right": 45.0
......@@ -167,28 +231,48 @@
"type": "numericAtt",
"id": "Color",
"name": "Color",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "Low",
"name": "pale",
"interval": {
"left": 0.0,
"right": 15.0
"left": 0,
"right": 3
}
}, {
},
{
"type": "numericProp",
"name": "Medium",
"name": "straw",
"interval": {
"left": 15.0,
"right": 30.0
"left": 3,
"right": 7.5
}
}, {
},
{
"type": "numericProp",
"name": "High",
"name": "amber",
"interval": {
"left": 30.0,
"right": 45.0
"left": 7.5,
"right": 19
}
}],
},
{
"type": "numericProp",
"name": "brown",
"interval": {
"left": 19,
"right": 29
}
},
{
"type": "numericProp",
"name": "black",
"interval": {
"left": 29,
"right": 45
}
}
],
"interval": {
"left": 0.0,
"right": 45.0
......@@ -233,30 +317,42 @@
"type": "numericAtt",
"id": "Bitterness",
"name": "Bitterness",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "Low",
"name": "low",
"interval": {
"left": 8.0,
"right": 88.66666666666667
"left": 7,
"right": 21
}
}, {
},
{
"type": "numericProp",
"name": "Medium",
"name": "low-medium",
"interval": {
"left": 88.66666666666667,
"right": 169.33333333333334
"left": 21,
"right": 32.5
}
}, {
},
{
"type": "numericProp",
"name": "High",
"name": "medium-high",
"interval": {
"left": 169.33333333333334,
"right": 250.0
"left": 32.5,
"right": 47.5
}
}],
},
{
"type": "numericProp",
"name": "high",
"interval": {
"left": 47.5,
"right": 250
}
}
],
"interval": {
"left": 8.0,
"left": 7.0,
"right": 250.0
},
"value": 0.0
......@@ -278,30 +374,42 @@
"type": "numericAtt",
"id": "Strength",
"name": "Strength",
"properties": [{
"properties": [
{
"type": "numericProp",
"name": "Low",
"name": "session",
"interval": {
"left": 0.039,
"right": 0.07133333333333333
"left": 0.035,
"right": 0.0525
}
}, {
},
{
"type": "numericProp",
"name": "Medium",
"name": "standard",
"interval": {
"left": 0.07133333333333333,
"right": 0.10366666666666666
"left": 0.0525,
"right": 0.0675
}
}, {
},
{
"type": "numericProp",
"name": "High",
"name": "high",
"interval": {
"left": 0.10366666666666666,
"left": 0.0675,
"right": 0.09
}
},
{
"type": "numericProp",
"name": "very high",
"interval": {
"left": 0.09,
"right": 0.136
}
}],
}
],
"interval": {
"left": 0.039,
"left": 0.035,
"right": 0.136
},
"value": 0.0
......