use of fr.lirmm.graphik.graal.api.store.TripleStore in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method backtrackHomomorphismBootstrapperTest2.
@Theory
public void backtrackHomomorphismBootstrapperTest2(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeFalse(store instanceof TripleStore);
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.addAll(DlgpParser.parseAtomSet("<P>(b,a)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X,Y)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- <Q>(X,a).");
CloseableIterator<Substitution> subReader;
Substitution sub;
subReader = h.execute(query, store, comp);
Assert.assertTrue(subReader.hasNext());
sub = subReader.next();
Assert.assertEquals(DefaultTermFactory.instance().createConstant("b"), sub.createImageOf(DefaultTermFactory.instance().createVariable("X")));
Assert.assertFalse(subReader.hasNext());
subReader.close();
}
use of fr.lirmm.graphik.graal.api.store.TripleStore in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method backtrackHomomorphismBootstrapperTest1.
@Theory
public void backtrackHomomorphismBootstrapperTest1(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeFalse(store instanceof TripleStore);
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.addAll(DlgpParser.parseAtomSet("<P>(b,a)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X,Y)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- <Q>(b,X).");
CloseableIterator<Substitution> subReader;
Substitution sub;
subReader = h.execute(query, store, comp);
Assert.assertTrue(subReader.hasNext());
sub = subReader.next();
Assert.assertEquals(DefaultTermFactory.instance().createConstant("a"), sub.createImageOf(DefaultTermFactory.instance().createVariable("X")));
Assert.assertFalse(subReader.hasNext());
subReader.close();
}
use of fr.lirmm.graphik.graal.api.store.TripleStore in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method issueWithAtom2SubstitutionConverter.
@Theory
public void issueWithAtom2SubstitutionConverter(RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeFalse(store instanceof TripleStore);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = AtomicQueryHomomorphism.instance();
store.addAll(DlgpParser.parseAtomSet("<P>(a,a)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X,Y,X) :- <P>(X,Y)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- <Q>(X,Y,Y).");
CloseableIterator<Substitution> results = h.execute(new DefaultConjunctiveQuery(query), store, comp);
Assert.assertTrue(results.hasNext());
results.close();
query = DlgpParser.parseQuery("?(Y) :- <Q>(X,Y,Y).");
results = h.execute(new DefaultConjunctiveQuery(query), store, comp);
Assert.assertTrue(results.hasNext());
results.close();
}
use of fr.lirmm.graphik.graal.api.store.TripleStore in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method test1.
// /////////////////////////////////////////////////////////////////////////
// TEST CASES
// /////////////////////////////////////////////////////////////////////////
@Theory
public void test1(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeFalse(store instanceof TripleStore);
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.add(DlgpParser.parseAtom("<P>(a)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X) :- <P>(X)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
CloseableIterator<Substitution> results = h.execute(DlgpParser.parseQuery("?(X) :- <Q>(X)."), store, comp);
Assert.assertTrue(results.hasNext());
Substitution next = results.next();
Assert.assertEquals(DefaultTermFactory.instance().createConstant("a"), next.createImageOf(DefaultTermFactory.instance().createVariable("X")));
Assert.assertFalse(results.hasNext());
results.close();
}
use of fr.lirmm.graphik.graal.api.store.TripleStore in project graal by graphik-team.
the class TripleStoreTest method simpleTest.
@Theory
public void simpleTest(AtomSet store) throws AtomSetException, IteratorException {
Assume.assumeTrue(store instanceof TripleStore);
Term t1 = DefaultTermFactory.instance().createConstant("http://to.to/b");
Term t2 = DefaultTermFactory.instance().createConstant("http://to.to/a");
Predicate p = new Predicate("http://to.to/p", 2);
Atom atom1 = new DefaultAtom(p, t1, t2);
store.add(atom1);
int i = 0;
for (CloseableIterator<Atom> it = store.iterator(); it.hasNext(); it.next()) {
++i;
}
Assert.assertEquals(1, i);
}
Aggregations