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();
}
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;
}
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);
}
}
}
}
}
}
}
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));
}
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));
}
Aggregations