private Set<String> getObjectsOfProperty(final Model model, final String subject, final String property) { final InfModel infModel = createInfModel(getOWLMicroReasoner(), createDefaultModel()); infModel.add(model.listStatements()); infModel.add(pcdmModel.listStatements()); return asStream(infModel.listObjectsOfProperty(createResource(subject), createProperty(property))) .filter(RDFNode::isURIResource).map(RDFNode::asResource).map(Resource::getURI).collect(toSet()); } }
public WebOntTestHarness() { testDefinitions = loadAllTestDefinitions(); reasoner = ReasonerRegistry.getOWLReasoner(); initResults(); }
/** * Return a Model through which all the RDFS entailments * derivable from the given model are accessible. Some work is done * when the inferenced model is created but each query will also trigger some * additional inference work. * * @param model the Model containing both instance data and schema assertions to be inferenced over */ public static InfModel createRDFSModel(Model model) { Reasoner reasoner = ReasonerRegistry.getRDFSReasoner(); InfGraph graph = reasoner.bind( model.getGraph() ); return new InfModelImpl( graph ); }
/** Answer a ReasonerFactory which delivers reasoners with the given URL <code>reasonerURL</code>. If there is no such reasoner, throw an <code>UnknownreasonerException</code>. */ public static ReasonerFactory getReasonerFactoryByURL( Resource root, Resource reasonerURL ) { String url = reasonerURL.getURI(); ReasonerFactory factory = ReasonerRegistry.theRegistry().getFactory( url ); if (factory == null) throw new UnknownReasonerException( root, reasonerURL ); return factory; } }
/** * Return a property Node which represents the direct version of a * transitively closed property. See <code>makeDirect(String)</code>; * this method makes a new Node with the direct respelling of * <code>node</code>s URI. */ public static Node makeDirect(Node node) { return NodeFactory.createURI( makeDirect( node.getURI() ) ); }
/** * 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); } } } } }
/** * Constructor is hidden - go via theRegistry */ private ReasonerRegistry() { allDescriptions = ModelFactory.createDefaultModel(); // Preload the known Jena reasoners register(TransitiveReasonerFactory.theInstance()); register(RDFSRuleReasonerFactory.theInstance()); register(OWLFBRuleReasonerFactory.theInstance()); register(GenericRuleReasonerFactory.theInstance()); register(OWLMicroReasonerFactory.theInstance()); register(OWLMiniReasonerFactory.theInstance()); }
/** * Return the single global instance of the registry */ public static ReasonerRegistry theRegistry() { if (theRegistry == null) { theRegistry = new ReasonerRegistry(); } return theRegistry; }
/** * Create and return a new instance of the reasoner identified by * the given uri. * @param uri the uri of the reasoner to be created, expressed as a simple string * @param configuration an optional set of configuration information encoded in RDF this * parameter can be null if no configuration information is required. * @return a reaoner instance * @throws ReasonerException if there is not such reasoner or if there is * some problem during instantiation */ public Reasoner create(String uri, Resource configuration) throws ReasonerException { ReasonerFactory factory = getFactory(uri); if (factory != null) { return factory.create(configuration); } else { throw new ReasonerException("Attempted to instantiate an unknown reasoner: " + uri); } }
/** * Return a property Node which represents the direct version of a * transitively closed property. See <code>makeDirect(String)</code>; * this method makes a new Node with the direct respelling of * <code>node</code>s URI. */ public static Node makeDirect(Node node) { return NodeFactory.createURI( makeDirect( node.getURI() ) ); }
/** Answer a ReasonerFactory which delivers reasoners with the given URL <code>reasonerURL</code>. If there is no such reasoner, throw an <code>UnknownreasonerException</code>. */ public static ReasonerFactory getReasonerFactoryByURL( Resource root, Resource reasonerURL ) { String url = reasonerURL.getURI(); ReasonerFactory factory = ReasonerRegistry.theRegistry().getFactory( url ); if (factory == null) throw new UnknownReasonerException( root, reasonerURL ); return factory; } }
/** * 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); } } } } }
/** * Constructor is hidden - go via theRegistry */ private ReasonerRegistry() { allDescriptions = ModelFactory.createDefaultModel(); // Preload the known Jena reasoners register(TransitiveReasonerFactory.theInstance()); register(RDFSRuleReasonerFactory.theInstance()); register(OWLFBRuleReasonerFactory.theInstance()); register(GenericRuleReasonerFactory.theInstance()); register(OWLMicroReasonerFactory.theInstance()); register(OWLMiniReasonerFactory.theInstance()); }
/** * Return the single global instance of the registry */ public static ReasonerRegistry theRegistry() { if (theRegistry == null) { theRegistry = new ReasonerRegistry(); } return theRegistry; }
/** * Create and return a new instance of the reasoner identified by * the given uri. * @param uri the uri of the reasoner to be created, expressed as a simple string * @param configuration an optional set of configuration information encoded in RDF this * parameter can be null if no configuration information is required. * @return a reaoner instance * @throws ReasonerException if there is not such reasoner or if there is * some problem during instantiation */ public Reasoner create(String uri, Resource configuration) throws ReasonerException { ReasonerFactory factory = getFactory(uri); if (factory != null) { return factory.create(configuration); } else { throw new ReasonerException("Attempted to instantiate an unknown reasoner: " + uri); } }
public WebOntTestHarness() { testDefinitions = loadAllTestDefinitions(); reasoner = ReasonerRegistry.getOWLReasoner(); initResults(); }
/** * Return a Model through which all the RDFS entailments * derivable from the given model are accessible. Some work is done * when the inferenced model is created but each query will also trigger some * additional inference work. * * @param model the Model containing both instance data and schema assertions to be inferenced over */ public static InfModel createRDFSModel(Model model) { Reasoner reasoner = ReasonerRegistry.getRDFSReasoner(); InfGraph graph = reasoner.bind( model.getGraph() ); return new InfModelImpl( graph ); }
/** compact call to ReasonerRegistry.makeDirect */ private static final Property makeDirect( Property type ) { return ResourceFactory.createProperty( ReasonerRegistry.makeDirect( type.asNode().getURI() ) ); }
private Set<String> getObjectsOfProperty(final Model model, final String subject, final String property) { final InfModel infModel = createInfModel(getOWLMicroReasoner(), createDefaultModel()); infModel.add(model.listStatements()); infModel.add(oreModel.listStatements()); return asStream(infModel.listObjectsOfProperty(createResource(subject), createProperty(property))) .filter(RDFNode::isURIResource).map(RDFNode::asResource).map(Resource::getURI).collect(toSet()); } }
/** * The reasoner contract for bind(data) is not quite precise. It allows for * reasoners which have state so that reusing the same reasoner on a second data * model might lead to interference. This in fact used to happen with the transitive * reasoner. This is a test to check that the transitive reasoner state reuse has been fixed at source. */ public void testTransitiveBindReuse() { Reasoner r = ReasonerRegistry.getTransitiveReasoner(); InfModel om1 = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel()); Resource c1 = om1.createResource(PrintUtil.egNS + "Class1"); Resource c2 = om1.createResource(PrintUtil.egNS + "Class2"); Resource c3 = om1.createResource(PrintUtil.egNS + "Class3"); om1.add(c1, RDFS.subClassOf, c2); om1.add(c2, RDFS.subClassOf, c3); om1.prepare(); assertFalse(om1.isEmpty()); InfModel om2 = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel()); StmtIterator si = om2.listStatements(); boolean ok = ! si.hasNext(); si.close(); assertTrue("Transitive reasoner state leak", ok); }