Search in sources :

Example 76 with Substitution

use of fr.lirmm.graphik.graal.api.core.Substitution 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);
    }
}
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 77 with Substitution

use of fr.lirmm.graphik.graal.api.core.Substitution 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);
    }
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 78 with Substitution

use of fr.lirmm.graphik.graal.api.core.Substitution 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);
    }
}
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 79 with Substitution

use of fr.lirmm.graphik.graal.api.core.Substitution 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);
    }
}
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 80 with Substitution

use of fr.lirmm.graphik.graal.api.core.Substitution 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);
    }
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

Aggregations

Substitution (fr.lirmm.graphik.graal.api.core.Substitution)158 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)58 Test (org.junit.Test)55 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)46 Theory (org.junit.experimental.theories.Theory)44 Atom (fr.lirmm.graphik.graal.api.core.Atom)41 Term (fr.lirmm.graphik.graal.api.core.Term)36 LinkedList (java.util.LinkedList)27 Variable (fr.lirmm.graphik.graal.api.core.Variable)25 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)24 Rule (fr.lirmm.graphik.graal.api.core.Rule)23 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)19 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)18 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)16 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)15 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)14 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)14 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)13 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)13 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)13