use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class ConjunctiveQueryTest method noAnswerQueryTest.
/**
* Test a query without answer
*/
@Theory
public void noAnswerQueryTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b),<P>(b,c),<Q>(c,a)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- <P>(c,X).");
CloseableIterator<Substitution> subReader;
subReader = h.execute(query, store);
Assert.assertFalse(subReader.hasNext());
subReader.close();
} catch (Exception e) {
Assert.assertTrue(e.getMessage(), false);
}
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class ConjunctiveQueryTest method booleanQueryWithoutAnswerTest.
/**
* Test a boolean query
*/
@Theory
public void booleanQueryWithoutAnswerTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
InMemoryAtomSet queryAtomSet = new LinkedListAtomSet();
queryAtomSet.add(DlgpParser.parseAtom("<Q>(a,c)."));
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(queryAtomSet);
CloseableIterator<Substitution> subReader;
subReader = h.execute(query, store);
Assert.assertFalse(subReader.hasNext());
subReader.close();
} catch (Exception e) {
Assert.assertTrue(e.getMessage(), false);
}
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class ConjunctiveQueryTest method queryAtomsWithoutNeighborsInForwardCheckingTest.
@Theory
public void queryAtomsWithoutNeighborsInForwardCheckingTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b).<P>(b,c)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y) :- <P>(X,Y),<P>(Y,c).");
CloseableIterator<Substitution> subReader;
Substitution sub;
subReader = h.execute(query, store);
Assert.assertTrue(subReader.hasNext());
sub = subReader.next();
Assert.assertEquals(2, sub.getTerms().size());
Assert.assertEquals(sub.createImageOf(DefaultTermFactory.instance().createVariable("X")), DefaultTermFactory.instance().createConstant("a"));
Assert.assertEquals(sub.createImageOf(DefaultTermFactory.instance().createVariable("Y")), DefaultTermFactory.instance().createConstant("b"));
Assert.assertFalse(subReader.hasNext());
subReader.close();
} catch (Exception e) {
Assert.assertTrue(e.getMessage(), false);
}
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class ConjunctiveQueryTest method existentialVariableInDataTest.
@Theory
public void existentialVariableInDataTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b)."));
Rule r = DlgpParser.parseRule("<Q>(X,Z) :- <P>(X,Y).");
LinkedList<Rule> rules = new LinkedList<Rule>();
rules.add(r);
StaticChase.executeChase(store, rules);
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- <Q>(X,Y), <P>(X,Z).");
CloseableIterator<Substitution> subReader;
Substitution sub;
subReader = h.execute(query, store);
Assert.assertTrue(subReader.hasNext());
sub = subReader.next();
Assert.assertEquals(3, sub.getTerms().size());
Assert.assertEquals(sub.createImageOf(DefaultTermFactory.instance().createVariable("X")), DefaultTermFactory.instance().createConstant("a"));
Assert.assertEquals(sub.createImageOf(DefaultTermFactory.instance().createVariable("Z")), DefaultTermFactory.instance().createConstant("b"));
Assert.assertFalse(subReader.hasNext());
subReader.close();
} catch (Exception e) {
Assert.assertTrue(e.getMessage(), false);
}
}
use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class ConjunctiveQueryTest method booleanQueryWithVariablesTest.
/**
* Test a boolean query with variables
*/
@Theory
public void booleanQueryWithVariablesTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b),<P>(d,e),<P>(e,c),<P>(f,d)."));
ConjunctiveQuery query = DlgpParser.parseQuery("? :- <P>(X,Y),<P>(Y,Z),<P>(Z,W).");
CloseableIterator<Substitution> subReader = h.execute(query, store);
Assert.assertTrue(subReader.hasNext());
Substitution sub = subReader.next();
Assert.assertEquals(0, sub.getTerms().size());
Assert.assertFalse(subReader.hasNext());
subReader.close();
} catch (Exception e) {
Assert.assertTrue(e.getMessage(), false);
}
}
Aggregations