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