use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class IDConditionImpl method homomorphism.
@Override
public Substitution homomorphism(List<Term> head, List<Term> to) {
if (!checkBody(to)) {
return null;
}
Pair<List<Term>, Substitution> ret = this.generateBody(head);
if (ret == null) {
return null;
}
Substitution s = ret.getRight();
Substitution homo = DefaultSubstitutionFactory.instance().createSubstitution();
List<Term> generatedBody = ret.getLeft();
// check for a simple homomorphism from generated body into 'to'
Iterator<Term> itFrom = generatedBody.iterator();
Iterator<Term> itTo = to.iterator();
while (itFrom.hasNext() && itTo.hasNext()) {
Term termFrom = itFrom.next();
Term termTo = itTo.next();
if (termFrom.isConstant()) {
if (!termFrom.equals(termTo)) {
return null;
}
} else {
if (!homo.put((Variable) termFrom, termTo)) {
return null;
}
}
}
if (itFrom.hasNext() || itTo.hasNext()) {
throw new Error("Wrong term number");
}
// homo
for (Variable t : s.getTerms()) {
homo.put(t, homo.createImageOf(s.createImageOf(t)));
}
return homo;
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class SubstitutionTest method aggregateTest1.
@Theory
public void aggregateTest1(Substitution s1, Substitution s2) {
s1.put(Y, A);
s1.put(Z, A);
s2.put(X, Y);
s2.put(Y, Z);
Substitution aggregation = s1.aggregate(s2);
Assert.assertNotNull(aggregation);
Assert.assertEquals(A, aggregation.createImageOf(X));
Assert.assertEquals(A, aggregation.createImageOf(Y));
Assert.assertEquals(A, aggregation.createImageOf(Z));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class SubstitutionTest method aggregateImpossibleTest2.
@Theory
public void aggregateImpossibleTest2(Substitution s1, Substitution s2) {
s1.put(X, Z);
s1.put(Y, Z);
s2.put(X, A);
s2.put(Y, B);
Substitution aggregation = s1.aggregate(s2);
Assert.assertNull(aggregation);
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class SubstitutionTest method compositionTest1.
@Theory
public void compositionTest1(Substitution s1, Substitution s2) {
s1.put(X, Y);
s1.put(S, T);
s2.put(Y, Z);
s2.put(U, V);
Substitution comp = s2.compose(s1);
System.out.println(comp);
Assert.assertEquals(Z, comp.createImageOf(X));
Assert.assertEquals(Z, comp.createImageOf(Y));
Assert.assertEquals(Z, comp.createImageOf(Z));
Assert.assertEquals(T, comp.createImageOf(S));
Assert.assertEquals(V, comp.createImageOf(U));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class SubstitutionTest method aggregateImpossibleTest1.
@Theory
public void aggregateImpossibleTest1(Substitution s1, Substitution s2) {
s1.put(X, A);
s2.put(X, B);
Substitution aggregation = s1.aggregate(s2);
Assert.assertNull(aggregation);
}
Aggregations