use of org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache in project jena by apache.
the class TestTransitiveGraphCache method initCache.
/**
* Initialize the cache with some test data
*/
private void initCache() {
// Create a graph with reflexive references, cycles, redundant links
cache = new TransitiveGraphCache(directP, closedP);
cache.addRelation(new Triple(a, closedP, b));
cache.addRelation(new Triple(b, closedP, e));
cache.addRelation(new Triple(b, closedP, c));
cache.addRelation(new Triple(e, closedP, f));
cache.addRelation(new Triple(c, closedP, f));
cache.addRelation(new Triple(f, closedP, g));
cache.addRelation(new Triple(d, closedP, c));
cache.addRelation(new Triple(d, closedP, e));
// reduntant two ways
cache.addRelation(new Triple(d, closedP, g));
// redundant
cache.addRelation(new Triple(a, closedP, e));
// Makes both earlier d's redundant
cache.addRelation(new Triple(d, closedP, b));
cache.addRelation(new Triple(a, closedP, a));
cache.addRelation(new Triple(b, closedP, b));
cache.addRelation(new Triple(c, closedP, c));
cache.addRelation(new Triple(d, closedP, d));
cache.addRelation(new Triple(e, closedP, e));
cache.addRelation(new Triple(f, closedP, f));
cache.addRelation(new Triple(g, closedP, g));
}
use of org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache 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) });
}
use of org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache in project jena by apache.
the class TestTransitiveGraphCache method testCloning.
/**
* Test the clone operation
*/
public void testCloning() {
initCache();
TransitiveGraphCache clone = cache.deepCopy();
// Mess with the original to check cloning
cache.addRelation(new Triple(a, closedP, d));
cache.addRelation(new Triple(g, closedP, a));
doBasicTest(clone);
}
use of org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache 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) });
}
use of org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache 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) });
}
Aggregations