// System.out.println("Created ontology: " + ontology);
// In OWL 2 if an ontology has an ontology IRI it may also have a
// version IRI The OWL API encapsulates ontology IRI and possible
// version IRI information in an OWLOntologyID Each ontology knows about
// its ID
OWLOntologyID ontologyID = ontology.getOntologyID();
// In this case our ontology has an IRI but does not have a version IRI
// System.out.println("Ontology IRI: " + ontologyID.getOntologyIRI());
// Our version IRI will be null to indicate that we don't have a version
// IRI
// System.out.println("Ontology Version IRI: "
// + ontologyID.getVersionIRI());
// An ontology may not have a version IRI - in this case, we count the
// ontology as an anonymous ontology. Our ontology does have an IRI so
// it is not anonymous:
// System.out.println("Anonymous Ontology: " +
// ontologyID.isAnonymous());
// Once an ontology has been created its ontology ID (Ontology IRI and
// version IRI can be changed) to do this we must apply a SetOntologyID
// change through the ontology manager. Lets specify a version IRI for
// our ontology. In our case we will just "extend" our ontology IRI with
// some version information. We could of course specify any IRI for our
// version IRI.
IRI versionIRI = IRI.create(ontologyIRI + "/version1");
// Note that we MUST specify an ontology IRI if we want to specify a
// version IRI
OWLOntologyID newOntologyID = new OWLOntologyID(
Optional.of(ontologyIRI), Optional.of(versionIRI));
// Create the change that will set our version IRI
SetOntologyID setOntologyID = new SetOntologyID(ontology, newOntologyID);
// Apply the change
manager.applyChange(setOntologyID);
// We can also just specify the ontology IRI and possibly the version
// IRI at ontology creation time Set up our ID by specifying an ontology
// IRI and version IRI
IRI ontologyIRI2 = IRI
.create("http://www.semanticweb.org/ontologies/myontology2");
IRI versionIRI2 = IRI
.create("http://www.semanticweb.org/ontologies/myontology2/newversion");
OWLOntologyID ontologyID2 = new OWLOntologyID(
Optional.of(ontologyIRI2), Optional.of(versionIRI2));
// Now create the ontology
OWLOntology ontology2 = manager.createOntology(ontologyID2);
// Finally, if we don't want to give an ontology an IRI, in OWL 2 we
// don't have to