use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class AtomicQueryHomomorphism method execute.
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a, RulesCompilation rc) throws HomomorphismException {
try {
List<CloseableIterator<Substitution>> iteratorsList = new LinkedList<CloseableIterator<Substitution>>();
Atom atom = q.getAtomSet().iterator().next();
for (Pair<Atom, Substitution> im : rc.getRewritingOf(atom)) {
iteratorsList.add(new ConverterCloseableIterator<Atom, Substitution>(a.match(im.getLeft()), new Atom2SubstitutionConverter(im.getLeft(), q.getAnswerVariables(), im.getRight())));
}
return new CloseableIteratorAggregator<Substitution>(new CloseableIteratorAdapter<CloseableIterator<Substitution>>(iteratorsList.iterator()));
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class UnifierTest method mostGeneralTest1.
@Test
public void mostGeneralTest1() throws IteratorException {
Rule rule = DefaultRuleFactory.instance().create();
rule.getBody().add(TestUtils.pXY);
rule.getHead().add(TestUtils.qXY);
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
atomset.add(TestUtils.qUV);
CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
Assert.assertEquals(1, Iterators.count(unifiers));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class UnifierTest method unificationExistentialWithFrontier.
@Test
public void unificationExistentialWithFrontier() {
Rule rule = DefaultRuleFactory.instance().create();
rule.getBody().add(TestUtils.sX);
rule.getHead().add(TestUtils.pXY);
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
atomset.add(TestUtils.pUU);
CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
Assert.assertEquals(0, Iterators.count(unifiers));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class UnifierTest method pieceUnifierTest2.
@Test
public void pieceUnifierTest2() {
Rule rule = DefaultRuleFactory.instance().create();
rule.getBody().add(TestUtils.sX);
rule.getHead().add(TestUtils.pXB);
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
atomset.add(TestUtils.pAU);
CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
Assert.assertEquals(1, Iterators.count(unifiers));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class UnifierTest method example35MelanieThesis.
@Test
public void example35MelanieThesis() {
Rule rule = DefaultRuleFactory.instance().create();
rule.getBody().add(TestUtils.pXY);
rule.getHead().add(TestUtils.qXY);
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
atomset.add(TestUtils.qUV);
atomset.add(TestUtils.pVW);
atomset.add(TestUtils.qTW);
CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
Assert.assertEquals(2, Iterators.count(unifiers));
}
Aggregations