Search in sources :

Example 41 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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 42 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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)

Example 43 with InMemoryAtomSet

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

the class FrontierRestrictedChaseHaltingConditionTest method test.

@Test
public void test() throws IteratorException, HomomorphismFactoryException, HomomorphismException {
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create(DlgpParser.parseAtom("p(a,b)."));
    Rule rule = DlgpParser.parseRule("p(X,Z):-p(X,Y).");
    Variable x = DefaultTermFactory.instance().createVariable("X");
    Variable y = DefaultTermFactory.instance().createVariable("Y");
    Constant a = DefaultTermFactory.instance().createConstant("a");
    Constant b = DefaultTermFactory.instance().createConstant("b");
    Substitution s = DefaultSubstitutionFactory.instance().createSubstitution();
    s.put(x, a);
    s.put(y, b);
    FrontierRestrictedChaseHaltingCondition condition = new FrontierRestrictedChaseHaltingCondition();
    CloseableIterator<Atom> toAdd = condition.apply(rule, s, atomset);
    Assert.assertTrue(toAdd.hasNext());
    Atom atom1 = toAdd.next();
    atomset.add(atom1);
    Assert.assertFalse(toAdd.hasNext());
    toAdd.close();
    s = DefaultSubstitutionFactory.instance().createSubstitution();
    s.put(x, a);
    s.put(y, atom1.getTerm(1));
    toAdd = condition.apply(rule, s, atomset);
    Assert.assertFalse(toAdd.hasNext());
    toAdd.close();
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Constant(fr.lirmm.graphik.graal.api.core.Constant) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 44 with InMemoryAtomSet

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

the class DefaultRuleFactory method create.

@Override
public Rule create(String label, Atom body, Atom head) {
    InMemoryAtomSet bodySet = DefaultAtomSetFactory.instance().create(body);
    InMemoryAtomSet headSet = DefaultAtomSetFactory.instance().create(head);
    return new DefaultRule(label, bodySet, headSet);
}
Also used : DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Example 45 with InMemoryAtomSet

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

the class AbstractMapper method map.

@Override
public Rule map(Rule rule) {
    InMemoryAtomSet body = this.map(rule.getBody());
    InMemoryAtomSet head = this.map(rule.getHead());
    return DefaultRuleFactory.instance().create(rule.getLabel(), body, head);
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Aggregations

InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)122 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)40 Atom (fr.lirmm.graphik.graal.api.core.Atom)38 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)35 Test (org.junit.Test)35 Term (fr.lirmm.graphik.graal.api.core.Term)31 Rule (fr.lirmm.graphik.graal.api.core.Rule)25 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)23 LinkedList (java.util.LinkedList)22 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)21 Variable (fr.lirmm.graphik.graal.api.core.Variable)19 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)10 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)10 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 Theory (org.junit.experimental.theories.Theory)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)8 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)7 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)6