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

Ontology caches should use weak keys #984

Closed
balhoff opened this issue Nov 3, 2020 · 7 comments
Closed

Ontology caches should use weak keys #984

balhoff opened this issue Nov 3, 2020 · 7 comments
Labels

Comments

@balhoff
Copy link
Contributor

balhoff commented Nov 3, 2020

If I load an ontology using an input stream, and then create an empty ontology, with the same ontology IRI, using a new instance of OWLOntologyManager, the empty ontology will return true when asked if it has a class from the first ontology in its signature.

This occurs with OWL API 4.5.18. In version 4.5.17, the bug was worse, in that it would occur also when the first ontology was created in code. With 4.5.18 I can only reproduce the error when I load the first ontology from an input stream.

Here is a Scala ammonite script demonstrating:

import $ivy.`net.sourceforge.owlapi:owlapi-distribution:4.5.18`

import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model.IRI
import java.io.FileInputStream
import java.io.File

val factory = OWLManager.getOWLDataFactory()
val class1 = factory.getOWLClass(IRI.create("http://purl.obolibrary.org/obo/UO_0000196"))
val ont1 = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new FileInputStream(new File("pH.ttl")))

// Should print true, does print true
println(ont1.containsEntityInSignature(class1))

// Should print false, instead prints true
val ont2 = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://purl.obolibrary.org/obo/uo.owl"))
println(ont2.containsEntityInSignature(class1))

// Should print false, instead prints true
val ont3 = OWLManager.createOWLOntologyManager().createOntology(ont1.getOntologyID())
println(ont3.containsEntityInSignature(class1))
@balhoff
Copy link
Contributor Author

balhoff commented Nov 3, 2020

I forgot the ontology file; here it is (had to append .txt to attach).

pH.ttl.txt

@ignazio1977
Copy link
Contributor

Reading the log I had a sudden sense of dread, thinking signature caches might be static or some similar blunder, but I can't replicate the issue.

Can this be replicated by you outside Scala? the only way I can imagine this happening is if some over eager optimization replaces the calls to createOWLOntologyManager() with the variable returned the first time.

@balhoff
Copy link
Contributor Author

balhoff commented Nov 3, 2020

I originally saw this in Java when trying to update ROBOT's OWL API dependency to 4.5.18. The version change causes a few failing tests there. I'll try making a standalone Java app or an OWL API test.

@balhoff
Copy link
Contributor Author

balhoff commented Nov 3, 2020

@ignazio1977 please take a look at #985.

@ignazio1977
Copy link
Contributor

Ok, weird - it happens for OWLClass objects, not for the IRI of that same object.

@ignazio1977
Copy link
Contributor

The signature caches are using the ontologies as object keys, which would be ok if they were using identity to find keys. Instead the default is equality, which for ontologies is based on the ontology id.
The caches should use weak keys, for this reason and because if a key (e.g., an ontology) is not referenced by any other object, it should be garbage collected.

@ignazio1977 ignazio1977 changed the title OWLOntology.containsEntityInSignature returns true for empty ontology Ontology caches should use weak keys Nov 3, 2020
@ignazio1977 ignazio1977 added the bug label Nov 3, 2020
@balhoff
Copy link
Contributor Author

balhoff commented Nov 4, 2020

Thanks @ignazio1977!

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

2 participants