Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnloadableImportException: Could not load imported ontology

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?

like image 890
enzom83 Avatar asked Jul 06 '16 17:07

enzom83


1 Answers

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.

like image 85
Ignazio Avatar answered Sep 22 '22 15:09

Ignazio