Search in sources :

Example 61 with Rule

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

the class DefaultGraphOfRuleDependencies method toString.

// /////////////////////////////////////////////////////////////////////////
// OVERRIDE METHODS
@Override
public String toString() {
    StringBuilder s = new StringBuilder();
    TreeSet<Rule> rules = new TreeSet<Rule>(new LabelRuleComparator());
    for (Rule r : this.graph.vertexSet()) {
        rules.add(r);
    }
    for (Rule src : rules) {
        for (Integer e : this.graph.outgoingEdgesOf(src)) {
            Rule dest = this.graph.getEdgeTarget(e);
            s.append(src.getLabel());
            s.append(" -");
            if (this.computingUnifiers) {
                for (Substitution sub : this.edgesValue.get(this.graph.getEdge(src, dest))) {
                    s.append(sub);
                }
            }
            s.append("-> ");
            s.append(dest.getLabel());
            s.append('\n');
        }
    }
    return s.toString();
}
Also used : LabelRuleComparator(fr.lirmm.graphik.graal.core.LabelRuleComparator) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeSet(java.util.TreeSet) Rule(fr.lirmm.graphik.graal.api.core.Rule)

Example 62 with Rule

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

the class GRDTest method test2.

@Test
public void test2() throws ParseException {
    Rule r1 = DlgpParser.parseRule("wf(X0,Y0), o(Y0) :- e(X0).");
    Rule r2 = DlgpParser.parseRule("wf(Y1,X1) :- o(Y1).");
    Substitution s = new HashMapSubstitution();
    s.put(DefaultTermFactory.instance().createVariable("Y1"), DefaultTermFactory.instance().createVariable("Y0"));
    RestrictedProductivityChecker filter = RestrictedProductivityChecker.instance();
    Assert.assertTrue(filter.isValidDependency(r1, r2, s));
}
Also used : HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) RestrictedProductivityChecker(fr.lirmm.graphik.graal.core.unifier.checker.RestrictedProductivityChecker) Rule(fr.lirmm.graphik.graal.api.core.Rule) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Test(org.junit.Test)

Example 63 with Rule

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

the class GRDTest method AtomErasingFilterTest.

@Test
public void AtomErasingFilterTest() {
    Rule r1 = DefaultRuleFactory.instance().create(DefaultAtomSetFactory.instance().create(TestUtils.pXZ), DefaultAtomSetFactory.instance().create(TestUtils.pXY, TestUtils.pYZ));
    Rule r2 = DefaultRuleFactory.instance().create(TestUtils.pUU, TestUtils.sU);
    Substitution s = new HashMapSubstitution();
    s.put(DefaultTermFactory.instance().createVariable("X"), DefaultTermFactory.instance().createVariable("U"));
    s.put(DefaultTermFactory.instance().createVariable("Y"), DefaultTermFactory.instance().createVariable("U"));
    s.put(DefaultTermFactory.instance().createVariable("Z"), DefaultTermFactory.instance().createVariable("U"));
    AtomErasingChecker filter = AtomErasingChecker.instance();
    Assert.assertFalse(filter.isValidDependency(r1, r2, s));
}
Also used : AtomErasingChecker(fr.lirmm.graphik.graal.core.unifier.checker.AtomErasingChecker) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Rule(fr.lirmm.graphik.graal.api.core.Rule) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Test(org.junit.Test)

Example 64 with Rule

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

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

the class ChaseTest method restrictedChaseTest0.

@Theory
public void restrictedChaseTest0(AtomSet atomSet) throws AtomSetException, HomomorphismFactoryException, HomomorphismException, ChaseException, IteratorException, ParseException {
    atomSet.addAll(DlgpParser.parseAtomSet("<P>(a,a)."));
    LinkedList<Rule> ruleSet = new LinkedList<>();
    ruleSet.add(DlgpParser.parseRule("<Q>(X,Z) :- <P>(X,X)."));
    Chase chase = new BreadthFirstChase(ruleSet, atomSet);
    chase.execute();
    int size = 0;
    for (CloseableIterator<Atom> it = atomSet.iterator(); it.hasNext(); it.next()) {
        ++size;
    }
    Assert.assertEquals(2, size);
}
Also used : Rule(fr.lirmm.graphik.graal.api.core.Rule) LinkedList(java.util.LinkedList) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase) Atom(fr.lirmm.graphik.graal.api.core.Atom) Theory(org.junit.experimental.theories.Theory)

Aggregations

Rule (fr.lirmm.graphik.graal.api.core.Rule)141 Test (org.junit.Test)87 Atom (fr.lirmm.graphik.graal.api.core.Atom)64 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)52 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)49 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)26 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)23 LinkedList (java.util.LinkedList)19 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)16 Term (fr.lirmm.graphik.graal.api.core.Term)15 Prefix (fr.lirmm.graphik.util.Prefix)14 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)14 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)7 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)7 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6