Noor
Noor

Reputation: 20178

Using OWL API to import ontology

I'm using the OWL API, and I have an ontology. I'm trying to import another ontology the way we do in protege, i.e. select the OWL File locally and then import it. Is this possible with the OWL API

I'm using the import declaration,

OWLImportsDeclaration importDeclaraton = ontology.getFactory().getOWLImportsDeclaration(IRI.create("/home/noor/Dropbox/TaggingCaseStudy/Programs/TextBasedMA/files/ontologies/OBMA2/photo1.owl"));

But I'm getting an error, it is not taking the file locally,

Caused by: java.io.FileNotFoundException: http://semanticweb.org/home/noor/Dropbox/TaggingCaseStudy/Programs/TextBasedMA/files/ontologies/OBMA2/photo1.owl

Upvotes: 2

Views: 2314

Answers (1)

Ignazio
Ignazio

Reputation: 10684

Your IRI is relative, not absolute - it needs to start with file: for a file to be found. Relative IRIs will be resolved against the base IRI at the time of loading, which in your case creates the URL which you can see in the error. Try making the IRI absolute, or use indirection by using the actual ontology IRI in the import and using an IRIMapper to point at the file.

E.g., if your ontology has an IRI of http://example.com/myontology, use

OWLImportsDeclaration importDeclaraton = ontology.getFactory().getOWLImportsDeclaration(IRI.create("http://example.com/myontology"));

to create the imports declaration, and add an IRIMapper to your OWLOntologyManager for resolving it when loading the ontology:

manager.addIRIMapper(new SimpleIRIMapper(IRI.create("http://example.com/myontology"),
       IRI.create("file:///actual/path/to/file.owl"));

Edit: with OWLAPI 4, this looks like:

manager.getIRIMappers().add(new SimpleIRIMapper(IRI.create("http://example.com/myontology"),
           IRI.create("file:///actual/path/to/file.owl"));

Javadoc for this can be found on the GitHub page

Upvotes: 2

Related Questions