Search in sources :

Example 11 with TriplePattern

use of org.apache.jena.reasoner.TriplePattern in project jena by apache.

the class TestTransitiveGraphCache method testRemove.

/**
     * Test the removeRelation functionality.
     */
public void testRemove() {
    TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP);
    cache.addRelation(new Triple(a, closedP, b));
    cache.addRelation(new Triple(a, closedP, c));
    cache.addRelation(new Triple(b, closedP, d));
    cache.addRelation(new Triple(c, closedP, d));
    cache.addRelation(new Triple(d, closedP, e));
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, closedP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), new Triple(a, closedP, b), new Triple(a, closedP, c), new Triple(a, closedP, d), new Triple(a, closedP, e) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(b, closedP, null)), new Object[] { new Triple(b, closedP, b), new Triple(b, closedP, d), new Triple(b, closedP, e) });
    cache.removeRelation(new Triple(b, closedP, d));
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, closedP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), new Triple(a, closedP, b), new Triple(a, closedP, c), new Triple(a, closedP, d), new Triple(a, closedP, e) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(b, closedP, null)), new Object[] { new Triple(b, closedP, b) });
    cache.removeRelation(new Triple(a, closedP, c));
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, closedP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(b, closedP, null)), new Object[] { new Triple(b, closedP, b) });
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePattern(org.apache.jena.reasoner.TriplePattern) TransitiveGraphCache(org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)

Example 12 with TriplePattern

use of org.apache.jena.reasoner.TriplePattern in project jena by apache.

the class TestTransitiveGraphCache method testBug2.

/**
     * Test a case where the transitive reduction appears to 
     * be incomplete. The links just
     * form a linear chain, with all closed links provided. But inserted
     * in a particular order.
     */
public void testBug2() {
    TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP);
    cache.addRelation(new Triple(a, closedP, b));
    cache.addRelation(new Triple(a, closedP, c));
    cache.addRelation(new Triple(b, closedP, c));
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, directP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b) });
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePattern(org.apache.jena.reasoner.TriplePattern) TransitiveGraphCache(org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)

Example 13 with TriplePattern

use of org.apache.jena.reasoner.TriplePattern in project jena by apache.

the class TestTransitiveGraphCache method testCycle3.

/**
     * Two ring-of-three cycles joined at two points
     */
public void testCycle3() {
    TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP);
    cache.addRelation(new Triple(a, closedP, b));
    cache.addRelation(new Triple(b, closedP, c));
    cache.addRelation(new Triple(c, closedP, a));
    cache.addRelation(new Triple(d, closedP, e));
    cache.addRelation(new Triple(e, closedP, f));
    cache.addRelation(new Triple(f, closedP, d));
    cache.addRelation(new Triple(b, closedP, d));
    cache.addRelation(new Triple(f, closedP, c));
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, directP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), new Triple(a, closedP, c), new Triple(a, closedP, d), new Triple(a, closedP, e), new Triple(a, closedP, f) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, directP, a)), new Object[] { new Triple(a, closedP, a), new Triple(b, closedP, a), new Triple(c, closedP, a), new Triple(d, closedP, a), new Triple(e, closedP, a), new Triple(f, closedP, a) });
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePattern(org.apache.jena.reasoner.TriplePattern) TransitiveGraphCache(org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)

Example 14 with TriplePattern

use of org.apache.jena.reasoner.TriplePattern in project jena by apache.

the class TestTransitiveGraphCache method doBasicTest.

public void doBasicTest(TransitiveGraphCache cache) {
    // Test forward property patterns
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, directP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, closedP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), new Triple(a, closedP, c), new Triple(a, closedP, e), new Triple(a, closedP, f), new Triple(a, closedP, g) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, closedP, g)), new Object[] { new Triple(a, closedP, g) });
    // Test backward patterns
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, directP, f)), new Object[] { new Triple(e, closedP, f), new Triple(f, closedP, f), new Triple(c, closedP, f) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, closedP, f)), new Object[] { new Triple(f, closedP, f), new Triple(e, closedP, f), new Triple(b, closedP, f), new Triple(c, closedP, f), new Triple(a, closedP, f), new Triple(d, closedP, f) });
    // List all cases
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, directP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), new Triple(d, closedP, d), new Triple(d, closedP, b), new Triple(b, closedP, b), new Triple(b, closedP, e), new Triple(b, closedP, c), new Triple(e, closedP, e), new Triple(e, closedP, f), new Triple(c, closedP, c), new Triple(c, closedP, f), new Triple(f, closedP, f), new Triple(f, closedP, g), new Triple(g, closedP, g) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, closedP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), new Triple(a, closedP, c), new Triple(a, closedP, e), new Triple(a, closedP, f), new Triple(a, closedP, g), new Triple(d, closedP, d), new Triple(d, closedP, b), new Triple(d, closedP, e), new Triple(d, closedP, c), new Triple(d, closedP, f), new Triple(d, closedP, g), new Triple(b, closedP, b), new Triple(b, closedP, e), new Triple(b, closedP, c), new Triple(b, closedP, f), new Triple(b, closedP, g), new Triple(e, closedP, e), new Triple(e, closedP, f), new Triple(e, closedP, g), new Triple(c, closedP, c), new Triple(c, closedP, f), new Triple(c, closedP, g), new Triple(f, closedP, f), new Triple(f, closedP, g), new Triple(g, closedP, g) });
    // Add a look in the graph and check the loop from each starting position
    cache.addRelation(new Triple(g, closedP, e));
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(e, directP, null)), new Object[] { new Triple(e, closedP, e), new Triple(e, closedP, f), new Triple(e, closedP, g) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(f, directP, null)), new Object[] { new Triple(f, closedP, f), new Triple(f, closedP, g), new Triple(f, closedP, e) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(g, directP, null)), new Object[] { new Triple(g, closedP, g), new Triple(g, closedP, e), new Triple(g, closedP, f) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, directP, e)), new Object[] { new Triple(e, closedP, e), new Triple(f, closedP, e), new Triple(b, closedP, e), new Triple(c, closedP, e), new Triple(g, closedP, e) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, directP, f)), new Object[] { new Triple(f, closedP, f), new Triple(g, closedP, f), new Triple(b, closedP, f), new Triple(c, closedP, f), new Triple(e, closedP, f) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, directP, g)), new Object[] { new Triple(g, closedP, g), new Triple(e, closedP, g), new Triple(b, closedP, g), new Triple(c, closedP, g), new Triple(f, closedP, g) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(g, closedP, null)), new Object[] { new Triple(g, closedP, g), new Triple(g, closedP, e), new Triple(g, closedP, f) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(e, closedP, null)), new Object[] { new Triple(e, closedP, g), new Triple(e, closedP, e), new Triple(e, closedP, f) });
    TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(f, closedP, null)), new Object[] { new Triple(f, closedP, g), new Triple(f, closedP, e), new Triple(f, closedP, f) });
/*        
        System.out.println("Add e-f-g-e loop");        
        cache.printAll();
        listFind(cache, e, directP, null);
        listFind(cache, e, closedP, null);
        listFind(cache, f, directP, null);
        listFind(cache, f, closedP, null);
        listFind(cache, g, directP, null);
        listFind(cache, g, closedP, null);        
        */
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePattern(org.apache.jena.reasoner.TriplePattern)

Example 15 with TriplePattern

use of org.apache.jena.reasoner.TriplePattern in project jena by apache.

the class TestTransitiveGraphCache method testEquivalences.

/**
     * Test equivalences case
     */
public void testEquivalences() {
    TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP);
    cache.addRelation(new Triple(a, closedP, b));
    cache.addRelation(new Triple(b, closedP, a));
    cache.addRelation(new Triple(c, closedP, d));
    cache.addRelation(new Triple(d, closedP, c));
    cache.addRelation(new Triple(b, closedP, d));
    cache.addRelation(new Triple(d, closedP, b));
    assertTrue("Test eq", cache.contains(new TriplePattern(a, closedP, d)));
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePattern(org.apache.jena.reasoner.TriplePattern) TransitiveGraphCache(org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)

Aggregations

TriplePattern (org.apache.jena.reasoner.TriplePattern)16 Triple (org.apache.jena.graph.Triple)13 TransitiveGraphCache (org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)9 Graph (org.apache.jena.graph.Graph)2 InfGraph (org.apache.jena.reasoner.InfGraph)2 Node (org.apache.jena.graph.Node)1 ReasonerException (org.apache.jena.reasoner.ReasonerException)1 BuiltinException (org.apache.jena.reasoner.rulesys.BuiltinException)1 Node_RuleVariable (org.apache.jena.reasoner.rulesys.Node_RuleVariable)1 BindingVector (org.apache.jena.reasoner.rulesys.impl.BindingVector)1 JenaException (org.apache.jena.shared.JenaException)1