owlcs / owlapi

OWL API main repository
821 stars 315 forks source link

unable to LoadOntologyFromDocument #1051

Closed Hebaallahibrahim closed 2 years ago

Hebaallahibrahim commented 2 years ago

Hi, I tried to load an ontology from the disk. The code was working perfectly before but now I get the following error:

Exception in thread "main" java.lang.NullPointerException at uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:186) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:1105) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1055) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1005) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1018)

I use OWLAPI version 5.1.17 and HermiT version 1.4.5.519. Here is the code I use:

val owlFile: File = new File(UrlOwlFile) val manager = OWLManager.createOWLOntologyManager() val ontology = manager.loadOntologyFromOntologyDocument(owlFile) val iri = manager.getOntologyDocumentIRI(ontology) manager.getIRIMappers.add(new SimpleIRIMapper(iri, IRI.create(owlFile)))

I got the error in the 3rd line. Could you please help?

ignazio1977 commented 2 years ago

That null pointer is due to an issue in the RDFFormat class in RDF4J. OWLAPI 5.1.17 includes parsing for a format included in one release of RDF4J but you have two different releases on the classpath, one coming with OWLAPI and an earlier one from HermiT, which includes OWLAPI 5.1.9.

Exclude the transitive dependency from HermiT, or use just HermiT in your dependency management, and everything should work.

Alternatively, instead of loading from a file, create a FileDocumentSource and specify the format for the input file - the failure only happens if the HDT format is used to try and read an ontology. If you restrict your choices to just the correct format the issue does not happen.