Search in sources :

Example 46 with Substitution

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

the class AtomicQueryHomomorphism method execute.

@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a, RulesCompilation rc) throws HomomorphismException {
    try {
        List<CloseableIterator<Substitution>> iteratorsList = new LinkedList<CloseableIterator<Substitution>>();
        Atom atom = q.getAtomSet().iterator().next();
        for (Pair<Atom, Substitution> im : rc.getRewritingOf(atom)) {
            iteratorsList.add(new ConverterCloseableIterator<Atom, Substitution>(a.match(im.getLeft()), new Atom2SubstitutionConverter(im.getLeft(), q.getAnswerVariables(), im.getRight())));
        }
        return new CloseableIteratorAggregator<Substitution>(new CloseableIteratorAdapter<CloseableIterator<Substitution>>(iteratorsList.iterator()));
    } catch (AtomSetException e) {
        throw new HomomorphismException(e);
    }
}
Also used : ConverterCloseableIterator(fr.lirmm.graphik.util.stream.converter.ConverterCloseableIterator) CloseableIterator(fr.lirmm.graphik.util.stream.CloseableIterator) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) CloseableIteratorAggregator(fr.lirmm.graphik.util.stream.CloseableIteratorAggregator) LinkedList(java.util.LinkedList) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 47 with Substitution

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

the class UnifierTest method mostGeneralTest1.

@Test
public void mostGeneralTest1() throws IteratorException {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.pXY);
    rule.getHead().add(TestUtils.qXY);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.qUV);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(1, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Example 48 with Substitution

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

the class UnifierTest method unificationExistentialWithFrontier.

@Test
public void unificationExistentialWithFrontier() {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.sX);
    rule.getHead().add(TestUtils.pXY);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.pUU);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(0, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Example 49 with Substitution

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

the class UnifierTest method pieceUnifierTest2.

@Test
public void pieceUnifierTest2() {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.sX);
    rule.getHead().add(TestUtils.pXB);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.pAU);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(1, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Example 50 with Substitution

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

the class UnifierTest method example35MelanieThesis.

@Test
public void example35MelanieThesis() {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.pXY);
    rule.getHead().add(TestUtils.qXY);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.qUV);
    atomset.add(TestUtils.pVW);
    atomset.add(TestUtils.qTW);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(2, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

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