How to make a deep copy of an OWLOntology

java, ontology, owl, owl-api

Solution

There's indeed no method to deep copy as far as I know. One solution is to add all the axioms present in your first ontology to a newly created ontology instance. This way you keep everything in memory and no needs to re-read the files. The OWL entities (classes, properties, etc...) should be copied too.

The following code should work (not tested):

manager.addAxioms(newOntology, oldOntology.getAxioms());

Problem

In my program I need to make a deep copy of an instance of `OWLOntology`. I suppose I need to create a new `OWLOntologyManager`: ``` ontologyManager = OWLManager.createOWLOntologyManager(); ``` now I want to add an ontology to the manager which is a DEEP copy of a given OWLOntology. I don't want to load the ontology again from a document, because this takes to much time. How can I do that in an easy way?

Original source