Search in sources :

Example 96 with ConjunctiveQuery

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());
}
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 97 with ConjunctiveQuery

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

Example 98 with ConjunctiveQuery

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

Example 99 with ConjunctiveQuery

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

Example 100 with ConjunctiveQuery

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));
}
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)

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