Search in sources :

Example 71 with ConjunctiveQuery

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

the class ConjunctiveQuery2Test method sameLiteralQueryTest.

@Theory
public void sameLiteralQueryTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        store.add(DlgpParser.parseAtom("<P>(a,\"literal\")."));
        ConjunctiveQuery query = DlgpParser.parseQuery("? :- <P>(a,\"literal\").");
        CloseableIterator<Substitution> subReader;
        subReader = h.execute(query, store);
        Assert.assertTrue("Error on " + store.getClass(), 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)

Example 72 with ConjunctiveQuery

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

the class ConjunctiveQuery2Test method tttTrueQueryTest.

@Theory
public void tttTrueQueryTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        store.addAll(DlgpParser.parseAtomSet("<P>(a,b),<Q>(a,c),<Q>(d,c)."));
        ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y) :- <Q>(a,c),<P>(X,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);
    }
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

Example 73 with ConjunctiveQuery

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

the class ConjunctiveQuery2Test method misc0.

@Theory
public void misc0(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("?(X,Y,Z,W) :- <P>(X,Y),<P>(Y,Z),<P>(Z,W).");
        CloseableIterator<Substitution> subReader = h.execute(query, store);
        Assert.assertTrue(subReader.hasNext());
        subReader.next();
        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)

Example 74 with ConjunctiveQuery

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

the class ConjunctiveQuery2Test method responseVariablesTest.

/**
 * Response variables Test
 */
@Theory
public void responseVariablesTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        store.addAll(DlgpParser.parseAtomSet("<P>(a,b)."));
        ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- <P>(X,Y).");
        CloseableIterator<Substitution> subReader;
        Substitution sub;
        subReader = h.execute(query, store);
        Assert.assertTrue(subReader.hasNext());
        sub = subReader.next();
        Assert.assertEquals(1, sub.getTerms().size());
        Assert.assertEquals(DefaultTermFactory.instance().createConstant("a"), sub.createImageOf(DefaultTermFactory.instance().createVariable("X")));
        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)

Example 75 with ConjunctiveQuery

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

the class ConjunctiveQuery2Test method NFC2Test.

@Theory
public void NFC2Test(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    Assume.assumeFalse(store instanceof TripleStore);
    try {
        store.addAll(DlgpParser.parseAtomSet("<P>(a,b,c)."));
        ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y) :- <P>(X,Y,Y).");
        CloseableIterator<Substitution> 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) TripleStore(fr.lirmm.graphik.graal.api.store.TripleStore) 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