Search in sources :

Example 51 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class ChaseTest method test1.

@Theory
public void test1(AtomSet atomSet) throws AtomSetException, HomomorphismFactoryException, HomomorphismException, ChaseException, IteratorException, ParseException {
    atomSet.addAll(DlgpParser.parseAtomSet("<P>(X,a),<Q>(a,a)."));
    LinkedList<Rule> ruleSet = new LinkedList<>();
    ruleSet.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X,Y)."));
    Chase chase = new BreadthFirstChase(ruleSet, atomSet);
    chase.execute();
    ConjunctiveQuery query = DlgpParser.parseQuery("? :- <P>(X,Y),<Q>(X,Y).");
    Assert.assertTrue(SmartHomomorphism.instance().execute(query, atomSet).hasNext());
}
Also used : Rule(fr.lirmm.graphik.graal.api.core.Rule) LinkedList(java.util.LinkedList) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

Example 52 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class ConjunctiveQueryFixedBugTest method issue52Bis.

@Theory
public void issue52Bis(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    Assume.assumeFalse(store instanceof TripleStore);
    try {
        store.addAll(DlgpParser.parseAtomSet("<P0>(a,b),<P1>(b,a),<P1>(d,b),<R>(b,c,c),<R>(b,d,d)."));
        ConjunctiveQuery query = DlgpParser.parseQuery("?(X0,X1,X2,X3,X4,X5) :- <P0>(X0,X3), <R>(X3,X4,X5), <P1>(X4,X2), <P1>(X5,X1).");
        Assert.assertTrue(h.exist(query, store));
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage(), false);
    }
}
Also used : TripleStore(fr.lirmm.graphik.graal.api.store.TripleStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Theory(org.junit.experimental.theories.Theory)

Example 53 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class ConjunctiveQueryFixedBugTest method GraphAtomSetQuery.

/**
 * Query using an DefaultInMemoryGraphAtomSet.
 *
 * @param h
 * @param store
 */
@Theory
public void GraphAtomSetQuery(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        InMemoryAtomSet atomset = new DefaultInMemoryGraphStore();
        atomset.add(DlgpParser.parseAtom("<P>(X)."));
        ConjunctiveQuery query = new DefaultConjunctiveQuery(atomset);
        CloseableIterator<Substitution> subReader;
        subReader = h.execute(query, store);
        Assert.assertFalse(subReader.hasNext());
        subReader.close();
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage(), false);
    }
}
Also used : DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Theory(org.junit.experimental.theories.Theory)

Example 54 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class ConjunctiveQueryWithCompilation method issue35.

@Theory
public void issue35(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>(a,a), <R>(a,b,b)."));
    RuleSet rules = new LinkedListRuleSet();
    rules.add(DlgpParser.parseRule("<Q>(X,Y,X) :- <P>(X,Y)."));
    ConjunctiveQuery query = DlgpParser.parseQuery("? :- <Q>(X,Y,Y), <R>(X,Y,Z).");
    RulesCompilation comp = factory.create();
    comp.compile(rules.iterator());
    StaticChase.executeChase(store, rules);
    CloseableIterator<Substitution> results = h.execute(new DefaultConjunctiveQuery(query), store, comp);
    Assert.assertFalse(results.hasNext());
    results.close();
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TripleStore(fr.lirmm.graphik.graal.api.store.TripleStore) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) RulesCompilation(fr.lirmm.graphik.graal.api.core.RulesCompilation) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) HomomorphismWithCompilation(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismWithCompilation) Theory(org.junit.experimental.theories.Theory)

Example 55 with ConjunctiveQuery

use of fr.lirmm.graphik.graal.api.core.ConjunctiveQuery in project graal by graphik-team.

the class ConjunctiveQueryTest method noAnswerQueryTest3.

/**
 * Test a query without answer
 */
@Theory
public void noAnswerQueryTest3(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        store.addAll(DlgpParser.parseAtomSet("<P>(a,b), <R>(c,c)."));
        ConjunctiveQuery query = DlgpParser.parseQuery("?(Y,X) :- <P>(a,X), <Q>(X,Y).");
        CloseableIterator<Substitution> subReader;
        subReader = h.execute(query, store);
        Assert.assertFalse(subReader.hasNext());
        subReader.close();
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage(), false);
    }
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

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