How to make a deep copy of OWLOntology

In my program, I need to make a deep copy of the OWLOntology instance.

I assume that I need to create a new OWLOntologyManager :

 ontologyManager = OWLManager.createOWLOntologyManager(); 

Now I want to add the ontology to the manager, which is a DEEP copy of this OWLOntology. I do not want to download the ontology from the document again, because it takes a lot of time.

How can I do this in a simple way?

+4
source share
2 answers

There really is no way to deep copy, as far as I know. One solution is to add all the axioms present in your first ontology to the newly created instance of the ontology. Thus, you store everything in memory and should not re-read the files. OWL objects (classes, properties, etc.) must also be copied.

The following code should work (not verified):

 manager.addAxioms(newOntology, oldOntology.getAxioms()); 
+4
source

The entire contents of the ontology in terms of axioms are immutable objects, so a deep copy only needs to add all the axioms from OWLOntology to another - you only need to create OWLOntology with the same OWLOntologyID in another OWLOntologyManager and add all the axioms. Since axioms, entities, and expressions are immutable, their references, referred to by two OWLOntologies, do not lead to the fact that the changes propagate from one to the other or to the conditions of the race.

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

+1
source

Source: https://habr.com/ru/post/1495981/


All Articles