Search in sources :

Example 16 with NodeIterator

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);
                }
            }
        }
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) ResIterator(org.apache.jena.rdf.model.ResIterator) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) InfModel(org.apache.jena.rdf.model.InfModel) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

NodeIterator (org.apache.jena.rdf.model.NodeIterator)16 RDFNode (org.apache.jena.rdf.model.RDFNode)8 Model (org.apache.jena.rdf.model.Model)6 Literal (org.apache.jena.rdf.model.Literal)5 Resource (org.apache.jena.rdf.model.Resource)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 RdfUtils (won.protocol.util.RdfUtils)3 HashSet (java.util.HashSet)2 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)2 Container (org.apache.jena.rdf.model.Container)2 NeedDeactivatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent)2 CloseFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherNeedEvent)2 IncorrectPropertyCountException (won.protocol.exception.IncorrectPropertyCountException)2 WonMessage (won.protocol.message.WonMessage)2 WonRdfUtils (won.protocol.util.WonRdfUtils)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Set (java.util.Set)1 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)1 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)1