Commit 4bead0f3 authored by Bruno López Trigo's avatar Bruno López Trigo

Engadida nova explicación con análise de casos transitivos e actualizado...

Engadida nova explicación con análise de casos transitivos e actualizado documento de requisitos da linguaxe
parent 0e5f5ae2
#Fri, 23 Mar 2018 14:36:11 +0100
#Sat, 31 Mar 2018 17:52:16 +0200
/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2=
......@@ -3,12 +3,16 @@
<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:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/log.xml</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/IOInterface.java</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/languagerealiser/ClauseGenerator.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/ConfusionMatrix.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/wekaparser/v2/Controller.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/IOImpl.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/src/iosystem/ReaderWeka.java</file>
<file>file:/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/config.xml</file>
</group>
</open-files>
</project-private>
......@@ -29,13 +29,15 @@ dist.jar=${dist.dir}/WekaParser-v2.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.cycles.jar=lib/cycles.jar
file.reference.jaxb-api-2.2.jar=lib/jaxb-api-2.2.jar
file.reference.SimpleNLG-4.4.9-SNAPSHOT.jar=lib/SimpleNLG-4.4.9-SNAPSHOT.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.SimpleNLG-4.4.9-SNAPSHOT.jar}:\
${file.reference.jaxb-api-2.2.jar}
${file.reference.jaxb-api-2.2.jar}:\
${file.reference.cycles.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
......
......@@ -74,13 +74,20 @@
<valueTxt>eventually</valueTxt>
<interval>
<leftValue>10</leftValue>
<rightValue>30</rightValue>
<rightValue>50</rightValue>
</interval>
</property>
<property>
<valueTxt>very</valueTxt>
<valueTxt>often</valueTxt>
<interval>
<leftValue>30</leftValue>
<leftValue>50</leftValue>
<rightValue>80</rightValue>
</interval>
</property>
<property>
<valueTxt>usually</valueTxt>
<interval>
<leftValue>80</leftValue>
<rightValue>100</rightValue>
</interval>
</property>
......
#!/bin/bash
properties_xsd="properties.xsd"
properties_xml="glass.xml"
entry_xsd="entry.xsd"
config_xsd="config.xsd"
config="config.xml"
log="logGlass.xml"
input="glassinput.xml"
weka="glass.txt"
html="explanationGlass.html"
type=glass
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>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
<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.</p><p>Types Lager, Porter, Stout, Belgian Strong Ale, Barleywine, IPA and Pilsner can lead to confusion. But among all of them pairs Barleywine, IPA and Pilsner, Lager are the most confused.</p><h2>Main Solution</h2><p>Beer is type Blanche because its strength is standard, its color is straw and its bitterness is low.</p><h2></h2>
\ No newline at end of file
<h1>Explanation</h1><p>Glass is type build wind non-float because system detected that its sodium and barium are low, medium or high, that its magnesium is medium or high, that its potassium is low and that its refractive index is low or high.</p><p>It is many times (61.84211 %) type build wind non-float however it can be of the following types.</p><ul><li>it is unlikely (2.0242915 %) to be type containers considering its refractive index slightly lower</li></ul><p>This glass could be confused with following types.</p><ul><li>it is likely (21.052631 %) to be type build wind float</li><li>it is unlikely (7.8947363 %) to be type vehic wind float</li><li>it is unlikely (3.9473681 %) to be type tableware</li><li>it is unlikely (7.692308 %) to be type headlamps</li></ul>
\ No newline at end of file
<h1>AutoExplainable Classifier</h1><h2>Global information</h2><p>There are 7 types of glass: build wind float, build wind non-float, vehic wind float, vehic wind non-float, containers, tableware and headlamps.</p><p>Types build wind float, vehic wind float, build wind non-float, containers, headlamps and tableware can lead to confusion. But among all of them pairs tableware, build wind float and build wind float, vehic wind float are the most confused.</p><h2>Main Solution</h2><p>Beer is type build wind non-float because its silicon is medium and its barium and refractive index are high.</p><h2>Alternatives</h2><p>However, this glass may be also build wind float because aluminum is quite close to the usual build wind float value. It may be also vehic wind float because silicon and calcium are quite close to the usual vehic wind float values.</p><p>For these specific values it is just as likely to be build wind float and vehic wind float.</p><p>In addition build wind float would be likely if classifier's global information is taken into account. But vehic wind float would be an exception.</p>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<problem>
<type>glass</type>
<attributes>
<attribute name="RI">
<value>1.53393</value>
</attribute>
<attribute name="Na">
<value>12.3</value>
</attribute>
<attribute name="Mg">
<value>0</value>
</attribute>
<attribute name="Al">
<value>1</value>
</attribute>
<attribute name="Si">
<value>70.16</value>
</attribute>
<attribute name="K">
<value>0.12</value>
</attribute>
<attribute name="Ca">
<value>16.19</value>
</attribute>
<attribute name="Ba">
<value>0</value>
</attribute>
<attribute name="Fe">
<value>0.24</value>
</attribute>
</attributes>
</problem>
<?xml version="1.0" encoding="UTF-8"?>
<problem>
<type>glass</type>
<attributes>
<attribute name="RI">
<value>1.5159</value>
</attribute>
<attribute name="Na">
<value>13.24</value>
</attribute>
<attribute name="Mg">
<value>3.34</value>
</attribute>
<attribute name="Al">
<value>1.47</value>
</attribute>
<attribute name="Si">
<value>73.1</value>
</attribute>
<attribute name="K">
<value>0.39</value>
</attribute>
<attribute name="Ca">
<value>8.22</value>
</attribute>
<attribute name="Ba">
<value>0</value>
</attribute>
<attribute name="Fe">
<value>0</value>
</attribute>
</attributes>
</problem>
......@@ -3,13 +3,13 @@
<type>beer</type>
<attributes>
<attribute name="Color">
<value>11</value>
<value>2</value>
</attribute>
<attribute name="Bitterness">
<value>93</value>
<value>17</value>
</attribute>
<attribute name="Strength">
<value>0.095</value>
<value>0.046</value>
</attribute>
</attributes>
</problem>
......@@ -6,7 +6,7 @@
<antecedents>
<antecedent>
<attribute name="Strength">
<value>0.095</value>
<value>0.046</value>
<valuetxt>Strength</valuetxt>
<maxValue>0.136</maxValue>
<minValue>0.035</minValue>
......@@ -43,68 +43,23 @@
</properties>
</attribute>
<interval>
<leftValue>0.091</leftValue>
<rightValue>0.136</rightValue>
<leftValue>0.035</leftValue>
<rightValue>0.07</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>0.09</leftValue>
<rightValue>0.136</rightValue>
<leftValue>0.035</leftValue>
<rightValue>0.0525</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="Bitterness">
<value>93.0</value>
<valuetxt>Bitterness</valuetxt>
<maxValue>250.0</maxValue>
<minValue>7.0</minValue>
<modified>false</modified>
<properties>
<property>
<valueTxt>Low</valueTxt>
<interval>
<leftValue>7.0</leftValue>
<rightValue>21.0</rightValue>
</interval>
</property>
<property>
<valueTxt>Low-Medium</valueTxt>
<interval>
<leftValue>21.0</leftValue>
<rightValue>32.5</rightValue>
</interval>
</property>
<property>
<valueTxt>Medium-High</valueTxt>
<interval>
<leftValue>32.5</leftValue>
<rightValue>47.5</rightValue>
</interval>
</property>
<property>
<valueTxt>High</valueTxt>
<interval>
<leftValue>47.5</leftValue>
<rightValue>250.0</rightValue>
</interval>
</property>
</properties>
</attribute>
<interval>
<leftValue>48.0</leftValue>
<rightValue>250.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>47.5</leftValue>
<rightValue>250.0</rightValue>
<leftValue>0.0525</leftValue>
<rightValue>0.0675</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="Color">
<value>11.0</value>
<value>2.0</value>
<valuetxt>Color</valuetxt>
<maxValue>45.0</maxValue>
<minValue>0.0</minValue>
......@@ -148,97 +103,23 @@
</properties>
</attribute>
<interval>
<leftValue>8.0</leftValue>
<rightValue>11.0</rightValue>
<leftValue>0.0</leftValue>
<rightValue>6.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>7.5</leftValue>
<rightValue>19.0</rightValue>
<leftValue>0.0</leftValue>
<rightValue>3.0</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
</antecedents>
<consequent>
<code>6.0</code>
<name>6.0</name>
<text>Barleywine</text>
<percentage_global>0.0</percentage_global>
<percentage_tree>80.0</percentage_tree>
<mistakes>
<mistake>
<code>4.0</code>
<name>4.0</name>
<text>IPA</text>
<percentage_global>14.0</percentage_global>
<percentage_tree>0.0</percentage_tree>
<mistakes/>
</mistake>
<mistake>
<code>8.0</code>
<name>8.0</name>
<text>Belgian Strong Ale</text>
<percentage_global>2.0</percentage_global>
<percentage_tree>0.0</percentage_tree>
<mistakes/>
</mistake>
</mistakes>
</consequent>
</rule>
<rule>
<antecedents>
<antecedent>
<attribute name="Strength">
<value>0.09025</value>
<valuetxt>Strength</valuetxt>
<maxValue>0.136</maxValue>
<minValue>0.035</minValue>
<modified>true</modified>
<properties>
<property>
<valueTxt>Session</valueTxt>
<interval>
<leftValue>0.035</leftValue>
<rightValue>0.0525</rightValue>
</interval>
</property>
<property>
<valueTxt>Standard</valueTxt>
<interval>
<leftValue>0.0525</leftValue>
<rightValue>0.0675</rightValue>
</interval>
</property>
<property>
<valueTxt>High</valueTxt>
<interval>
<leftValue>0.0675</leftValue>
<rightValue>0.09</rightValue>
</interval>
</property>
<property>
<valueTxt>Very high</valueTxt>
<interval>
<leftValue>0.09</leftValue>
<rightValue>0.136</rightValue>
</interval>
</property>
</properties>
</attribute>
<interval>
<leftValue>0.07</leftValue>
<rightValue>0.091</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>0.0675</leftValue>
<rightValue>0.09</rightValue>
<leftValue>3.0</leftValue>
<rightValue>7.5</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="Bitterness">
<value>93.0</value>
<value>17.0</value>
<valuetxt>Bitterness</valuetxt>
<maxValue>250.0</maxValue>
<minValue>7.0</minValue>
......@@ -275,49 +156,24 @@
</properties>
</attribute>
<interval>
<leftValue>48.0</leftValue>
<rightValue>250.0</rightValue>
<leftValue>7.0</leftValue>
<rightValue>26.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>47.5</leftValue>
<rightValue>250.0</rightValue>
<leftValue>7.0</leftValue>
<rightValue>21.0</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
</antecedents>
<consequent>
<code>4.0</code>
<name>4.0</name>
<text>IPA</text>
<code>1.0</code>
<name>1.0</name>
<text>Blanche</text>
<percentage_global>0.0</percentage_global>
<percentage_tree>93.75</percentage_tree>
<mistakes>
<mistake>
<code>2.0</code>
<name>2.0</name>
<text>Lager</text>
<percentage_global>2.0</percentage_global>
<percentage_tree>0.0</percentage_tree>
<mistakes/>
</mistake>
<mistake>
<code>3.0</code>
<name>3.0</name>
<text>Pilsner</text>
<percentage_global>2.0</percentage_global>
<percentage_tree>0.0</percentage_tree>
<mistakes/>
</mistake>
<mistake>
<code>6.0</code>
<name>6.0</name>
<text>Barleywine</text>
<percentage_global>10.0</percentage_global>
<percentage_tree>0.0</percentage_tree>
<mistakes/>
</mistake>
</mistakes>
<percentage_tree>100.0</percentage_tree>
<mistakes/>
</consequent>
</rule>
</rules>
......
This diff is collapsed.
package iosystem;
import de.normalisiert.utils.graphs.ElementaryCyclesSearch;
import java.util.ArrayList;
import java.util.List;
import rulesystem.Consequent;
/**
*
......@@ -10,13 +13,23 @@ import java.util.ArrayList;
*/
public class ConfusionMatrix {
private final String[] nodes;
private final ArrayList<ArrayList<Integer>> matrix;
private boolean adjMatrix[][];
/**
* Constructor que inicia a matriz vacía
* @param c Lista de consecuentes
*/
public ConfusionMatrix() {
public ConfusionMatrix(ArrayList<Consequent> c) {
this.nodes = new String[c.size()];
int i=0;
for(Consequent con: c){
this.nodes[i] = con.getName();
i++;
}
this.matrix = new ArrayList<>();
this.adjMatrix = null;
}
/**
......@@ -24,7 +37,19 @@ public class ConfusionMatrix {
* @param row fila nova
*/
public void addRow(ArrayList<Integer> row){
if(this.adjMatrix==null){
this.adjMatrix = new boolean[row.size()][row.size()];
}
int column = 0;
for(Integer i: row){
this.adjMatrix[this.matrix.size()][column] = (i!=0 && column!=this.matrix.size());
column++;
}
this.matrix.add(new ArrayList<>(row));
}
/**
......@@ -77,4 +102,12 @@ public class ConfusionMatrix {
return getElement(row, column) / sum * 100;
}
public List getCycles(){
ElementaryCyclesSearch ecs = new ElementaryCyclesSearch(this.adjMatrix, this.nodes);
return ecs.getElementaryCycles();
}
}
package iosystem;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBException;
import org.xml.sax.SAXException;
import rulesystem.Consequent;
......@@ -28,21 +30,21 @@ public class IOImpl implements IOInterface{
/**
* Extrae o problema de clasificación a resolver
* @return problema de clasificación
* @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
*/
@Override
public Problem readProblem() throws SAXException, JAXBException, FileNotFoundException {
ConfusionMatrix matrix = readMatrix();
Problem p = this.xmlparser.extractProblem();
p.setMatrix(readMatrix(p.getConsequents()));
for(Consequent c: p.getConsequents()){
c.setPercentage_global(matrix.classReliability((int) c.getCode() - 1));
c.setPercentage_global(p.getMatrix().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){
if(i!=(c.getCode()-1) && p.getMatrix().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));
n.setPercentage_global(p.getMatrix().classConfusion((int) c.getCode() - 1, i));
c.addMistake(n);
}
}
......@@ -66,8 +68,8 @@ public class IOImpl implements IOInterface{
* Extrae a matriz de confusión do problema
* @return matriz de confusión
*/
private ConfusionMatrix readMatrix() throws FileNotFoundException {
return this.rweka.readMatrix();
private ConfusionMatrix readMatrix(ArrayList<Consequent> c) throws FileNotFoundException {
return this.rweka.readMatrix(c);
}
/**
......
......@@ -13,7 +13,7 @@ public interface IOInterface {
/**
* Extrae un problema concreto
* @return problema concreto
* @return problema concreto extraido
* @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
......
......@@ -26,7 +26,7 @@ public class Problem {
@XmlElementWrapper(name="consequents")
@XmlElement(name="consequent")
private final ArrayList<Consequent> consequents;
private ConfusionMatrix matrix;
/**
* Constructor vacío para xerar XML
*/
......@@ -133,4 +133,13 @@ public class Problem {
return null;
}
public void setMatrix(ConfusionMatrix matrix) {
this.matrix = matrix;
}
public ConfusionMatrix getMatrix() {
return matrix;
}
}
......@@ -150,11 +150,12 @@ public class ReaderWeka {
/**
* Constrúe a matriz de confusión do problema
* @param c Lista de consecuentes
* @return matriz de confusión
*/
public ConfusionMatrix readMatrix() throws FileNotFoundException {
public ConfusionMatrix readMatrix(ArrayList<Consequent> c) throws FileNotFoundException {
ConfusionMatrix m = new ConfusionMatrix();
ConfusionMatrix m = new ConfusionMatrix(c);
String line = "";
ArrayList<Integer> row = new ArrayList<>();
......
......@@ -42,7 +42,7 @@ public class XMLParser {
p2.setType(p1.getType());
for(int i=0; i<p2.getAttributes().size(); i++){
p2.getAttributes().get(i).setValue(p1.getAttributes().get(i).getValue());
p2.getAttributes().get(i).setValue(p1.getAttributeByName(p2.getAttributes().get(i).getName()).getValue());
}
return p2;
......
package languagerealiser;
import iosystem.FileContainer;
import java.io.IOException;
import java.util.ArrayList;
import simplenlg.features.Feature;
import simplenlg.features.Tense;
import simplenlg.format.english.HTMLFormatter;
import simplenlg.framework.CoordinatedPhraseElement;
import simplenlg.framework.DocumentElement;
import simplenlg.framework.NLGElement;
import simplenlg.framework.NLGFactory;
import simplenlg.lexicon.Lexicon;
import simplenlg.phrasespec.SPhraseSpec;
import simplenlg.phrasespec.VPPhraseSpec;
import simplenlg.realiser.english.Realiser;
public class ClauseGenerator {
private final Lexicon lexicon;
private final NLGFactory nlgFactory;
private final Realiser realiser;
public ClauseGenerator() {
this.lexicon = Lexicon.getDefaultLexicon();
this.nlgFactory = new NLGFactory(lexicon);
this.realiser = new Realiser(lexicon);
}
public SPhraseSpec generateClause(ArrayList<String> subject, String verb, ArrayList<String> object, boolean plural){
SPhraseSpec phrase = this.nlgFactory.createClause();
VPPhraseSpec verbPhrase = this.nlgFactory.createVerbPhrase(verb);
CoordinatedPhraseElement subjectPhrase = this.nlgFactory.createCoordinatedPhrase();
CoordinatedPhraseElement objectPhrase = this.nlgFactory.createCoordinatedPhrase();
for(String s: subject){
subjectPhrase.addCoordinate(s);
}
for(String s: object){
objectPhrase.addCoordinate(s);
}
phrase.setSubject(subjectPhrase);
phrase.setVerb(verbPhrase);
phrase.setObject(objectPhrase);
phrase.setPlural(plural);
return phrase;
}