Commit 0e5f5ae2 authored by Bruno López Trigo's avatar Bruno López Trigo

Engadida versión coa nova xeración de explicacións, explicación do caso e...

Engadida versión coa nova xeración de explicacións, explicación do caso e explicación do clasificador
parent 874ee8f1
#Tue, 20 Mar 2018 17:42:04 +0100
#Fri, 23 Mar 2018 14:36:11 +0100
C\:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2=
/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2=
application.args="C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\properties.xsd" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\glass.xml" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\entry.xsd" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\config.xsd" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\config.xml" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\logGlass.xml" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\glassinput.xml" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\glass.txt" "C:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2\\resources\\explanationGlass.html"
application.args="/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/properties.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/beer.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/entry.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/config.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/config.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/log.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/inputexample.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/ALL-infer.txt" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/explanation.html"
compile.on.save=true
do.depend=false
do.jar=true
javac.debug=true
javadoc.preview=true
user.properties.file=C:\\Users\\brilemau\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
user.properties.file=/home/brilemau/.netbeans/8.2/build.properties
......@@ -3,15 +3,12 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/rulesystem/RuleBuilder.java</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/languagerealiser/LanguageRealiser.java</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/rulesystem/Consequent.java</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/Problem.java</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/ReaderWeka.java</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/wekaparser/v2/Controller.java</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/properties.xsd</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/LeafNode.java</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/beer.xml</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/Problem.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/LeafNode.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/languagerealiser/LanguageRealiser.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/rulesystem/Consequent.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/rulesystem/RuleBuilder.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/ReaderWeka.java</file>
</group>
</open-files>
</project-private>
......@@ -2,62 +2,87 @@
<config>
<propertiesAlt>
<property>
<valueTxt>Very likely</valueTxt>
<valueTxt>unlikely</valueTxt>
<interval>
<leftValue>90</leftValue>
<rightValue>100</rightValue>
<leftValue>0</leftValue>
<rightValue>25</rightValue>
</interval>
</property>
<property>
<valueTxt>Quite likely</valueTxt>
<valueTxt>quite likely</valueTxt>
<interval>
<leftValue>50</leftValue>
<rightValue>90</rightValue>
<leftValue>25</leftValue>
<rightValue>75</rightValue>
</interval>
</property>
<property>
<valueTxt>Likely</valueTxt>
<valueTxt>just as likely</valueTxt>
<interval>
<leftValue>10</leftValue>
<rightValue>50</rightValue>
<leftValue>75</leftValue>
<rightValue>100</rightValue>
</interval>
</property>
</propertiesAlt>
<propertiesTree>
<property>
<valueTxt>Unlikely</valueTxt>
<valueTxt>an exception</valueTxt>
<interval>
<leftValue>0</leftValue>
<rightValue>10</rightValue>
</interval>
</property>
</propertiesAlt>
<propertiesOri>
<property>
<valueTxt>Almost always</valueTxt>
<valueTxt>likely</valueTxt>
<interval>
<leftValue>80</leftValue>
<leftValue>10</leftValue>
<rightValue>30</rightValue>
</interval>
</property>
<property>
<valueTxt>very likely</valueTxt>
<interval>
<leftValue>30</leftValue>
<rightValue>100</rightValue>
</interval>
</property>
</propertiesTree>
<propertiesGlob>
<property>
<valueTxt>very confusing</valueTxt>
<interval>
<leftValue>0</leftValue>
<rightValue>30</rightValue>
</interval>
</property>
<property>
<valueTxt>quite confusing</valueTxt>
<interval>
<leftValue>30</leftValue>
<rightValue>89</rightValue>
</interval>
</property>
<property>
<valueTxt>Many times</valueTxt>
<valueTxt>very reliable</valueTxt>
<interval>
<leftValue>50</leftValue>
<rightValue>80</rightValue>
<leftValue>89</leftValue>
<rightValue>100</rightValue>
</interval>
</property>
</propertiesGlob>
<propertiesGlobConf>
<property>
<valueTxt>Eventually</valueTxt>
<valueTxt>eventually</valueTxt>
<interval>
<leftValue>10</leftValue>
<rightValue>50</rightValue>
<rightValue>30</rightValue>
</interval>
</property>
<property>
<valueTxt>Rarely</valueTxt>
<valueTxt>very</valueTxt>
<interval>
<leftValue>0</leftValue>
<rightValue>10</rightValue>
<leftValue>30</leftValue>
<rightValue>100</rightValue>
</interval>
</property>
</propertiesOri>
</propertiesGlobConf>
</config>
......@@ -25,7 +25,49 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="propertiesOri">
<xs:element name="propertiesTree">
<xs:complexType>
<xs:sequence>
<xs:element name="property" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="valueTxt"/>
<xs:element name="interval">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="leftValue"/>
<xs:element type="xs:float" name="rightValue"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="propertiesGlob">
<xs:complexType>
<xs:sequence>
<xs:element name="property" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="valueTxt"/>
<xs:element name="interval">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="leftValue"/>
<xs:element type="xs:float" name="rightValue"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="propertiesGlobConf">
<xs:complexType>
<xs:sequence>
<xs:element name="property" maxOccurs="unbounded" minOccurs="1">
......
"/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/properties.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/beer.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/entry.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/config.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/config.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/log.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/inputexample.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/ALL-infer.txt" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/explanation.html"
#!/bin/bash
properties_xsd="properties.xsd"
properties_xml="beer.xml"
entry_xsd="entry.xsd"
config_xsd="config.xsd"
config="config.xml"
log="log.xml"
input="inputexample.xml"
weka="ALL-infer.txt"
html="explanation.html"
type=beer
index=1
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $input
echo "<problem>" >> $input
echo " <type>$type</type>" >> $input
echo " <attributes>" >> $input
for var in $@
do
if [ $index -eq 1 ]
then
echo " <attribute name=\"$var\">" >> $input
index=0
else
echo " <value>$var</value>" >> $input
echo " </attribute>" >> $input
index=1
fi
done
echo " </attributes>" >> $input
echo "</problem>" >> $input
java -jar ../dist/WekaParser-v2.jar $properties_xsd $properties_xml $entry_xsd $config_xsd $config $log $input $weka $html
firefox $html
<h1>Explanation</h1><p>Beer is type Stout because system detected that its strength is session or standard and that its color is black.</p><p>It is almost always (98.0 %) type Stout however it can be of the following types.</p><ul><li>it is just as likely to be type Stout as type Porter considering its color slightly lower</li></ul><p>This beer could be confused with following types.</p><ul><li>it is unlikely (2.0 %) to be type Belgian Strong Ale</li></ul>
\ No newline at end of file
<h1>AutoExplainable Classifier</h1><h2>Global information</h2><p>There are 8 types of beer: Blanche, Lager, Pilsner, IPA, Stout, Barleywine, Porter and Belgian Strong Ale. Types Blanche, Lager, Pilsner, Stout, Porter and Belgian Strong Ale are very reliable. Types IPA and Barleywine are quite confusing.</p><p>Type Barleywine is eventually confused with type IPA.</p><h2>Explanation</h2><p>Beer is type Barleywine because system detected that its strength is very high, that its bitterness is high and that its color is amber.</p><p>This class can be confused with type IPA if its strength is sligthly lower.</p><p>It is just as likely to be type IPA.</p><p>Considering global information IPA would be likely</p>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<problem>
<type>beer</type>
<attributes>
<attribute name="Color">
<value>30</value>
</attribute>
<attribute name="Bitterness">
<value>29</value>
</attribute>
<attribute name="Strength">
<value>0.046</value>
</attribute>
</attributes>
</problem>
<?xml version="1.0" encoding="UTF-8"?>
<problem>
<type>beer</type>
<attributes>
<attribute name="Color">
<value>11</value>
</attribute>
<attribute name="Bitterness">
<value>93</value>
</attribute>
<attribute name="Strength">
<value>0.095</value>
</attribute>
</attributes>
</problem>
This diff is collapsed.
......@@ -17,44 +17,66 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "config")
public class Config {
@XmlElementWrapper(name="propertiesOri")
@XmlElementWrapper(name="propertiesTree")
@XmlElement(name = "property")
private final ArrayList<Property> propertiesOri;
private final ArrayList<Property> propertiesTree;
@XmlElementWrapper(name="propertiesAlt")
@XmlElement(name = "property")
private final ArrayList<Property> propertiesAlt;
@XmlElementWrapper(name="propertiesGlob")
@XmlElement(name = "property")
private final ArrayList<Property> propertiesGlob;
@XmlElementWrapper(name="propertiesGlobConf")
@XmlElement(name = "property")
private final ArrayList<Property> propertiesGlobConf;
/**
* Constructor vacío para xerar xml
*/
public Config() {
this.propertiesOri = null;
this.propertiesTree = null;
this.propertiesAlt = null;
this.propertiesGlob = null;
this.propertiesGlobConf = null;
}
/**
* Getter de propiedades das regras alternativas
* @return lista de propiedades alternativas
* Getter dunha propiedade para regra alternativa respecto ao global
* segundo un valor numérico
* @param value valor numérico
* @return propiedade, no caso de entrar o valor no intervalo ou null
*/
public ArrayList<Property> getPropertiesAlt() {
return propertiesAlt;
public Property getPropertyTree(Float value){
for(Property p: this.propertiesTree){
if(p.getInterval().isValueInside(value))
return p;
}
return null;
}
/**
* Getter de propiedades das regras orixinais
* @return lista de propiedades orixinais
* Getter dunha propiedade para regra alternativa segundo un valor numérico
* @param value valor numérico
* @return propiedade, no caso de entrar o valor no intervalo ou null
*/
public ArrayList<Property> getPropertiesOri() {
return propertiesOri;
public Property getPropertyAlt(Float value){
for(Property p: this.propertiesAlt){
if(p.getInterval().isValueInside(value))
return p;
}
return null;
}
/**
* Getter dunha propiedade para regra orixinal segundo un valor numérico
* Getter dunha propiedade para a matriz de confusión a nivel global
* segundo un valor numérico
* @param value valor numérico
* @return propiedade, no caso de entrar o valor no intervalo ou null
*/
public Property getPropertyOri(Float value){
for(Property p: this.propertiesOri){
public Property getPropertyGlob(Float value){
for(Property p: this.propertiesGlob){
if(p.getInterval().isValueInside(value))
return p;
}
......@@ -63,12 +85,13 @@ public class Config {
}
/**
* Getter dunha propiedade para regra alternativa segundo un valor numérico
* Getter dunha propiedade para a matriz de confusión a nivel de erros entre
* clases
* @param value valor numérico
* @return propiedade, no caso de entrar o valor no intervalo ou null
*/
public Property getPropertyAlt(Float value){
for(Property p: this.propertiesAlt){
public Property getPropertyGlobConf(Float value){
for(Property p: this.propertiesGlobConf){
if(p.getInterval().isValueInside(value))
return p;
}
......
......@@ -36,4 +36,45 @@ public class ConfusionMatrix {
return this.matrix.get(row);
}
/**
* Getter dun elemento concreto dado os índices de fila e columna
* @param row indice da fila
* @param column indice da columna
* @return elemento
*/
public Integer getElement(int row, int column){
return this.matrix.get(row).get(column);
}
/**
* Getter de la fiabilidad de la clase
* @param row índice de la clase
* @return porcentaje de fiabilidad
*/
public float classReliability(int row){
float sum = 0;
for(Integer i: getRow(row)){
sum += i;
}
return getElement(row, row) / sum * 100;
}
/**
* Getter de la confusión entre dos clases
* @param row índice de la primera clase
* @param column indice de la segunda clase
* @return porcentaje de confusión
*/
public float classConfusion(int row, int column){
float sum = 0;
for(Integer i: getRow(row)){
sum += i;
}
return getElement(row, column) / sum * 100;
}
}
......@@ -3,6 +3,7 @@ package iosystem;
import java.io.FileNotFoundException;
import javax.xml.bind.JAXBException;
import org.xml.sax.SAXException;
import rulesystem.Consequent;
import rulesystem.Solution;
/**
......@@ -32,8 +33,23 @@ public class IOImpl implements IOInterface{
* @throws JAXBException en caso de existir algún erro ao ler os xml
*/
@Override
public Problem readProblem() throws SAXException, JAXBException {
return this.xmlparser.extractProblem();
public Problem readProblem() throws SAXException, JAXBException, FileNotFoundException {
ConfusionMatrix matrix = readMatrix();
Problem p = this.xmlparser.extractProblem();
for(Consequent c: p.getConsequents()){
c.setPercentage_global(matrix.classReliability((int) c.getCode() - 1));
for(int i=0; i<p.getConsequents().size(); i++){
if(i!=(c.getCode()-1) && matrix.classConfusion((int) c.getCode() - 1, i)!=0){
Consequent con = p.getConsequentByCode((float) i + 1);
Consequent n = new Consequent(con.getCode(), con.getName(), con.getText(), con.getPercentage_tree());
n.setPercentage_global(matrix.classConfusion((int) c.getCode() - 1, i));
c.addMistake(n);
}
}
}
return p;
}
/**
......@@ -50,8 +66,7 @@ public class IOImpl implements IOInterface{
* Extrae a matriz de confusión do problema
* @return matriz de confusión
*/
@Override
public ConfusionMatrix readMatrix() {
private ConfusionMatrix readMatrix() throws FileNotFoundException {
return this.rweka.readMatrix();
}
......
package iosystem;
import java.io.FileNotFoundException;
import javax.xml.bind.JAXBException;
import org.xml.sax.SAXException;
import rulesystem.Solution;
......@@ -15,19 +16,16 @@ public interface IOInterface {
* @return problema concreto
* @throws SAXException en caso de existir algún erro ao ler os xml
* @throws JAXBException en caso de existir algún erro ao ler os xml
* @throws java.io.FileNotFoundException en caso de non atopar o arquivo Weka
*/
public Problem readProblem() throws SAXException, JAXBException;
public Problem readProblem() throws SAXException, JAXBException, FileNotFoundException;
/**
* Extrae unha árbore de clasificación a partir dun problema concreto
* @param p problema concreto
* @return árbore de clasificación
*/
public Tree readTree(Problem p);
/**
* Extrae a matriz de confusión do problema
* @return matriz de confusión
*/
public ConfusionMatrix readMatrix();
/**
* Extrae a configuración global do sistema
* @return configuración global
......
......@@ -9,23 +9,20 @@ package iosystem;
public class LeafNode extends Node {
private final String consequent;
private final float instances;
private final float wrong;
private final float percentage;
/**
* Constructor
* @param text texto literal do nodo
* @param value valor numérico do nodo
* @param consequent nome do consecuente asociado ao nodo
* @param instances total de instancias clasificadas neste nodo
* @param wrong total de instancias clasificadas erróneamente
* @param percentage porcentaxe de fiabilidade da rama
*/
public LeafNode(String text, float value, String consequent, float instances, float wrong) {
public LeafNode(String text, float value, String consequent, float percentage) {
super.setText(text);
super.setValue(value);
this.consequent = consequent;
this.instances = instances;
this.wrong = wrong;
this.percentage = percentage;
}
/**
......@@ -72,19 +69,12 @@ public class LeafNode extends Node {
}
/**
* Getter do número de instancias clasificadas polo nodo
* @return número de instancias
* Getter do porcentaxe de fiabilidade da rama
* @return porcentaxe de fiabilidade
*/
public float getInstances() {
return instances;
public float getPercentage() {
return percentage;
}
/**
* Getter do número de instancias mal clasificadas polo nodo
* @return número de instancias
*/
public float getWrong() {
return wrong;
}
}
......@@ -53,7 +53,7 @@ public class Problem {
}
this.consequents = new ArrayList<>();
p.getConsequents().forEach((c) -> {
this.consequents.add(new Consequent(c.getCode(), c.getName(), c.getText(), c.getInstances(), c.getWrong()));
this.consequents.add(new Consequent(c.getCode(), c.getName(), c.getText(), c.getPercentage_tree()));
});
}
......
......@@ -16,7 +16,7 @@ import rulesystem.Consequent;
public class ReaderWeka {
private final FileContainer fcontainer;
private final Scanner scanner;
private Scanner scanner;
/**
* Constructor
......@@ -59,7 +59,8 @@ public class ReaderWeka {
matcherNode = patternNode.matcher(line);
matcherLeaf = patternLeaf.matcher(line);
String[] instances;
float percentage;
if (matcherNode.matches()) {
node = new NoLeafNode(line, Float.parseFloat(matcherNode.group(3)), matcherNode.group(1));
pending.add(node);
......@@ -70,9 +71,10 @@ public class ReaderWeka {
Consequent c = problem.getConsequentByName(matcherLeaf.group(4));
instances = matcherLeaf.group(5).split("/");
if (instances.length > 1) {
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), Float.parseFloat(instances[1])));
percentage = (Float.parseFloat(instances[0]) - Float.parseFloat(instances[1])) / Float.parseFloat(instances[0]) * 100;
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), percentage));
} else {
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), 0));
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), 100));
}
}
......@@ -100,9 +102,10 @@ public class ReaderWeka {
instances = matcherLeafAux.group(5).split("/");
if (instances.length > 1) {
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), Float.parseFloat(instances[1])));
percentage = (Float.parseFloat(instances[0]) - Float.parseFloat(instances[1])) / Float.parseFloat(instances[0]) * 100;
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), percentage));
} else {
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), 0));
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), 100));
}
pending.add(node);
}
......@@ -116,9 +119,10 @@ public class ReaderWeka {
Consequent c = problem.getConsequentByName(matcherLeaf.group(4));
instances = matcherLeaf.group(5).split("/");
if (instances.length > 1) {
pending.get(pending.size() - 1).setRightChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), Float.parseFloat(instances[1])));
percentage = (Float.parseFloat(instances[0]) - Float.parseFloat(instances[1])) / Float.parseFloat(instances[0]) * 100;
pending.get(pending.size() - 1).setRightChild(new LeafNode(c.getText(), c.getCode(), c.getName(), percentage));
} else {
pending.get(pending.size() - 1).setRightChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), 0));
pending.get(pending.size() - 1).setRightChild(new LeafNode(c.getText(), c.getCode(), c.getName(), 100));
}
pending.remove(pending.size() - 1);
} else {
......@@ -127,9 +131,10 @@ public class ReaderWeka {
Consequent c = problem.getConsequentByName(matcherLeaf.group(4));
instances = matcherLeaf.group(5).split("/");
if (instances.length > 1) {
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), Float.parseFloat(instances[1])));
percentage = (Float.parseFloat(instances[0]) - Float.parseFloat(instances[1])) / Float.parseFloat(instances[0]) * 100;
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), percentage));
} else {
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), Float.parseFloat(instances[0]), 0));
node.setLeftChild(new LeafNode(c.getText(), c.getCode(), c.getName(), 100));
}
pending.add(node);
}
......@@ -147,7 +152,7 @@ public class ReaderWeka {
* Constrúe a matriz de confusión do problema
* @return matriz de confusión
*/
public ConfusionMatrix readMatrix() {
public ConfusionMatrix readMatrix() throws FileNotFoundException {
ConfusionMatrix m = new ConfusionMatrix();
......@@ -176,7 +181,14 @@ public class ReaderWeka {
line = this.scanner.nextLine().split(" \\| ")[0].trim();
}
resetScanner();
return m;
}
private void resetScanner() throws FileNotFoundException{
this.scanner.close();
this.scanner = new Scanner(fcontainer.getWEKA_FILE());
}
}