use of fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts in project graal by graphik-team.
the class HomomorphismTest method test4.
@Test
public void test4() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b)."));
Variable x = DefaultTermFactory.instance().createVariable("X");
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(a,X)."));
positivePart.iterator().next().setTerm(1, x);
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(X)."));
negatedPart.iterator().next().setTerm(0, x);
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, Collections.singletonList(negatedPart));
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertFalse(res.hasNext());
res.close();
}
use of fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts in project graal by graphik-team.
the class HomomorphismTest method test3.
@Test
public void test3() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b)."));
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(a,b)."));
LinkedList<InMemoryAtomSet> parts = new LinkedList<InMemoryAtomSet>();
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(a)."));
parts.add(negatedPart);
negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(b)."));
parts.add(negatedPart);
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, parts);
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertFalse(res.hasNext());
res.close();
}
use of fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts in project graal by graphik-team.
the class HomomorphismTest method test6Compilation.
@Test
public void test6Compilation() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("r(X,Y) :- s(X,Y)."));
RulesCompilation comp = new IDCompilation();
comp.compile(rules.iterator());
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b), p(a,c), s(a,d), q(d), s(a,e)."));
Variable y = DefaultTermFactory.instance().createVariable("Y");
Variable z = DefaultTermFactory.instance().createVariable("Z");
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(X,Y),r(X,Z)."));
CloseableIteratorWithoutException<Atom> it = positivePart.iterator();
it.next().setTerm(1, y);
it.next().setTerm(1, z);
LinkedList<InMemoryAtomSet> parts = new LinkedList<InMemoryAtomSet>();
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(Y)."));
negatedPart.iterator().next().setTerm(0, y);
parts.add(negatedPart);
negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(Z)."));
negatedPart.iterator().next().setTerm(0, z);
parts.add(negatedPart);
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, parts);
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data, comp);
Assert.assertTrue(res.hasNext());
res.next();
Assert.assertFalse(res.hasNext());
res.close();
}
use of fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts in project graal by graphik-team.
the class HomomorphismTest method test6.
@Test
public void test6() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b), p(a,c), r(a,d), q(d), r(a,e)."));
Variable y = DefaultTermFactory.instance().createVariable("Y");
Variable z = DefaultTermFactory.instance().createVariable("Z");
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(X,Y),r(X,Z)."));
CloseableIteratorWithoutException<Atom> it = positivePart.iterator();
it.next().setTerm(1, y);
it.next().setTerm(1, z);
LinkedList<InMemoryAtomSet> parts = new LinkedList<InMemoryAtomSet>();
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(Y)."));
negatedPart.iterator().next().setTerm(0, y);
parts.add(negatedPart);
negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(Z)."));
negatedPart.iterator().next().setTerm(0, z);
parts.add(negatedPart);
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, parts);
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertTrue(res.hasNext());
res.next();
Assert.assertFalse(res.hasNext());
res.close();
}
use of fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts in project graal by graphik-team.
the class HomomorphismTest method test2.
@Test
public void test2() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b)."));
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(a,b)."));
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(b)."));
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, Collections.singletonList(negatedPart));
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertFalse(res.hasNext());
res.close();
}
Aggregations