owlcs / owlapi

OWL API main repository
821 stars 315 forks source link

OWLOntologyManagerImpl.copyOntology() No difference between DEEP and SHALLOW #1052

Closed SteinerPascal closed 2 years ago

SteinerPascal commented 2 years ago

Hi, First of all thanks for maintaining the owlapi!

I have wondered about the OWLOntologyManagerImpl.copyOntology(). It seems there is no difference between calling OWLOntologyManagerImpl.copyOntology(ontology, OntologyCopy.DEEP) and OWLOntologyManagerImpl.copyOntology(ontology, OntologyCopy.SHALLOW)

In the code the following is given: https://github.com/owlcs/owlapi/blob/e85b6882a6de0e31d9921d0a96b53b503ed72235/impl/src/main/java/uk/ac/manchester/cs/owl/owlapi/OWLOntologyManagerImpl.java#L861-L875

Is that intentionally or can SHALLOW be removed as an OntologyCopy config enum?

yuvrajgarg commented 2 years ago

Hi, if possible, could you please explain a use case to me where SHALLOW copy would be useful?

yuvrajgarg commented 2 years ago

Hi @SteinerPascal , don't you think the code for SHALLOW case would be just returning the passed on ontology because that is what SHALLOW copy mean, we don't need to create a new Ontology and copy the axioms. Let me know if I am incorrect and if maybe you could share some documentation or a particular file of the repository which I should focus on to understand more and to work on this issue. Thanks

ignazio1977 commented 2 years ago

The difference between deep and shallow is in the code that follows immediately the portion you quoted: as described in the javadoc for OntologyCopy, a shallow copy copies the axioms and annotations in a new ontology, but does not copy format and document IRI - meaning there won't be a default format for the new ontology, nor a file IRI where save operations will be performed by default. It's useful if those details are not needed.

        OWLOntologyManager m = toCopy.getOWLOntologyManager();
        if (settings == OntologyCopy.MOVE || settings == OntologyCopy.DEEP) {
            setOntologyDocumentIRI(toReturn, m.getOntologyDocumentIRI(toCopy));
            OWLDocumentFormat ontologyFormat = m.getOntologyFormat(toCopy);
            if (ontologyFormat != null) {
                setOntologyFormat(toReturn, ontologyFormat);
            }
        }
        if (settings == OntologyCopy.MOVE) {
            m.removeOntology(toCopy);
            // at this point toReturn and toCopy are the same object
            // change the manager on the ontology
            toReturn.setOWLOntologyManager(this);
            // change the lock on the ontology
            if (toReturn instanceof OWLMutableOntology) {
                ((OWLMutableOntology) toReturn).setLock(lock);
            }
        }
SteinerPascal commented 2 years ago

@yuvrajgarg & @ignazio1977 Thanks for the replies. @ignazio1977 Yes you are absolutely right. I did miss that part after my quote! Thank you for the clarification! Going to close this issue then.