Search in sources :

Example 91 with ConjunctiveQuery

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

Example 92 with ConjunctiveQuery

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

Example 93 with ConjunctiveQuery

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

Example 94 with ConjunctiveQuery

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

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