Question

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?

Was it helpful?

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());

OTHER TIPS

All the contents of an ontology in terms of axioms are immutable objects, so a deep copy only needs to add all axioms from an OWLOntology to another - you only need to create an OWLOntology with the same OWLOntologyID in a different OWLOntologyManager and add all the axioms. Since the axioms, entities and expressions are all immutable, having them referenced by two OWLOntologies does not cause changes to be propagated from one to the other, or race conditions.

Adding all axioms can be done as in loopasam answer, which is indeed correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top