Commit 874ee8f1 authored by Bruno López Trigo's avatar Bruno López Trigo

Solucionado bug que xeraba explicacións alternativas extra

parent b508f8d3
#Tue, 20 Mar 2018 14:33:58 +0100
#Tue, 20 Mar 2018 17:42:04 +0100
C\:\\Users\\brilemau\\Documents\\repos\\ExpliClas-TFG\\codigo\\WekaParser-v2=
......@@ -3,28 +3,28 @@
<type>diabetes</type>
<attributes>
<attribute name="preg">
<value>2</value>
<value>0</value>
</attribute>
<attribute name="plas">
<value>120</value>
<value>137</value>
</attribute>
<attribute name="pres">
<value>0</value>
<value>40</value>
</attribute>
<attribute name="skin">
<value>0</value>
<value>35</value>
</attribute>
<attribute name="insu">
<value>0</value>
<value>168</value>
</attribute>
<attribute name="mass">
<value>40</value>
<value>43.1</value>
</attribute>
<attribute name="pedi">
<value>1.183</value>
<value>2.288</value>
</attribute>
<attribute name="age">
<value>38</value>
<value>33</value>
</attribute>
</attributes>
</problem>
<h1>Explanation</h1><p>Beer is type IPA because system detected that its strength and bitterness are high.</p><ul></ul><p>This beer could be confused with following types.</p><ul><li>it is unlikely (2.0 %) to be type Lager</li><li>it is unlikely (2.0 %) to be type Pilsner</li><li>it is unlikely (10.0 %) to be type Barleywine</li></ul>
\ No newline at end of file
<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>Explanation</h1><p>Diabetes is type Negative because system detected that its age and diabetes pedigree function are medium or high, that its plasma glucose concentration is medium, that its body mass index is high and that its number of times pregnant is low.</p><ul></ul><p>This diabetes could be confused with following types.</p><ul><li>it is likely (21.199999 %) to be type Positive</li></ul>
\ No newline at end of file
<h1>Explanation</h1><p>Diabetes is type Positive because system detected that its body mass index and plasma glucose concentration are high and that its diastolic blood pressure is low.</p><ul></ul><p>This diabetes could be confused with following types.</p><ul><li>it is likely (38.80597 %) to be type Negative</li></ul>
\ No newline at end of file
<h1>Explanation</h1><p>Glass is type vehic wind float because system detected that its potassium, barium and magnesium are low, medium or high, that its silicon and aluminum are medium or high, that its refractive index is low and that its sodium is medium.</p><p>It is eventually (41.17647 %) type vehic wind float however it can be of the following types.</p><ul><li>it is likely (21.008406 %) to be type build wind float considering its refractive index slightly lower</li></ul><p>This glass could be confused with following types.</p><ul><li>it is likely (23.529411 %) to be type build wind non-float</li><li>it is unlikely (5.882353 %) to be type tableware</li></ul>
\ 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
......@@ -3,31 +3,31 @@
<type>glass</type>
<attributes>
<attribute name="RI">
<value>1.52121</value>
<value>1.53393</value>
</attribute>
<attribute name="Na">
<value>14.03</value>
<value>12.3</value>
</attribute>
<attribute name="Mg">
<value>3.76</value>
<value>0</value>
</attribute>
<attribute name="Al">
<value>0.58</value>
<value>1</value>
</attribute>
<attribute name="Si">
<value>71.79</value>
<value>70.16</value>
</attribute>
<attribute name="K">
<value>0.11</value>
<value>0.12</value>
</attribute>
<attribute name="Ca">
<value>9.65</value>
<value>16.19</value>
</attribute>
<attribute name="Ba">
<value>0</value>
</attribute>
<attribute name="Fe">
<value>0</value>
<value>0.24</value>
</attribute>
</attributes>
</problem>
......@@ -3,13 +3,13 @@
<type>beer</type>
<attributes>
<attribute name="Color">
<value>24</value>
<value>30</value>
</attribute>
<attribute name="Bitterness">
<value>60</value>
<value>29</value>
</attribute>
<attribute name="Strength">
<value>0.08</value>
<value>0.046</value>
</attribute>
</attributes>
</problem>
This diff is collapsed.
......@@ -6,7 +6,7 @@
<antecedents>
<antecedent>
<attribute name="plas">
<value>120.0</value>
<value>137.0</value>
<valuetxt>Plasma glucose concentration</valuetxt>
<maxValue>199.0</maxValue>
<minValue>0.0</minValue>
......@@ -36,19 +36,19 @@
</properties>
</attribute>
<interval>
<leftValue>99.0</leftValue>
<rightValue>127.0</rightValue>
<leftValue>127.0</leftValue>
<rightValue>157.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>60.0</leftValue>
<rightValue>120.0</rightValue>
<leftValue>120.0</leftValue>
<rightValue>199.0</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="mass">
<value>40.0</value>
<value>43.1</value>
<valuetxt>Body mass index</valuetxt>
<maxValue>67.1</maxValue>
<minValue>0.0</minValue>
......@@ -78,7 +78,7 @@
</properties>
</attribute>
<interval>
<leftValue>33.1</leftValue>
<leftValue>29.9</leftValue>
<rightValue>67.1</rightValue>
</interval>
<posibleintervals>
......@@ -89,56 +89,10 @@
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="age">
<value>38.0</value>
<valuetxt>Age</valuetxt>
<maxValue>81.0</maxValue>
<minValue>21.0</minValue>
<modified>false</modified>
<properties>
<property>
<valueTxt>Low</valueTxt>
<interval>
<leftValue>21.0</leftValue>
<rightValue>41.0</rightValue>
</interval>
</property>
<property>
<valueTxt>Medium</valueTxt>
<interval>
<leftValue>41.0</leftValue>
<rightValue>61.0</rightValue>
</interval>
</property>
<property>
<valueTxt>High</valueTxt>
<interval>
<leftValue>61.0</leftValue>
<rightValue>81.0</rightValue>
</interval>
</property>
</properties>
</attribute>
<interval>
<leftValue>34.0</leftValue>
<rightValue>81.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>41.0</leftValue>
<rightValue>61.0</rightValue>
</posibleinterval>
<posibleinterval>
<leftValue>61.0</leftValue>
<rightValue>81.0</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="pedi">
<value>1.183</value>
<valuetxt>Diabetes pedigree function</valuetxt>
<maxValue>2.42</maxValue>
<attribute name="pres">
<value>40.0</value>
<valuetxt>Diastolic blood pressure</valuetxt>
<maxValue>122.0</maxValue>
<minValue>0.0</minValue>
<modified>false</modified>
<properties>
......@@ -146,89 +100,50 @@
<valueTxt>Low</valueTxt>
<interval>
<leftValue>0.0</leftValue>
<rightValue>0.7</rightValue>
<rightValue>40.0</rightValue>
</interval>
</property>
<property>
<valueTxt>Medium</valueTxt>
<interval>
<leftValue>0.7</leftValue>
<rightValue>1.4</rightValue>
</interval>
</property>
<property>
<valueTxt>High</valueTxt>
<interval>
<leftValue>1.4</leftValue>
<rightValue>2.42</rightValue>
</interval>
</property>
</properties>
</attribute>
<interval>
<leftValue>0.561</leftValue>
<rightValue>2.42</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>0.7</leftValue>
<rightValue>1.4</rightValue>
</posibleinterval>
<posibleinterval>
<leftValue>1.4</leftValue>
<rightValue>2.42</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
<antecedent>
<attribute name="preg">
<value>2.0</value>
<valuetxt>Number of times pregnant</valuetxt>
<maxValue>17.0</maxValue>
<minValue>0.0</minValue>
<modified>false</modified>
<properties>
<property>
<valueTxt>Low</valueTxt>
<interval>
<leftValue>0.0</leftValue>
<rightValue>9.0</rightValue>
<leftValue>40.0</leftValue>
<rightValue>80.0</rightValue>
</interval>
</property>
<property>
<valueTxt>High</valueTxt>
<interval>
<leftValue>9.0</leftValue>
<rightValue>17.0</rightValue>
<leftValue>80.0</leftValue>
<rightValue>122.0</rightValue>
</interval>
</property>
</properties>
</attribute>
<interval>
<leftValue>0.0</leftValue>
<rightValue>6.0</rightValue>
<rightValue>61.0</rightValue>
</interval>
<posibleintervals>
<posibleinterval>
<leftValue>0.0</leftValue>
<rightValue>9.0</rightValue>
<rightValue>40.0</rightValue>
</posibleinterval>
</posibleintervals>
</antecedent>
</antecedents>
<consequent>
<code>1.0</code>
<name>tested_negative</name>
<text>Negative</text>
<percentage>78.799995</percentage>
<instances>4.0</instances>
<code>2.0</code>
<name>tested_positive</name>
<text>Positive</text>
<percentage>61.19403</percentage>
<instances>15.0</instances>
<wrong>1.0</wrong>
<mistakes>
<mistake>
<code>2.0</code>
<name>tested_positive</name>
<text>Positive</text>
<percentage>21.199999</percentage>
<code>1.0</code>
<name>tested_negative</name>
<text>Negative</text>
<percentage>38.80597</percentage>
<instances>0.0</instances>
<wrong>0.0</wrong>
<mistakes/>
......
This diff is collapsed.
......@@ -28,7 +28,7 @@ import simplenlg.realiser.english.Realiser;
/**
*
* Constructor e realizador lingüístico
*
*
* @author Bruno López Trigo
*/
public class LanguageRealiser implements LanguageRealiserInterface {
......@@ -61,6 +61,7 @@ public class LanguageRealiser implements LanguageRealiserInterface {
/**
* Constrúe a explicación da solución principal
*
* @return sección de explicación principal
*/
public DocumentElement buildMainExplanation() {
......@@ -83,7 +84,7 @@ public class LanguageRealiser implements LanguageRealiserInterface {
String att;
ArrayList<String> labs;
ArrayList<String> atts = new ArrayList<>();
for (Antecedent a : r.getAntecedents()) {
att = a.getAttribute().getValueTxt().toLowerCase();
atts.add(att);
......@@ -104,30 +105,29 @@ public class LanguageRealiser implements LanguageRealiserInterface {
HashMap<String, ArrayList<String>> same = new HashMap<>();
boolean equals = true;
String attribute;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
attribute = (String) pair.getKey();
if(atts.contains(attribute)){
if (atts.contains(attribute)) {
Iterator it2 = labels.entrySet().iterator();
while (it2.hasNext()) {
Map.Entry pair2 = (Map.Entry) it2.next();
ArrayList<String> labels1 = (ArrayList<String>) pair.getValue();
ArrayList<String> labels2 = (ArrayList<String>) pair2.getValue();
if(labels1.size() == labels2.size() && !((String) pair.getKey()).equals((String) pair2.getKey())){
for(int i=0; i<labels1.size(); i++){
if(!labels1.get(i).equals(labels2.get(i))){
ArrayList<String> labels2 = (ArrayList<String>) pair2.getValue();
if (labels1.size() == labels2.size() && !((String) pair.getKey()).equals((String) pair2.getKey())) {
for (int i = 0; i < labels1.size(); i++) {
if (!labels1.get(i).equals(labels2.get(i))) {
equals = false;
break;
}
}
if(equals == true){
if (equals == true) {
atts.remove((String) pair.getKey());
atts.remove((String) pair2.getKey());
if(same.get(attribute)!=null){
if (same.get(attribute) != null) {
same.get(attribute).add((String) pair2.getKey());
}
else{
} else {
ArrayList<String> s = new ArrayList<>();
s.add((String) pair2.getKey());
same.put(attribute, s);
......@@ -138,11 +138,11 @@ public class LanguageRealiser implements LanguageRealiserInterface {
}
}
}
VPPhraseSpec verbAtt = this.nlgFactory.createVerbPhrase("be");
it = same.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
SPhraseSpec attClause = this.nlgFactory.createClause();
......@@ -153,14 +153,14 @@ public class LanguageRealiser implements LanguageRealiserInterface {
NPPhraseSpec subjectAtt = this.nlgFactory.createNounPhrase();
attCord.addCoordinate(pair.getKey());
for(String s: (ArrayList<String>) pair.getValue()){
for (String s : (ArrayList<String>) pair.getValue()) {
attCord.addCoordinate(s);
}
for(String l: (ArrayList<String>) labels.get((String) pair.getKey())){
for (String l : (ArrayList<String>) labels.get((String) pair.getKey())) {
labCord.addCoordinate(l);
}
subjectAtt.setNoun(attCord);
subjectAtt.setDeterminer("its");
objectAtt.addComplement(labCord);
......@@ -169,20 +169,20 @@ public class LanguageRealiser implements LanguageRealiserInterface {
attClause.setObject(objectAtt);
attClause.setPlural(true);
object2.addCoordinate(attClause);
}
for(String a: atts){
for (String a : atts) {
SPhraseSpec attClause = this.nlgFactory.createClause();
CoordinatedPhraseElement labCord = this.nlgFactory.createCoordinatedPhrase();
labCord.setConjunction("or");
NPPhraseSpec objectAtt = this.nlgFactory.createNounPhrase();
NPPhraseSpec subjectAtt = this.nlgFactory.createNounPhrase("its " + a);
for(String l: (ArrayList<String>) labels.get(a)){
for (String l : (ArrayList<String>) labels.get(a)) {
labCord.addCoordinate(l);
}
objectAtt.addComplement(labCord);
attClause.setSubject(subjectAtt);
attClause.setVerb(verbAtt);
......@@ -210,6 +210,7 @@ public class LanguageRealiser implements LanguageRealiserInterface {
/**
* Constrúe a sección de explicación de solucións alternativas
*
* @return sección de solucións alternativas
*/
public DocumentElement buildAlternatives() {
......@@ -303,22 +304,21 @@ public class LanguageRealiser implements LanguageRealiserInterface {
DocumentElement list2 = this.nlgFactory.createList();
if (codes.size() > 0) {
for (Float a : codes) {
for (Consequent c : original.getConsequent().getMistakes()) {
if (c.getCode() != a) {
DocumentElement listElement = this.nlgFactory.createListItem();
SPhraseSpec alt = this.nlgFactory.createClause();
NPPhraseSpec subject2 = this.nlgFactory.createNounPhrase("it");
VPPhraseSpec verb2 = this.nlgFactory.createVerbPhrase("be");
verb2.addModifier(this.config.getPropertyAlt(c.getPercentage()).getValueTxt().toLowerCase() + " (" + c.getPercentage() + " %)");
NPPhraseSpec object2 = this.nlgFactory.createNounPhrase("to be type " + c.getText());
alt.setSubject(subject2);
alt.setVerb(verb2);
alt.setObject(object2);
listElement.addComponent(alt);
list2.addComponent(listElement);
}
for (Consequent c : original.getConsequent().getMistakes()) {
if (!codes.contains(c.getCode())) {
DocumentElement listElement = this.nlgFactory.createListItem();
SPhraseSpec alt = this.nlgFactory.createClause();
NPPhraseSpec subject2 = this.nlgFactory.createNounPhrase("it");
VPPhraseSpec verb2 = this.nlgFactory.createVerbPhrase("be");
verb2.addModifier(this.config.getPropertyAlt(c.getPercentage()).getValueTxt().toLowerCase() + " (" + c.getPercentage() + " %)");
NPPhraseSpec object2 = this.nlgFactory.createNounPhrase("to be type " + c.getText());
alt.setSubject(subject2);
alt.setVerb(verb2);
alt.setObject(object2);
listElement.addComponent(alt);
list2.addComponent(listElement);
}
}
} else {
for (Consequent c : original.getConsequent().getMistakes()) {
......@@ -347,6 +347,7 @@ public class LanguageRealiser implements LanguageRealiserInterface {
/**
* Construe a explicación completa da solución ao problema de clasificación
*
* @return explicación completa
* @throws IOException en caso de fallar a xeración do html coa solución
*/
......
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