use of org.apache.jena.rdf.model.NodeIterator in project jena by apache.
the class TestReasoners method doTestTransitiveReduction.
/**
* Test that a transitive reduction is complete.
* Assumes test graph has no cycles (other than the trivial
* identity ones).
*/
public void doTestTransitiveReduction(Model model, Property dp) {
InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model);
for (ResIterator i = im.listSubjects(); i.hasNext(); ) {
Resource base = i.nextResource();
List<RDFNode> directLinks = new ArrayList<>();
for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) {
directLinks.add(j.next());
}
for (int n = 0; n < directLinks.size(); n++) {
Resource d1 = (Resource) directLinks.get(n);
for (int m = n + 1; m < directLinks.size(); m++) {
Resource d2 = (Resource) directLinks.get(m);
if (im.contains(d1, dp, d2) && !base.equals(d1) && !base.equals(d2)) {
assertTrue("Triangle discovered in transitive reduction", false);
}
}
}
}
}
Aggregations