use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class DlgpParserTest method parseQuery.
// /////////////////////////////////////////////////////////////////////////
// QUERY
// /////////////////////////////////////////////////////////////////////////
@Test
public void parseQuery() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X) :- p(a,X).");
Assert.assertEquals(X, q.getAnswerVariables().get(0));
Atom a = q.getAtomSet().iterator().next();
Assert.assertEquals(A, a.getTerm(0));
Assert.assertEquals(X, a.getTerm(1));
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class DlgpParserTest method parseBooleanQuery.
@Test
public void parseBooleanQuery() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("? :- p(a,X).");
Assert.assertTrue(q.getAnswerVariables().isEmpty());
Assert.assertTrue(q.isBoolean());
Atom a = q.getAtomSet().iterator().next();
Assert.assertEquals(A, a.getTerm(0));
Assert.assertEquals(X, a.getTerm(1));
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class DlgpParserTest method parseBooleanQuery2.
@Test
public void parseBooleanQuery2() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?() :- .");
Assert.assertTrue(q.getAnswerVariables().isEmpty());
Assert.assertTrue(q.isBoolean());
Assert.assertFalse(q.getAtomSet().iterator().hasNext());
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class EqualityUtilsTest method test3.
@Test
public void test3() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- p(X,Y), X=Y.");
Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(q);
q = pair.getLeft();
Substitution s = pair.getRight();
// check substitution
Set<Variable> terms = new HashSet<Variable>(s.getTerms());
terms.remove(x);
terms.remove(y);
Assert.assertTrue(terms.isEmpty());
Assert.assertEquals(s.createImageOf(x), s.createImageOf(y));
Assert.assertTrue(s.createImageOf(y).isVariable());
// check query ans part
Assert.assertEquals(1, q.getAnswerVariables().size());
Assert.assertEquals(s.createImageOf(x), q.getAnswerVariables().get(0));
// check query atomset
Assert.assertEquals(1, Iterators.count(q.getAtomSet().iterator()));
Atom atom = q.getAtomSet().iterator().next();
Assert.assertEquals(p, atom.getPredicate());
Assert.assertEquals(s.createImageOf(x), atom.getTerm(0));
Assert.assertEquals(s.createImageOf(x), atom.getTerm(1));
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class EqualityUtilsTest method test2.
@Test
public void test2() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- p(X,Y), 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) :- p(X,a)."), q);
}
Aggregations