Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OWLOntologyManager.copyOntology does not copy imports #480

Closed
JoyW3000 opened this issue Jan 21, 2016 · 10 comments
Closed

OWLOntologyManager.copyOntology does not copy imports #480

JoyW3000 opened this issue Jan 21, 2016 · 10 comments
Labels

Comments

@JoyW3000
Copy link

Using the following code, the rdf import statement (<owl:imports rdf:resource="http://protege.stanford.edu/junitOntologies/testset/travel.owl"/>) is missing in the copied ontology when setting OntologyCopy to DEEP or SHALLOW. MOVE is the only setting that copies the statement over.

     OWLOntologyManager owlManager = OWLManager.createOWLOntologyManager();
     tOntology = owlManager.copyOntology(ontology, OntologyCopy.DEEP);

Furthermore, tOntology.getDirectImports() returns empty set even the rdf import statement exists in the copied ontology.

The sample ontology used in the test:
protegeSample.txt

@sesuncedu
Copy link
Contributor

I am not sure if this is a bug or not; for a deep copy I am more inclined
to think yes.
Copying a ontology copies the axioms. Import declarations aren't axioms,
so the imports would become lost. I'm not sure what happens to imports
that are turned into includes (horrible rdf format edge case).

Copying just the declarations is not always what is wanted; most of the
time (but not always) one also wants the OWLOntology objects that the
imports resolved to.

The best approach might be a new copy mode, OntologyCopyWithImports, which
would copy the entire imports closure, adding all imports declarations.

A temporary workaround is to copy imports declarations and resolved
imported ontologies by hand.
On Jan 21, 2016 12:29 PM, "JoyW3000" [email protected] wrote:

Using the following code, the rdf import statement () is missing in the
copied ontology when setting OntologyCopy to DEEP or SHADOW MOVE is the
only setting that copies the statement over

 OWLOntologyManager owlManager = OWLManagercreateOWLOntologyManager();
 tOntology = owlManagercopyOntology(ontology, OntologyCopyDEEP);

Furthermore, tOntologygetDirectImports() returns empty set even the rdf
import statement exists in the copied ontology

The sample ontology used in the test:
protegeSampletxt
https://githubcom/owlcs/owlapi/files/99559/protegeSampletxt


Reply to this email directly or view it on GitHub
#480.

@JoyW3000
Copy link
Author

Yes, copying imports declarations would work. But the document itself remains without the import statements. Are the toCopy ontology and the DEEP-copying ontology considered equivalent (equals())? I would suggest to add imports to the DEEP copy.

@ignazio1977
Copy link
Contributor

The javadoc for the method does not mention imports - but it does not mention annotations either and they are copied, so I think bug.

However, note:

tOntology.getDirectImports() returns empty set even the rdf import statement exists in the copied ontology.

This is expected behaviour. The ontology copied to a new manager is only the specified ontology, not its imports closure. And imported ontologies are not loaded in a manager when the imports annotation is added - only when the ontology is loaded from storage. This is existing behaviour, to allow adding an import to an ontology without having to load the import (think importing very large ontologies; one doesn't want to do that just to add an import and save).

@ignazio1977
Copy link
Contributor

On version 5, this test passes:

@Test
public void testDeep() throws OWLOntologyCreationException {
    OWLOntology o = m.loadOntologyFromOntologyDocument(new StringDocumentSource(s));
    OWLOntology copy = m1.copyOntology(o, OntologyCopy.DEEP);
    assertEquals(m1, copy.getOWLOntologyManager());
    assertTrue(m.contains(o));
    assertTrue(m1.contains(copy));
    assertNotNull(m.getOntologyFormat(o));
    assertNotNull(m1.getOntologyFormat(o));
    assertEquals(asSet(o.annotations()), asSet(copy.annotations()));
}

I'll try on 4.

@ignazio1977
Copy link
Contributor

Imports declarations are ontology annotations. But we don't treat them the same as ontology annotations, and therefore they're not included in OWLOntology::annotations()

Why, why why do we make life harder for ourselves?

Bug.

@ignazio1977 ignazio1977 changed the title Copied ontology using OWLOntologyManager.copyOntology has missing imports OWLOntologyManager.copyOntology does not copy imports Jan 21, 2016
@matthewhorridge
Copy link
Contributor

Imports declarations are ontology annotations

According the the OWL 2 FS doc they are distinguished from annotations. Also, adding/removing an import slurps in or removes axioms to/from the imports closure - annotations don't do this.

@ignazio1977
Copy link
Contributor

But owl:imports is an annotation property :-)

There are also several built-in ontology properties; they are owl:imports, owl:priorVersion, owl:backwardCompatibleWith, and owl:incompatibleWith. Ontology annotations that use owl:imports have the extra effect of importing the target ontology.

https://www.w3.org/TR/owl-semantics/syntax.html

Anyway, my bad - I should have added a test for that.

@matthewhorridge
Copy link
Contributor

But owl:imports is an annotation property :-)
https://www.w3.org/TR/owl-semantics/syntax.html

Hang on, thats ancient OWL 1....

In OWL 2 imports declarations are distinct from ontology annotations...

http://www.w3.org/TR/owl2-syntax/#General_Definitions

@sesuncedu
Copy link
Contributor

sesuncedu commented Jan 21, 2016 via email

@ignazio1977
Copy link
Contributor

fixed on 4 and 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants