I have an ontology created in Protege 4.3.0 and stored in an OWL file. In order to load this ontology using the OWL API, I use the following code sample.
public class MySampleClass {
private final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
private final OWLDataFactory df = manager.getOWLDataFactory();
private final OWLReasonerFactory rf = new StructuralReasonerFactory();
private final OWLOntology ontology;
private final OWLOntologyID id;
private final IRI iri;
private final PrefixManager pm;
private final OWLReasoner reasoner;
/**
*
* @param file
*/
public MySampleClass(File file) {
try {
ontology = manager.loadOntologyFromOntologyDocument(file);
} catch (OWLOntologyInputSourceException | OWLOntologyCreationException ex) {
// throw custom exception
}
id = ontology.getOntologyID();
iri = id.getOntologyIRI();
pm = new DefaultPrefixManager(iri.toString().concat("#"));
reasoner = rf.createReasoner(ontology);
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
}
}
However, if I try to load an ontology that includes one or more imports, if these imports are not available, an UnloadableImportException is thrown, as the following example:
org.semanticweb.owlapi.model.UnloadableImportException: Could not load imported ontology: http://www.w3.org/2004/02/skos/core Cause: connection timed out
How to solve this problem? If the imported ontology is available offline, how to import this ontology during the loading of my ontology?
You can use AutoIRIMapper
to point to a local folder containing local copies of ontologies.
AutoIRIMapper mapper=new AutoIRIMapper(folder, true);
manager.addIRIMapper(mapper);
Do this before starting to load ontologies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With