Commit e41b38d4 authored by Bruno López Trigo's avatar Bruno López Trigo

Engadida correspondencia entre códigos e labels para os tipos de cervexa no xml de configuración

parent 23528e2a
......@@ -2,6 +2,9 @@
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<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/>
<group>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v1/resources/inputexample.xml</file>
<file>file:/C:/Users/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v1/resources/beer.xml</file>
</group>
</open-files>
</project-private>
......@@ -113,4 +113,38 @@
</properties>
</attribute>
</attributes>
<consequents>
<consequent>
<code>1</code>
<text>Blanche</text>
</consequent>
<consequent>
<code>2</code>
<text>Lager</text>
</consequent>
<consequent>
<code>3</code>
<text>Pilsner</text>
</consequent>
<consequent>
<code>4</code>
<text>IPA</text>
</consequent>
<consequent>
<code>5</code>
<text>Stout</text>
</consequent>
<consequent>
<code>6</code>
<text>Barleywine</text>
</consequent>
<consequent>
<code>7</code>
<text>Porter</text>
</consequent>
<consequent>
<code>8</code>
<text>Belgian Strong Ale</text>
</consequent>
</consequents>
</container>
\ No newline at end of file
......@@ -5,15 +5,15 @@
<entries>
<entry>
<attribute>Color</attribute>
<value>4</value>
<value>36</value>
</entry>
<entry>
<attribute>Bitterness</attribute>
<value>20</value>
<value>28</value>
</entry>
<entry>
<attribute>Strength</attribute>
<value>0.03</value>
<value>0.065</value>
</entry>
</entries>
</problem>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rule>
<type>beer</type>
<antecedents>
<antecedent>
<attribute name="Strength">
<value>0.03</value>
<value>0.065</value>
<maxValue>0.136</maxValue>
<minValue>0.035</minValue>
<properties>
......@@ -54,7 +55,7 @@
</antecedent>
<antecedent>
<attribute name="Color">
<value>4.0</value>
<value>36.0</value>
<maxValue>45.0</maxValue>
<minValue>0.0</minValue>
<properties>
......@@ -96,71 +97,20 @@
</properties>
</attribute>
<interval>
<leftValue>0.0</leftValue>
<rightValue>6.0</rightValue>
<leftValue>29.0</leftValue>
<rightValue>45.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>0.0</leftValue>
<rightValue>3.0</rightValue>
</posibleinterval>
<posibleinterval>
<leftValue>3.0</leftValue>
<rightValue>7.5</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="Bitterness">
<value>20.0</value>
<maxValue>250.0</maxValue>
<minValue>7.0</minValue>
<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>7.0</leftValue>
<rightValue>26.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>7.0</leftValue>
<rightValue>21.0</rightValue>
<leftValue>29.0</leftValue>
<rightValue>45.0</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
</antecedents>
<consequent>
<code>1.0</code>
<text>1.0</text>
<code>5.0</code>
<text>Stout</text>
<percentage>100.0</percentage>
<mistakes/>
</consequent>
......
......@@ -43,6 +43,20 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="consequents">
<xs:complexType>
<xs:sequence>
<xs:element name="consequent" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="code"/>
<xs:element type="xs:string" name="text"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
......
<h1>Beer Classification</h1><h2>Explanation</h2><p>Beer is type 1.0 the 100.0% of times because system detected that its Strength is Session or Standard, that its Color is Pale or Straw and that its Bitterness is Low.</p><p>This classification is derived from the following data.</p><p><ul><li>possible intervals are [0.035, 0.0525] as "Session" and [0.0525, 0.0675] as "Standard" while its Strength is between 0.035 and 0.07</li><li>possible intervals are [0.0, 3.0] as "Pale" and [3.0, 7.5] as "Straw" while its Color is between 0.0 and 6.0</li><li>possible interval is [7.0, 21.0] as "Low" while its Bitterness is between 7.0 and 26.0</li></ul></p>
<h1>Beer Classification</h1><h2>Explanation</h2><p>Beer is type Stout the 100.0% of times because system detected that its Strength is Session or Standard and that its Color is Black.</p><p>This classification is derived from the following data.</p><p><ul><li>possible intervals are [0.035, 0.0525] as "Session" and [0.0525, 0.0675] as "Standard" while its Strength is between 0.035 and 0.07</li><li>possible interval is [29.0, 45.0] as "Black" while its Color is between 29.0 and 45.0</li></ul></p>
......@@ -124,7 +124,7 @@ public class LanguageRealiser implements LanguageRealiserInterface {
public SPhraseSpec generateConsequentTxt(Rule rule) {
Consequent cons = rule.getConsequent();
SPhraseSpec sentence = this.nlgFactory.createClause();
NPPhraseSpec subject = this.nlgFactory.createNounPhrase("beer");
NPPhraseSpec subject = this.nlgFactory.createNounPhrase(rule.getType());
VPPhraseSpec verb = this.nlgFactory.createVerbPhrase("be");
NPPhraseSpec object = this.nlgFactory.createNounPhrase("type " + cons.getText());
object.addModifier("the " + cons.getPercentage() + "% of times");
......@@ -163,7 +163,9 @@ public class LanguageRealiser implements LanguageRealiserInterface {
consequent.addComplement(sentece);
DocumentElement doc = this.nlgFactory.createDocument("Beer Classification");
String type = Character.toUpperCase(rule.getType().charAt(0)) + rule.getType().substring(1);
DocumentElement doc = this.nlgFactory.createDocument(type + " Classification");
DocumentElement s1 = this.nlgFactory.createSection("Explanation");
s1.addComponent(consequent);
......
......@@ -65,6 +65,7 @@ public class XMLParser {
AttributeContainer container = (AttributeContainer) (jaxbUnmarshaller.unmarshal(this.fcontainer.getPROPERTIES_XML()));
problem.setAttributes(container.getAttributes());
problem.setConsequents(container.getConsequents());
for(Attribute a : problem.getAttributes()){
a.setValue(problem.getEntryByName(a.getName()).getValue());
......
......@@ -31,6 +31,7 @@ public class Consequent {
public Consequent() {
this.code = 0;
this.text = null;
this.mistakes = new ArrayList<>();
}
/**
......
......@@ -15,6 +15,8 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "rule")
public class Rule {
@XmlElement(name="type")
private String type;
@XmlElementWrapper(name="antecedents")
@XmlElement(name = "antecedent")
private final ArrayList<Antecedent> antecedents;
......@@ -26,6 +28,7 @@ public class Rule {
*/
public Rule() {
this.antecedents = new ArrayList<>();
this.type = null;
}
/**
......@@ -95,5 +98,21 @@ public class Rule {
public Consequent getConsequent() {
return consequent;
}
/**
* Getter del tipo de la regla
* @return tipo de la regla
*/
public String getType() {
return type;
}
/**
* Setter para el tipo de regla
* @param type tipo
*/
public void setType(String type) {
this.type = type;
}
}
......@@ -41,6 +41,7 @@ public class RuleBuilder implements RuleBuilderInterface {
*/
@Override
public Rule buildRules(Problem problem) {
this.rule.setType(problem.getType());
this.reader.goToTreeStart();
// Grupo 1: Atributo --- Grupo 2: Condicion --- Grupo 3: Valor
Pattern patternNode = Pattern.compile("^(\\w*)\\s(<=|>)\\s([+-]?[0-9]*.?[0-9]+)$");
......@@ -91,10 +92,10 @@ public class RuleBuilder implements RuleBuilderInterface {
interval = new Interval(interval.getLeftValue(), this.rule.getAntecedentByAtt(matcherLeaf.group(1)).getInterval().getRightValue());
antecedent.setInterval(interval);
this.rule.modifyAntecedent(antecedent);
this.rule.setConsequent(new Consequent(Float.parseFloat(matcherLeaf.group(4)), matcherLeaf.group(4)));
this.rule.setConsequent(problem.getConsequentByCode(Float.parseFloat(matcherLeaf.group(4))));
} else {
this.rule.addAntecedent(antecedent);
this.rule.setConsequent(new Consequent(Float.parseFloat(matcherLeaf.group(4)), matcherLeaf.group(4)));
this.rule.setConsequent(problem.getConsequentByCode(Float.parseFloat(matcherLeaf.group(4))));
}
}
}
......@@ -110,10 +111,10 @@ public class RuleBuilder implements RuleBuilderInterface {
interval = new Interval(this.rule.getAntecedentByAtt(matcherLeaf.group(1)).getInterval().getLeftValue(), interval.getRightValue());
antecedent.setInterval(interval);
this.rule.modifyAntecedent(antecedent);
this.rule.setConsequent(new Consequent(Float.parseFloat(matcherLeaf.group(4)), matcherLeaf.group(4)));
this.rule.setConsequent(problem.getConsequentByCode(Float.parseFloat(matcherLeaf.group(4))));
} else {
this.rule.addAntecedent(antecedent);
this.rule.setConsequent(new Consequent(Float.parseFloat(matcherLeaf.group(4)), matcherLeaf.group(4)));
this.rule.setConsequent(problem.getConsequentByCode(Float.parseFloat(matcherLeaf.group(4))));
}
} else {
line = this.reader.readTreeLine().replaceAll("\\|\\s*", "");
......@@ -140,10 +141,10 @@ public class RuleBuilder implements RuleBuilderInterface {
interval = new Interval(interval.getLeftValue(), this.rule.getAntecedentByAtt(matcherLeaf.group(1)).getInterval().getRightValue());
antecedent.setInterval(interval);
this.rule.modifyAntecedent(antecedent);
this.rule.setConsequent(new Consequent(Float.parseFloat(matcherLeaf.group(4)), matcherLeaf.group(4)));
this.rule.setConsequent(problem.getConsequentByCode(Float.parseFloat(matcherLeaf.group(4))));
} else {
this.rule.addAntecedent(antecedent);
this.rule.setConsequent(new Consequent(Float.parseFloat(matcherLeaf.group(4)), matcherLeaf.group(4)));
this.rule.setConsequent(problem.getConsequentByCode(Float.parseFloat(matcherLeaf.group(4))));
}
}
}
......@@ -152,7 +153,7 @@ public class RuleBuilder implements RuleBuilderInterface {
}
addPosibleIntervals();
addMistakes();
addMistakes(problem);
return this.rule;
}
......@@ -186,7 +187,7 @@ public class RuleBuilder implements RuleBuilderInterface {
/**
* Añade un posible error del consecuente a la lista de posibles errores
*/
private void addMistakes() {
private void addMistakes(Problem problem) {
this.reader.goToMatrixStart();
String[] splited_line;
......@@ -214,7 +215,7 @@ public class RuleBuilder implements RuleBuilderInterface {
for (int i=0; i<splited_line.length; i++){
value = Float.parseFloat(splited_line[i]);
if(level != i && value != 0){
Consequent con = new Consequent(level, String.valueOf(i+1.0));
Consequent con = problem.getConsequentByCode((float) level);
con.setPercentage(value/sum*100);
this.rule.getConsequent().addMistake(con);
}
......
......@@ -7,6 +7,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import rulesystem.Consequent;
/**
* Contenedor de atributos
......@@ -19,12 +20,16 @@ public class AttributeContainer {
@XmlElementWrapper(name="attributes")
@XmlElement(name="attribute")
private final ArrayList<Attribute> attributes;
@XmlElementWrapper(name="consequents")
@XmlElement(name="consequent")
private final ArrayList<Consequent> consequents;
/**
* Constructor vacío para generar XML
*/
public AttributeContainer() {
this.attributes = new ArrayList<>();
this.consequents = new ArrayList<>();
}
/**
......@@ -34,5 +39,13 @@ public class AttributeContainer {
public ArrayList<Attribute> getAttributes() {
return attributes;
}
/**
* Getter de los consecuentes
* @return lista de consecuentes
*/
public ArrayList<Consequent> getConsequents() {
return consequents;
}
}
......@@ -7,6 +7,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import rulesystem.Consequent;
/**
* Problema concreto
......@@ -24,7 +25,7 @@ public class Problem {
private final ArrayList<Entry> entries;
private ArrayList<Attribute> attributes;
private ArrayList<Consequent> consequents;
/**
* Constructor vacío para generar XML
*/
......@@ -107,5 +108,35 @@ public class Problem {
public String getType() {
return type;
}
/**
* Setter de los consecuentes del problema
* @param consequents lista de consecuentes
*/
public void setConsequents(ArrayList<Consequent> consequents) {
this.consequents = consequents;
}
/**
* Getter de los consecuentes del problema
* @return lista de consecuentes
*/
public ArrayList<Consequent> getConsequents() {
return consequents;
}
/**
* Obtiene un consecuente por su código
* @param code código del consecuente
* @return consecuente, en caso de existir o null, si no existe
*/
public Consequent getConsequentByCode(Float code){
for(Consequent c : this.consequents){
if(c.getCode() == code){
return c;
}
}
return null;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment