Search code examples
owlontologyowl-api

Get an ontology IRI


When we wanna create or load an ontology we use this line of code IRI ontologyIRI = IRI.create("http://owl.man.ac.uk/2005/07/sssw/ontologyName"); So, what should I use to get it as an output?

I tried with this function IRI documentIRI = manager.getOntologyDocumentIRI(ontology); but it retunrs the location of the ontology file, something like this file:/Users/.../Desktop/ontologyname.owl.

Instead of it, I need the one written like this :

http://owl.man.ac.uk/2005/07/sssw/ontologyName

Please, If you have any ideas... Thank you


Solution

  • OWLOntology o = ...
    IRI iri = o.getOWLOntologyID().getOntologyIRI().get();
    

    This returns the IRI that the ontology is identified with; note - this might not be the same IRI that you loaded the ontology from. The resolvable IRI in your example might point at an ontology declaring a different IRI for itself (it is, in that sense, a document IRI).