public code v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?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.method.common.model.retranslation</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Retranslation</name>
|
||||
<organization>
|
||||
<name>Sinbad2</name>
|
||||
</organization>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.method.common.model.retranslation</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>1779484362634</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>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
+7
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,17 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Retranslation
|
||||
Bundle-SymbolicName: flintstones.method.common.model.retranslation
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: Sinbad2
|
||||
Automatic-Module-Name: flintstones.method.common.retranslation
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.entity.domain,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.entity.valuation,
|
||||
flintstones.valuation.twoTuple,
|
||||
flintstones.domain.fuzzyset.unbalanced,
|
||||
org.eclipse.e4.core.contexts,
|
||||
javax.inject,
|
||||
org.eclipse.e4.core.di
|
||||
Export-Package: flintstones.method.common.model.retranslation
|
||||
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
package flintstones.method.common.model.retranslation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
import flintstones.domain.fuzzyset.unbalanced.Unbalanced;
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.problemelement.entities.Alternative;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.valuation.twoTuple.TwoTupleValuation;
|
||||
|
||||
public class RetranslationModel {
|
||||
|
||||
private static final int LEFT = 0;
|
||||
private static final int RIGHT = 1;
|
||||
|
||||
private List<Object[]> retranslationDomains = new LinkedList<>();
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
public RetranslationModel() {}
|
||||
|
||||
public List<Object[]> getRetranslationDomains() {
|
||||
return retranslationDomains;
|
||||
}
|
||||
|
||||
public void setRetranslationDomains(List<Object[]> retranslationDomains) {
|
||||
this.retranslationDomains = retranslationDomains;
|
||||
}
|
||||
|
||||
public String[] getRetranslationDomainsIds() {
|
||||
String[] ids = new String[retranslationDomains.size()];
|
||||
for(int i = 0; i < ids.length; ++i)
|
||||
ids[i] = (String) retranslationDomains.get(i)[1];
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
public Domain getRetranslationDomain(String id) {
|
||||
for(int i = 0; i < retranslationDomains.size(); ++i)
|
||||
if(retranslationDomains.get(i)[1].equals(id))
|
||||
return (Domain) retranslationDomains.get(i)[2];
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<Alternative, Valuation> retranslate(Map<Alternative, Valuation> aggregationResults, FuzzySet retranslationDomain) {
|
||||
Map<Alternative, Valuation> retranslationResults = new HashMap<>();
|
||||
|
||||
Valuation valuation, auxValuation = null;
|
||||
for (ProblemElement alternative : aggregationResults.keySet()) {
|
||||
valuation = aggregationResults.get(alternative);
|
||||
if (retranslationDomain instanceof Unbalanced) {
|
||||
auxValuation = transformUnbalancedValuation((TwoTupleValuation) valuation, (Unbalanced) retranslationDomain);
|
||||
} else {
|
||||
auxValuation = ((TwoTupleValuation) valuation).transform(retranslationDomain);
|
||||
}
|
||||
retranslationResults.put((Alternative)alternative, auxValuation);
|
||||
}
|
||||
|
||||
return retranslationResults;
|
||||
}
|
||||
|
||||
private Valuation transformUnbalancedValuation(TwoTupleValuation result, Unbalanced retranslationDomain) {
|
||||
|
||||
Map<Integer, Integer> domains = null;
|
||||
|
||||
int testPos, domainSize;
|
||||
boolean find = false;
|
||||
Integer labelPos;
|
||||
|
||||
Unbalanced domainTest;
|
||||
Unbalanced[] auxDomains;
|
||||
|
||||
LabelLinguisticDomain labelTest = null;
|
||||
LabelLinguisticDomain[] labels;
|
||||
|
||||
double[] alphas = null;
|
||||
|
||||
int size;
|
||||
int[] sizes = null;
|
||||
|
||||
int[] lh = retranslationDomain.getLh();
|
||||
Map<Integer, Unbalanced> lhDomains = new HashMap<Integer, Unbalanced>();
|
||||
|
||||
for (int i = 0; i < lh.length; i++) {
|
||||
lhDomains.put(lh[i], generateDomain(lh[i]));
|
||||
}
|
||||
|
||||
LabelLinguisticDomain label = ((TwoTupleValuation) result).getLabel();
|
||||
double alpha = ((TwoTupleValuation) result).getAlpha();
|
||||
|
||||
int domainPos = lh.length - 1;
|
||||
do {
|
||||
domainSize = lh[domainPos];
|
||||
domainTest = lhDomains.get(domainSize);
|
||||
testPos = domainTest.getLabelSet().getPos(label);
|
||||
labelPos = retranslationDomain.labelPos(domainSize, testPos);
|
||||
|
||||
if (labelPos != null) {
|
||||
find = true;
|
||||
|
||||
labelTest = retranslationDomain.getLabelSet().getLabel(labelPos);
|
||||
domains = retranslationDomain.getLabel(labelPos);
|
||||
|
||||
size = domains.size();
|
||||
|
||||
auxDomains = new Unbalanced[size];
|
||||
labels = new LabelLinguisticDomain[size];
|
||||
sizes = new int[size];
|
||||
alphas = new double[size];
|
||||
|
||||
int i = 0;
|
||||
for (Integer auxSize : domains.keySet()) {
|
||||
auxDomains[i] = lhDomains.get(auxSize);
|
||||
labels[i] = auxDomains[i].getLabelSet().getLabel(domains.get(auxSize));
|
||||
sizes[i] = auxSize;
|
||||
if (labels[i] == label)
|
||||
alphas[i] = alpha;
|
||||
else
|
||||
alphas[i] = ((TwoTupleValuation) result).transform(auxDomains[i]).getAlpha();
|
||||
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
domainPos--;
|
||||
result = ((TwoTupleValuation) result).transform(lhDomains.get(lh[domainPos]));
|
||||
label = ((TwoTupleValuation) result).getLabel();
|
||||
alpha = ((TwoTupleValuation) result).getAlpha();
|
||||
}
|
||||
} while (!find);
|
||||
|
||||
if ((domains.size() == 1) || (alpha == 0)) {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain);
|
||||
} else {
|
||||
if (alpha > 0) {
|
||||
if (smallSide(labelTest) == RIGHT) {
|
||||
if (sizes[0] > sizes[1]) {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain);
|
||||
} else {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain);
|
||||
}
|
||||
} else {
|
||||
if (sizes[0] > sizes[1]) {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain);
|
||||
} else {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (smallSide(label) == RIGHT) {
|
||||
if (sizes[0] > sizes[1]) {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain);
|
||||
} else {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain);
|
||||
}
|
||||
} else {
|
||||
if (sizes[0] > sizes[1]) {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain);
|
||||
} else {
|
||||
result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Unbalanced generateDomain(int cardinality) {
|
||||
String[] labels = new String[cardinality];
|
||||
for (int i = 0; i < cardinality; i++) {
|
||||
labels[i] = Integer.toString(i);
|
||||
}
|
||||
|
||||
Unbalanced domain = ContextInjectionFactory.make(Unbalanced.class, context);
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
private Valuation transformToResultsDomain(LabelLinguisticDomain label, double alpha, Unbalanced unificationDomain) {
|
||||
TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context);
|
||||
result.build(unificationDomain, label, alpha);
|
||||
return result;
|
||||
}
|
||||
|
||||
private int smallSide(LabelLinguisticDomain l) {
|
||||
NumericRealDomain center = l.getSemantic().getCenter();
|
||||
NumericRealDomain coverage = l.getSemantic().getCoverage();
|
||||
|
||||
double left = center.getMin() - coverage.getMin();
|
||||
double right = coverage.getMax() - center.getMax();
|
||||
|
||||
if (left > right) {
|
||||
return RIGHT;
|
||||
} else {
|
||||
return LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user