Search in sources :

Example 6 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class DlgpParserTest method parseQueryWithIntegerLiteralInAns.

@Test
public void parseQueryWithIntegerLiteralInAns() throws ParseException {
    ConjunctiveQuery q = DlgpParser.parseQuery("?(1,X) :- p(a,X).");
    List<Term> ans = q.getAnswerVariables();
    Assert.assertEquals(L1, 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));
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 7 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class DlgpParserTest method parseQueryWithConstantInAns.

@Test
public void parseQueryWithConstantInAns() throws ParseException {
    ConjunctiveQuery q = DlgpParser.parseQuery("?(b,X) :- p(a,X).");
    List<Term> ans = q.getAnswerVariables();
    Assert.assertEquals(B, 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));
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 8 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class DlgpParserTest method parseQueryWithBooleanLiteralInAns.

@Test
public void parseQueryWithBooleanLiteralInAns() throws ParseException {
    ConjunctiveQuery q = DlgpParser.parseQuery("?(true,X) :- p(a,X).");
    List<Term> ans = q.getAnswerVariables();
    Assert.assertEquals(LTRUE, 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));
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 9 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery 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());
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 10 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery 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);
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Aggregations

ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)113 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)58 Theory (org.junit.experimental.theories.Theory)57 Atom (fr.lirmm.graphik.graal.api.core.Atom)34 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)29 Test (org.junit.Test)29 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)23 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)22 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)22 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)19 DefaultConjunctiveQuery (fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery)18 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)14 Term (fr.lirmm.graphik.graal.api.core.Term)14 PureRewriter (fr.lirmm.graphik.graal.backward_chaining.pure.PureRewriter)14 LinkedList (java.util.LinkedList)13 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)12 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)11 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)10 TripleStore (fr.lirmm.graphik.graal.api.store.TripleStore)9 RulesCompilation (fr.lirmm.graphik.graal.api.core.RulesCompilation)7