Search in sources :

Example 26 with Substitution

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

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

the class DefaultGraphOfRuleDependencies method getSubGraph.

@Override
public DefaultGraphOfRuleDependencies getSubGraph(Iterable<Rule> ruleSet) {
    DefaultGraphOfRuleDependencies subGRD = new DefaultGraphOfRuleDependencies(this.computingUnifiers);
    subGRD.addRuleSet(ruleSet);
    for (Rule src : ruleSet) {
        for (Rule target : ruleSet) {
            Integer e = this.graph.getEdge(src, target);
            if (e != null) {
                // there is an edge
                for (Substitution s : this.edgesValue.get(e)) {
                    subGRD.addDependency(src, s, target);
                }
            }
        }
    }
    return subGRD;
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Rule(fr.lirmm.graphik.graal.api.core.Rule)

Example 28 with Substitution

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

the class DefaultGraphOfRuleDependencies method computeDependencies.

protected void computeDependencies(DependencyChecker... checkers) {
    // preprocess
    IndexedByBodyPredicatesRuleSet index = new IndexedByBodyPredicatesRuleSet(this.graph.vertexSet());
    Iterable<Rule> candidates = null;
    Set<String> marked = new TreeSet<String>();
    for (Rule r1 : this.graph.vertexSet()) {
        marked.clear();
        CloseableIteratorWithoutException<Atom> it = r1.getHead().iterator();
        while (it.hasNext()) {
            Atom a = it.next();
            candidates = index.getRulesByBodyPredicate(a.getPredicate());
            if (candidates != null) {
                for (Rule r2 : candidates) {
                    if (marked.add(r2.getLabel())) {
                        Set<Substitution> unifiers = computeDependency(r1, r2, checkers);
                        if (!unifiers.isEmpty()) {
                            this.setDependency(r1, unifiers, r2);
                        }
                    }
                }
            }
        }
    }
}
Also used : IndexedByBodyPredicatesRuleSet(fr.lirmm.graphik.graal.core.ruleset.IndexedByBodyPredicatesRuleSet) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeSet(java.util.TreeSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 29 with Substitution

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

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

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