use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.
the class ConjunctiveQueryTest method fullInstantiatedQueryFalseTest.
/**
* full instantiated query which is false
*/
@Theory
public void fullInstantiatedQueryFalseTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b), <P>(b,c), <Q>(c,a)."));
ConjunctiveQuery query = DlgpParser.parseQuery("? :- <P>(c,c).");
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 variableFusionTest.
public void variableFusionTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b),<Q>(b,b)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y) :- <P>(a,X),<Q>(X,Y),<Q>(Y,X).");
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("b"));
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 noAnswerQueryTest2.
/**
* Test a query without answer
*/
@Theory
public void noAnswerQueryTest2(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
ConjunctiveQuery query = DlgpParser.parseQuery("?(Y,X) :- <P>(Y,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 queryAtomsWithoutNeighborsInForwardChecking2Test.
@Theory
public void queryAtomsWithoutNeighborsInForwardChecking2Test(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b),<P>(a,c),<Q>(b,b)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y) :- <P>(X,Y),<Q>(Y,Y).");
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 booleanQueryTest.
/**
* Test a boolean query
*/
@Theory
public void booleanQueryTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
try {
store.addAll(DlgpParser.parseAtomSet("<P>(a,b).<P>(b,c).<Q>(a,c).<Q>(d,c)."));
InMemoryAtomSet queryAtomSet = new LinkedListAtomSet();
queryAtomSet.add(DlgpParser.parseAtom("<Q>(a,c)."));
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(queryAtomSet);
CloseableIterator<Substitution> subReader;
Substitution sub;
subReader = h.execute(query, store);
Assert.assertTrue(subReader.hasNext());
sub = subReader.next();
Assert.assertEquals(0, sub.getTerms().size());
Assert.assertFalse(subReader.hasNext());
subReader.close();
} catch (Exception e) {
Assert.assertTrue(e.getMessage(), false);
}
}
Aggregations