use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class EqualityUtilsTest method testBottomQuery1.
@Test
public void testBottomQuery1() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- p(X,Y), a=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.ConjunctiveQuery in project graal by graphik-team.
the class EqualityUtilsTest method testQuery1.
@Test
public void testQuery1() throws HomomorphismException, IteratorException, AtomSetException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- b(X), Y=a.");
InMemoryAtomSet store = new DefaultInMemoryGraphStore();
store.addAll(DlgpParser.parseAtomSet("b(a),b(b)."));
BacktrackHomomorphism h = new BacktrackHomomorphism();
CloseableIterator<Substitution> results = h.execute(q, store);
while (results.hasNext()) {
results.next();
}
results.close();
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class EqualityUtilsTest method test4.
@Test
public void test4() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- p(X,Y), X=a, X=Y.");
Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(q);
q = pair.getLeft();
Substitution s = pair.getRight();
// check substitution minimality
Set<Variable> terms = new HashSet<Variable>(s.getTerms());
terms.remove(x);
terms.remove(y);
Assert.assertTrue(terms.isEmpty());
// check substitution completude
Assert.assertEquals(a, s.createImageOf(y));
Assert.assertEquals(a, s.createImageOf(y));
// 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(p, atom.getPredicate());
Assert.assertEquals(a, atom.getTerm(0));
Assert.assertEquals(a, atom.getTerm(1));
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class EqualityUtilsTest method testQuery2.
@Test
public void testQuery2() throws HomomorphismException, IteratorException, AtomSetException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- p(X,Y), X=Y.");
InMemoryAtomSet store = new DefaultInMemoryGraphStore();
store.addAll(DlgpParser.parseAtomSet("p(a,a),p(a,b),p(b,b)."));
BacktrackHomomorphism h = new BacktrackHomomorphism();
CloseableIterator<Substitution> results = h.execute(q, store);
while (results.hasNext()) {
results.next();
}
results.close();
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class DlgpParserTest method parseQueryWithStringLiteralInAns.
@Test
public void parseQueryWithStringLiteralInAns() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(\"string\",X) :- p(a,X).");
List<Term> ans = q.getAnswerVariables();
Assert.assertEquals(LSTRING, ans.get(0));
Assert.assertEquals(X, ans.get(1));
Atom a = q.getAtomSet().iterator().next();
Assert.assertEquals(A, a.getTerm(0));
Assert.assertEquals(X, a.getTerm(1));
}
Aggregations