class OntologyModels {

    public static Optional<IRI> findFirstOntologyIRI(Model model, ValueFactory vf) {
        Optional<Resource> optionalResource = Models.findFirstSubject(model, vf.createIRI(RDF.TYPE.stringValue()),
                vf.createIRI(OWL.ONTOLOGY.stringValue()));
        if (optionalResource.isPresent() && optionalResource.get() instanceof IRI) {
            return Optional.of((IRI) optionalResource.get());
        }
        return Optional.empty();
    }

}