public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,7 @@
<?flintstones.helper.data.xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.valuation.hesitant</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Hesitant</name>
<organization>
<name>Sinbad2</name>
</organization>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.valuation.hesitant</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362745</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,27 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hesitant
Bundle-SymbolicName: flintstones.valuation.hesitant;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Sinbad2
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.entity.valuation,
flintstones.model.valuation.service,
flintstones.valuation.twoTuple,
flintstones.valuation.linguistic,
flintstones.operator,
flintstones.domain.fuzzyset.unbalanced,
flintstones.operator.aggregation.owa,
flintstones.quantifiers.yager,
flintstones.helper.validator,
flintstones.domain.numeric.real,
flintstones.operator,
flintstones.helper.data.wxml,
org.eclipse.e4.core.contexts,
javax.inject,
flintstones.entity.domain,
org.eclipse.e4.core.di,
org.apache.commons.lang,
flintstones.entity.operator
Automatic-Module-Name: flintstones.valuation.hesitant
Export-Package: flintstones.valuation.hesitant
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.valuation">
<valuation
domain="flintstones.domain.hesitant"
uid="flintstones.valuation.hesitant"
implementation="flintstones.valuation.hesitant.HesitantValuation"
is_intermediate="false"
name="Hesitant">
</valuation>
</extension>
</plugin>
@@ -0,0 +1,37 @@
package flintstones.valuation.hesitant;
@SuppressWarnings("javadoc")
public enum EUnaryRelationType {
LowerThan(),
GreaterThan(),
AtLeast(),
AtMost();
private String _relationType;
private EUnaryRelationType() {}
EUnaryRelationType(String relationType) {
this._relationType = relationType;
}
public String getRelationType() {
return this._relationType;
}
public void setRelationType(String relationType) {
this._relationType = relationType;
}
public static EUnaryRelationType getEUnaryRelationType(String relationType) {
if(relationType.equals(LowerThan.toString())) {
return LowerThan;
} else if(relationType.equals(GreaterThan.toString())) {
return GreaterThan;
} else if(relationType.endsWith(AtLeast.toString())) {
return AtLeast;
} else {
return AtMost;
}
}
}
@@ -0,0 +1,709 @@
package flintstones.valuation.hesitant;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.nls.Translation;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
import flintstones.domain.fuzzyset.label.LabelSetLinguisticDomain;
import flintstones.domain.fuzzyset.semantic.IMembershipFunction;
import flintstones.domain.fuzzyset.unbalanced.Unbalanced;
import flintstones.entity.domain.Domain;
import flintstones.entity.extensionenum.ExtensionEnum;
import flintstones.entity.operator.AggregationOperator;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.wxml.WNode;
import flintstones.helper.validator.Validator;
import flintstones.operator.aggregation.owa.OWA;
import flintstones.operator.service.IOperatorService;
import flintstones.quantifiers.yager.YagerQuantifiers;
import flintstones.valuation.hesitant.messages.Messages;
import flintstones.valuation.twoTuple.TwoTupleValuation;
@SuppressWarnings("javadoc")
public class HesitantValuation extends Valuation {
@Inject
@Translation
private Messages messages;
@Inject
IOperatorService operatorService;
@Inject
IEclipseContext context;
public static final String ID = "flintstones.valuation.hesitant"; //$NON-NLS-1$
private EUnaryRelationType _unaryRelation;
private LabelLinguisticDomain _term;
private LabelLinguisticDomain _upperTerm;
private LabelLinguisticDomain _lowerTerm;
private LabelLinguisticDomain _label;
public enum FieldsFS3 implements ExtensionEnum {
hesitant, lowerTerm, lowerTermv, upperTerm, upperTermv, relation, unaryRelation, termv, term, labelv, label,
}
public enum Fields implements ExtensionEnum {
Hesitant, lowerTerm, lowerTermValuation, upperTerm, upperTermValuation, relation, unaryRelation, termValuation,
term, labelValuation, label,
}
public HesitantValuation() {
super();
this.setId(HesitantValuation.ID);
this._unaryRelation = null;
this._term = null;
this._upperTerm = null;
this._lowerTerm = null;
this._label = null;
}
public HesitantValuation(FuzzySet domain) {
this();
this.setDomain(domain);
}
@Override
public void setDomain(Domain domain) {
Validator.notNull(domain);
Validator.notIllegalElementType(domain,
new String[] { FuzzySet.class.toString(), Unbalanced.class.toString() });
Validator.notEmpty(((FuzzySet) domain).getLabelSet().getLabels().toArray());
this.domain = domain;
}
public void setLabel(int pos) {
LabelLinguisticDomain newLabel = ((FuzzySet) this.domain).getLabelSet().getLabel(pos);
Validator.notNull(newLabel);
this._label = newLabel;
this.disableRelations();
}
public void setLabel(String name) {
LabelLinguisticDomain newLabel = ((FuzzySet) this.domain).getLabelSet().getLabel(name);
Validator.notNull(newLabel);
this._label = newLabel;
this.disableRelations();
}
public void setLabel(LabelLinguisticDomain label) {
Validator.notNull(label);
if (((FuzzySet) this.domain).getLabelSet().containsLabel(label)) {
this._label = label;
this.disableRelations();
} else
throw new IllegalArgumentException(this.messages.Label_not_contains_in_domain);
}
public LabelLinguisticDomain getLabel() {
return this._label;
}
public void setUnaryRelation(EUnaryRelationType unaryRelation, LabelLinguisticDomain term) {
Validator.notNull(unaryRelation);
Validator.notNull(term);
if (!((FuzzySet) this.domain).getLabelSet().containsLabel(term))
throw new IllegalArgumentException(this.messages.Label_not_contains_in_domain);
this._unaryRelation = unaryRelation;
this._term = term;
this.disablePrimary();
this.disableBinary();
}
public EUnaryRelationType getUnaryRelation() {
return this._unaryRelation;
}
public LabelLinguisticDomain getTerm() {
return this._term;
}
public void setBinaryRelation(LabelLinguisticDomain lowerTerm, LabelLinguisticDomain upperTerm) {
Validator.notNull(lowerTerm);
Validator.notNull(upperTerm);
if (!((FuzzySet) this.domain).getLabelSet().containsLabel(lowerTerm))
throw new IllegalArgumentException(this.messages.Lower_term_not_contains_in_domai);
if (!((FuzzySet) this.domain).getLabelSet().containsLabel(upperTerm))
throw new IllegalArgumentException(this.messages.Upper_term_is_bigger_than_lower_term);
if (upperTerm.compareTo(lowerTerm) <= 0)
throw new IllegalArgumentException(this.messages.Upper_term_not_contains_in_domain);
this._lowerTerm = lowerTerm;
this._upperTerm = upperTerm;
this.disablePrimary();
this.disableUnary();
}
public void setBinaryRelation(int lowerTermPos, int upperTermPos) {
LabelLinguisticDomain lowerTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(lowerTermPos);
Validator.notNull(lowerTerm);
LabelLinguisticDomain upperTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(upperTermPos);
Validator.notNull(upperTerm);
if (upperTermPos <= lowerTermPos)
throw new IllegalArgumentException(this.messages.Upper_term_is_bigger_than_lower_term);
this._lowerTerm = lowerTerm;
this._upperTerm = upperTerm;
this.disablePrimary();
this.disableUnary();
}
public void setBinaryRelation(String lowerTermName, String upperTermName) {
LabelLinguisticDomain lowerTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(lowerTermName);
Validator.notNull(lowerTerm);
LabelLinguisticDomain upperTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(upperTermName);
Validator.notNull(upperTerm);
if (upperTerm.compareTo(lowerTerm) <= 0)
throw new IllegalArgumentException(this.messages.Upper_term_is_bigger_than_lower_term);
this._lowerTerm = lowerTerm;
this._upperTerm = upperTerm;
this.disablePrimary();
this.disableUnary();
}
public LabelLinguisticDomain getLowerTerm() {
return this._lowerTerm;
}
public LabelLinguisticDomain getUpperTerm() {
return this._upperTerm;
}
public boolean isPrimary() {
return (this._label != null);
}
public boolean isComposite() {
return (this.isUnary() || this.isBinary());
}
public boolean isUnary() {
return ((this._unaryRelation != null) && (this._term != null));
}
public boolean isBinary() {
return ((this._lowerTerm != null) && (this._upperTerm != null));
}
public TrapezoidalFunction calculateFuzzyEnvelope(FuzzySet domain) {
if (this.isPrimary())
return calculateFuzzyEnvelopePrimaryRelation();
else if (this.isUnary())
return calculateFuzzyEnvelopeUnaryRelation(domain);
else
return calculateFuzzyEnvelopeBinaryRelation(domain);
}
private TrapezoidalFunction calculateFuzzyEnvelopePrimaryRelation() {
double a, b, c, d;
IMembershipFunction semantic = this.getLabel().getSemantic();
a = semantic.getCoverage().getMin();
b = semantic.getCenter().getMin();
c = semantic.getCenter().getMax();
d = semantic.getCoverage().getMax();
TrapezoidalFunction tp = new TrapezoidalFunction();
tp.setLimits(new double[] { a, b, c, d });
return tp;
}
private TrapezoidalFunction calculateFuzzyEnvelopeUnaryRelation(FuzzySet domain) {
double a, b, c, d;
int g = domain.getLabelSet().getCardinality();
Boolean lower = null;
switch (this.getUnaryRelation()) {
case LowerThan:
lower = Boolean.valueOf(true);
break;
case AtMost:
lower = Boolean.valueOf(true);
break;
default:
lower = Boolean.valueOf(false);
break;
}
List<Double> weights = computeOWAWeights(lower, g);
List<Valuation> valuations = getLabelsInExpression(this.getEnvelopeIndex()[0], this.getEnvelopeIndex()[1], domain);
Valuation aggregated = aggregateValuations(valuations, weights);
if (lower.booleanValue()) {
a = 0.0D;
b = 0.0D;
c = ((TwoTupleValuation) aggregated).calculateInverseDelta() / ((double) g - 1);
d = ((FuzzySet) this.getDomain()).getLabelSet().getLabel(this.getEnvelopeIndex()[1]).getSemantic().getCoverage().getMax();
} else {
a = ((FuzzySet) this.getDomain()).getLabelSet().getLabel(this.getEnvelopeIndex()[0]).getSemantic().getCoverage().getMin();
b = ((TwoTupleValuation) aggregated).calculateInverseDelta() / ((double) g - 1);
c = 1.0D;
d = 1.0D;
}
TrapezoidalFunction tp = new TrapezoidalFunction();
tp.setLimits(new double[] { a, b, c, d });
return tp;
}
private List<Double> computeOWAWeights(Boolean lower, int g) {
YagerQuantifiers.NumeredQuantificationType nqt = YagerQuantifiers.NumeredQuantificationType.FilevYager;
double[] auxWeights = YagerQuantifiers.QWeighted(nqt, g - 1, this.getEnvelopeIndex(), lower);
List<Double> weights = new LinkedList<>();
for (Double weight : auxWeights)
weights.add(weight);
return weights;
}
private List<Valuation> getLabelsInExpression(int initial_index, int final_index, FuzzySet domain) {
List<Valuation> valuations = new LinkedList<>();
for (int i = initial_index; i <= final_index; i++) {
TwoTupleValuation twoSome = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoSome.build(domain, domain.getLabelSet().getLabel(i));
valuations.add(twoSome);
}
return valuations;
}
private Valuation aggregateValuations(List<Valuation> valuations, List<Double> weights) {
AggregationOperator owa = this.operatorService.getAggregationOperator(OWA.ID, "flintstones.valuation.twoTuple");
Valuation aux = ((OWA) owa).aggregate(valuations, weights);
return aux;
}
private TrapezoidalFunction calculateFuzzyEnvelopeBinaryRelation(FuzzySet domain) {
double a, b, c, d;
int g = domain.getLabelSet().getCardinality();
int[] envelope = this.getEnvelopeIndex();
a = ((FuzzySet) this.getDomain()).getLabelSet().getLabel(envelope[0]).getSemantic().getCoverage().getMin();
d = ((FuzzySet) this.getDomain()).getLabelSet().getLabel(envelope[1]).getSemantic().getCoverage().getMax();
if (envelope[0] + 1 == envelope[1]) {
b = ((FuzzySet) this.getDomain()).getLabelSet().getLabel(envelope[0]).getSemantic().getCenter().getMin();
c = ((FuzzySet) this.getDomain()).getLabelSet().getLabel(envelope[1]).getSemantic().getCenter().getMax();
} else {
int sum = envelope[1] + envelope[0];
int top;
if (sum % 2 == 0)
top = sum / 2;
else
top = (sum - 1) / 2;
List<Double> weights = computeOWAWeights(null, g);
List<Valuation> valuations = getLabelsInExpression(envelope[0], top, domain);
Valuation aggregated = aggregateValuations(valuations, weights);
b = ((TwoTupleValuation) aggregated).calculateInverseDelta() / ((double) g - 1);
c = 2D * domain.getLabelSet().getLabel(top).getSemantic().getCenter().getMin() - b;
}
TrapezoidalFunction tp = new TrapezoidalFunction();
tp.setLimits(new double[] { a, b, c, d });
return tp;
}
public LabelLinguisticDomain[] getEnvelope() {
LabelLinguisticDomain[] result = new LabelLinguisticDomain[2];
int pos, cardinality;
if (this.isPrimary()) {
result[0] = this._label;
result[1] = this._label;
} else if (this.isUnary())
switch (this._unaryRelation) {
// TODO fallo si ponemos LowerThan y la primera etiqueta (se sale del rango)
case LowerThan:
pos = ((FuzzySet) this.domain).getLabelSet().getPos(this._term) - 1;
if (pos == -1)
pos = 0;
result[0] = ((FuzzySet) this.domain).getLabelSet().getLabel(0);
result[1] = ((FuzzySet) this.domain).getLabelSet().getLabel(pos);
break;
case GreaterThan:
cardinality = ((FuzzySet) this.domain).getLabelSet().getCardinality();
pos = ((FuzzySet) this.domain).getLabelSet().getPos(this._term) + 1;
result[0] = ((FuzzySet) this.domain).getLabelSet().getLabel(pos);
result[1] = ((FuzzySet) this.domain).getLabelSet().getLabel(cardinality - 1);
break;
case AtLeast:
cardinality = ((FuzzySet) this.domain).getLabelSet().getCardinality();
result[0] = this._term;
result[1] = ((FuzzySet) this.domain).getLabelSet().getLabel(cardinality - 1);
break;
case AtMost:
result[0] = ((FuzzySet) this.domain).getLabelSet().getLabel(0);
result[1] = this._term;
break;
default:
result = null;
}
else if (this.isBinary()) {
result[0] = this._lowerTerm;
result[1] = this._upperTerm;
} else
result = null;
return result;
}
public int[] getEnvelopeIndex() {
int[] result = null;
LabelLinguisticDomain[] envelope = this.getEnvelope();
if (envelope != null) {
result = new int[2];
result[0] = ((FuzzySet) this.domain).getLabelSet().getPos(envelope[0]);
result[1] = ((FuzzySet) this.domain).getLabelSet().getPos(envelope[1]);
}
return result;
}
@Override
public String toString() {
if (this.isPrimary())
return (this._label + this.messages.in + this.domain.toString());
else if (this.isUnary())
return (this._unaryRelation.toString() + " " + this._term + this.messages.in + this.domain.toString()); //$NON-NLS-1$
else if (this.isBinary())
return (this.messages.between + this._lowerTerm + this.messages.and + this._upperTerm + this.messages.in
+ this.domain.toString());
else
return ""; //$NON-NLS-1$
}
@Override
public Valuation negateValuation() {
return null;
}
@Override
public int hashCode() {
if (this._unaryRelation != null)
return new HashCodeBuilder(17, 31).append(this._label).append(this.domain)
.append(this._unaryRelation.toString()).append(this._term).append(this._lowerTerm)
.append(this._upperTerm).toHashCode();
return new HashCodeBuilder(17, 31).append(this._label).append(this.domain).append("") //$NON-NLS-1$
.append(this._term).append(this._lowerTerm).append(this._upperTerm).toHashCode();
}
@Override
public int compareTo(Valuation other) {
Validator.notNull(other);
Validator.notIllegalElementType(other, new String[] { HesitantValuation.class.toString() });
if (this.domain.equals(other.getDomain())) {
int[] tEnvelopeIndex = this.getEnvelopeIndex();
int[] oEnvelopeIndex = ((HesitantValuation) other).getEnvelopeIndex();
double tc = (tEnvelopeIndex[1] + tEnvelopeIndex[0]) / 2d;
double tw = (tEnvelopeIndex[1] - tEnvelopeIndex[0]) / 2d;
double oc = (oEnvelopeIndex[1] + oEnvelopeIndex[0]) / 2d;
double ow = (oEnvelopeIndex[1] - oEnvelopeIndex[0]) / 2d;
double acceptability;
if ((tw + ow) == 0)
if (tc == oc)
return 0;
else if (tc > oc)
return 1;
else
return -1;
acceptability = (tc - oc) / (tw + ow);
double limit = 0.25;
if ((acceptability <= limit) && (acceptability >= -limit))
return 0;
else if (acceptability > limit)
return 1;
else
return -1;
}
throw new IllegalArgumentException(this.messages.different_domains);
}
@Override
public String changeFormatValuationToString() {
if (this.isPrimary())
return this._label.getName();
else if (this.isUnary()) {
String aux = this.getUnaryRelation().toString();
String[] splitUpper = aux.split("(?=\\p{Lu})");
aux = splitUpper[0] + " " + splitUpper[1].toLowerCase();
return aux + " " + this.getTerm() //$NON-NLS-1$
.getName();
} else
return this.messages.between + " " + this.getLowerTerm() //$NON-NLS-1$
.getName() + " " + this.messages.and + " " //$NON-NLS-1$ //$NON-NLS-2$
+ this.getUpperTerm().getName();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (obj.getClass() != this.getClass())
return false;
final HesitantValuation other = (HesitantValuation) obj;
return new EqualsBuilder().append(this._label, other._label).append(this.domain, other.domain)
.append(this._unaryRelation, other._unaryRelation).append(this._term, other._term)
.append(this._lowerTerm, other._lowerTerm).append(this._upperTerm, other._upperTerm).isEquals();
}
@Override
public Object clone() {
Object result = null;
result = super.clone();
return result;
}
private void disablePrimary() {
this._label = null;
}
private void disableRelations() {
this.disableUnary();
this.disableBinary();
}
private void disableUnary() {
this._unaryRelation = null;
this._term = null;
}
private void disableBinary() {
this._lowerTerm = null;
this._upperTerm = null;
}
@Override
public void write(XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement(Fields.Hesitant.toString());
if (this._label != null)
this.writeLabel(writer);
if (this._term != null) {
this.writeTerm(writer);
this.writeRelation(writer);
}
if (this._upperTerm != null)
this.writeUpperTerm(writer);
if (this._lowerTerm != null)
this.writeLowerTerm(writer);
writer.writeEndElement();
}
private void writeLowerTerm(XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement(Fields.lowerTermValuation.toString());
writer.writeAttribute(Fields.lowerTerm.toString(), this._lowerTerm.getName());
this._lowerTerm.write(writer);
writer.writeEndElement();
}
private void writeUpperTerm(XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement(Fields.upperTermValuation.toString());
writer.writeAttribute(Fields.upperTerm.toString(), this._upperTerm.getName());
this._upperTerm.write(writer);
writer.writeEndElement();
}
private void writeRelation(XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement(Fields.relation.toString());
writer.writeAttribute(Fields.unaryRelation.toString(), this._unaryRelation.getRelationType());
writer.writeEndElement();
}
private void writeTerm(XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement(Fields.termValuation.toString());
writer.writeAttribute(Fields.term.toString(), this._term.getName());
this._term.write(writer);
writer.writeEndElement();
}
private void writeLabel(XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement(Fields.labelValuation.toString());
writer.writeAttribute(Fields.label.toString(), this._label.getName());
this._label.write(writer);
writer.writeEndElement();
}
@Override
public void read(WNode node) {
if (node.getVersion().equals("3.0")) //$NON-NLS-1$
this.readFS3(node);
else
this.readFS4(node);
}
private void readFS3(WNode node) {
WNode nnode = node.getFirst(FieldsFS3.hesitant);
List<WNode> nodes = nnode.getChildren();
for (WNode item : nodes) {
String pseudoType = item.getName();
if (pseudoType.equals(FieldsFS3.labelv.toString()))
this.readLabelV(item);
else if (pseudoType.equals(FieldsFS3.termv.toString()))
this.readTermV(item);
else if (pseudoType.equals(FieldsFS3.relation.toString()))
this.readRelation(item);
else if (pseudoType.equals(FieldsFS3.upperTermv.toString()))
this.readUpperTermV(item);
else if (pseudoType.equals(FieldsFS3.lowerTermv.toString()))
this.readLowerTermV(item);
else
throw new Error("Implementar un read" + pseudoType); //$NON-NLS-1$
}
}
private void readFS4(WNode node) {
WNode nnode = node.getFirst(Fields.Hesitant);
List<WNode> nodes = nnode.getChildren();
for (WNode item : nodes) {
String pseudoType = item.getName();
if (pseudoType.equals(Fields.labelValuation.toString()))
this.readLabelV(item);
else if (pseudoType.equals(Fields.termValuation.toString()))
this.readTermV(item);
else if (pseudoType.equals(Fields.relation.toString()))
this.readRelation(item);
else if (pseudoType.equals(Fields.upperTermValuation.toString()))
this.readUpperTermV(item);
else if (pseudoType.equals(Fields.lowerTermValuation.toString()))
this.readLowerTermV(item);
else
throw new Error("Implementar un read" + pseudoType); //$NON-NLS-1$
}
}
private void readLabelV(WNode node) {
String name = node.getAttribute("label"); //$NON-NLS-1$
this._label = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context);
this._label.setName(name);
this._label.read(node);
}
private void readTermV(WNode node) {
String name = node.getAttribute("term"); //$NON-NLS-1$
this._term = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context);
this._term.setName(name);
this._term.read(node);
}
private void readUpperTermV(WNode node) {
String name = node.getAttribute("upperTerm"); //$NON-NLS-1$
this._upperTerm = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context);
this._upperTerm.setName(name);
this._upperTerm.read(node);
}
private void readLowerTermV(WNode node) {
String name = node.getAttribute("lowerTerm"); //$NON-NLS-1$
this._lowerTerm = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context);
this._lowerTerm.setName(name);
this._lowerTerm.read(node);
}
private void readRelation(WNode node) {
String unaryRelation = node.getAttribute("unaryRelation"); //$NON-NLS-1$
if (unaryRelation.contains(EUnaryRelationType.GreaterThan.toString()))
this._unaryRelation = EUnaryRelationType.GreaterThan;
else if (unaryRelation.contains(EUnaryRelationType.LowerThan.toString()))
this._unaryRelation = EUnaryRelationType.LowerThan;
else if (unaryRelation.contains(EUnaryRelationType.AtLeast.toString()))
this._unaryRelation = EUnaryRelationType.AtLeast;
else if (unaryRelation.contains(EUnaryRelationType.AtMost.toString()))
this._unaryRelation = EUnaryRelationType.AtMost;
else
throw new Error("Revisar " + unaryRelation); //$NON-NLS-1$
}
@Override
public void initFromString(String value) {
LabelSetLinguisticDomain labelSet = ((FuzzySet) this.domain).getLabelSet();
if(labelSet.containsLabel(value)) //Primary relation
setLabel(value);
else if(value.contains("bt") || value.contains("btw") || value.contains("between")) { //Binary relation
String[] expression_terms = value.split(" ");
String lowerTermName = expression_terms[1];
String upperTermName = expression_terms[3];
setBinaryRelation(lowerTermName, upperTermName);
} else {
String[] expression_terms = value.split(" ");
String term = expression_terms[2];
if(value.contains("greater"))
setUnaryRelation(EUnaryRelationType.GreaterThan, labelSet.getLabel(term));
else if(value.contains("lower"))
setUnaryRelation(EUnaryRelationType.LowerThan, labelSet.getLabel(term));
else if(value.contains("least"))
setUnaryRelation(EUnaryRelationType.AtLeast, labelSet.getLabel(term));
else
setUnaryRelation(EUnaryRelationType.AtMost, labelSet.getLabel(term));
}
}
}
@@ -0,0 +1,19 @@
// This file has been auto-generated
package flintstones.valuation.hesitant.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
@SuppressWarnings("javadoc")
public class Messages {
public String and;
public String between;
public String different_domains;
public String in;
public String Label_not_contains_in_domain;
public String Lower_term_not_contains_in_domai;
public String Upper_term_is_bigger_than_lower_term;
public String Upper_term_not_contains_in_domain;
}
@@ -0,0 +1,8 @@
and=and
between=Between
different_domains=Different domains
in=in
Label_not_contains_in_domain=Label not contained in domain.
Lower_term_not_contains_in_domai=Lower term not contained in domain.
Upper_term_is_bigger_than_lower_term=Lower term is bigger than upper term.
Upper_term_not_contains_in_domain=Upper term not contained in domain.
@@ -0,0 +1,8 @@
and=y
between=Entre
different_domains=Diferentes dominios
in=in
Label_not_contains_in_domain=Etiqueta no contenida en el dominio.
Lower_term_not_contains_in_domai=Término inferior no contenido en el dominio.
Upper_term_is_bigger_than_lower_term=El término superior no puede ser menor que el término inferior.
Upper_term_not_contains_in_domain=Término superior no contenido en el dominio.