use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class EqualityUtilsTest method test1.
@Test
public void test1() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- b(X), Y=a.");
Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(q);
q = pair.getLeft();
Substitution s = pair.getRight();
// check substitution
Assert.assertEquals(1, s.getTerms().size());
Assert.assertEquals(a, s.createImageOf(y));
// check query
Assert.assertEquals(DlgpParser.parseQuery("?(X) :- b(X)."), q);
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class EqualityUtilsTest method testBottomQuery2.
@Test
public void testBottomQuery2() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- p(X,Y), X=a, X=Y, Y=b.");
Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(q);
q = pair.getLeft();
Substitution s = pair.getRight();
// check substitution minimality
Assert.assertTrue(s.getTerms().isEmpty());
// check query ans part
Assert.assertEquals(0, q.getAnswerVariables().size());
// check query atomset
Assert.assertEquals(1, Iterators.count(q.getAtomSet().iterator()));
Atom atom = q.getAtomSet().iterator().next();
Assert.assertEquals(Predicate.BOTTOM, atom.getPredicate());
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class ForwardCheckingTest method FCTest2.
@Test
public void FCTest2() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
Profiler profiler = new CPUTimeProfiler();
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), p(a,c), q(a,a), q(a,b)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Z), q(Y,Z).");
Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
h.setProfiler(profiler);
CloseableIterator<Substitution> results = h.execute(query, data);
while (results.hasNext()) {
results.next();
}
results.close();
Assert.assertEquals(7, profiler.get("#calls"));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class ForwardCheckingTest method NFC2Test.
@Test
public void NFC2Test() throws HomomorphismException, IteratorException, ParseException {
Profiler profiler = new CPUTimeProfiler();
Predicate[] predicates = { new Predicate("p2", 2), new Predicate("p3", 3), new Predicate("p4", 4) };
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
TestUtil.addNAtoms(data, 13, predicates, 5, new Random(0));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X5,X6,X7,X8) :- p4(X5,X6,X7,X8), p4(X8,X7,X6,X5), p3(X7,X8,X9), p2(X7,X11).");
Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
h.setProfiler(profiler);
CloseableIterator<Substitution> results = h.execute(query, data);
while (results.hasNext()) {
results.next();
}
results.close();
Assert.assertEquals(1, profiler.get("#calls"));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class ForwardCheckingTest method test1.
@Test
public void test1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), p(X,Z).");
Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
CloseableIterator<Substitution> results = h.execute(query, data);
while (results.hasNext()) {
results.next();
}
results.close();
}
Aggregations