Search in sources :

Example 1 with BindingVector

use of org.apache.jena.reasoner.rulesys.impl.BindingVector in project jena by apache.

the class TestBackchainer method testUnify.

/**
     * Test goal/head unify operation.
     */
public void testUnify() {
    Node_RuleVariable xg = new Node_RuleVariable("?x", 0);
    Node_RuleVariable yg = new Node_RuleVariable("?y", 1);
    Node_RuleVariable zg = new Node_RuleVariable("?z", 2);
    Node_RuleVariable xh = new Node_RuleVariable("?x", 0);
    Node_RuleVariable yh = new Node_RuleVariable("?y", 1);
    Node_RuleVariable zh = new Node_RuleVariable("?z", 2);
    TriplePattern g1 = new TriplePattern(xg, p, yg);
    TriplePattern g2 = new TriplePattern(xg, p, xg);
    TriplePattern g3 = new TriplePattern(a, p, xg);
    TriplePattern g4 = new TriplePattern(a, p, b);
    TriplePattern h1 = new TriplePattern(xh, p, yh);
    TriplePattern h2 = new TriplePattern(xh, p, xh);
    TriplePattern h3 = new TriplePattern(a, p, xh);
    TriplePattern h4 = new TriplePattern(a, p, b);
    TriplePattern h5 = new TriplePattern(xh, p, a);
    doTestUnify(g1, h1, true, new Node[] { null, null });
    doTestUnify(g1, h2, true, new Node[] { null, null });
    doTestUnify(g1, h3, true, new Node[] { null, null });
    doTestUnify(g1, h4, true, new Node[] { null, null });
    doTestUnify(g1, h5, true, new Node[] { null, null });
    doTestUnify(g2, h1, true, new Node[] { null, xh });
    doTestUnify(g2, h2, true, new Node[] { null, null });
    doTestUnify(g2, h3, true, new Node[] { a, null });
    doTestUnify(g2, h4, false, null);
    doTestUnify(g2, h5, true, new Node[] { a, null });
    doTestUnify(g3, h1, true, new Node[] { a, null });
    doTestUnify(g3, h2, true, new Node[] { a, null });
    doTestUnify(g3, h3, true, new Node[] { null, null });
    doTestUnify(g3, h4, true, new Node[] { null, null });
    doTestUnify(g3, h5, true, new Node[] { a, null });
    doTestUnify(g4, h1, true, new Node[] { a, b });
    doTestUnify(g4, h2, false, null);
    doTestUnify(g4, h3, true, new Node[] { b });
    doTestUnify(g4, h4, true, null);
    doTestUnify(g4, h5, false, null);
    // Recursive case
    doTestUnify(h1, h1, true, new Node[] { null, null });
    // Wildcard case
    doTestUnify(new TriplePattern(null, null, null), h2, true, new Node[] { null, null });
    // Test functor cases as well!
    TriplePattern gf = new TriplePattern(xg, p, Functor.makeFunctorNode("f", new Node[] { xg, b }));
    TriplePattern hf1 = new TriplePattern(yh, p, Functor.makeFunctorNode("f", new Node[] { zh, b }));
    TriplePattern hf2 = new TriplePattern(yh, p, Functor.makeFunctorNode("f", new Node[] { a, yh }));
    TriplePattern hf3 = new TriplePattern(yh, p, Functor.makeFunctorNode("f", new Node[] { b, yh }));
    doTestUnify(gf, hf1, true, new Node[] { null, null, yh });
    doTestUnify(gf, hf2, false, null);
    doTestUnify(gf, hf3, true, new Node[] { null, b });
    // Check binding environment use
    BindingVector env = BindingVector.unify(g2, h1, MAX_VARS);
    env.bind(xh, c);
    assertEquals(env.getBinding(yh), c);
    env = BindingVector.unify(g2, h1, MAX_VARS);
    env.bind(yh, c);
    assertEquals(env.getBinding(xh), c);
}
Also used : BindingVector(org.apache.jena.reasoner.rulesys.impl.BindingVector) TriplePattern(org.apache.jena.reasoner.TriplePattern)

Aggregations

TriplePattern (org.apache.jena.reasoner.TriplePattern)1 BindingVector (org.apache.jena.reasoner.rulesys.impl.BindingVector)1