Owlrady2 Load imported onotologies from file not from url

1.4k views Asked by At

I'm trying to load an ontology that imports some other ontologies. These other ontologies are located on my machine and not on the web. If I try my_ontology.load() it tries to load these other ontologies from their URI. But that fails. How can I tell owlready2 where these ontologies are located?

The traceback looks like this:

    Traceback (most recent call last):
  File "~Software/PyOntologyChecker/app.py", line 12, in <module>
    covid_onto = get_ontology_from_file(COVID_ONTOLOGY)
  File "~Software/PyOntologyChecker/app.py", line 8, in get_ontology_from_file
    return get_ontology("file://" + file_path).load()
  File "~.local/lib/python3.8/site-packages/owlready2/namespace.py", line 813, in load
    imported_ontologies = [self.world.get_ontology(self._unabbreviate(abbrev_iri)).load() for abbrev_iri in self.world._get_obj_triples_sp_o(self.storid, owl_imports)]
  File "~.local/lib/python3.8/site-packages/owlready2/namespace.py", line 813, in <listcomp>
    imported_ontologies = [self.world.get_ontology(self._unabbreviate(abbrev_iri)).load() for abbrev_iri in self.world._get_obj_triples_sp_o(self.storid, owl_imports)]
  File "~.local/lib/python3.8/site-packages/owlready2/namespace.py", line 773, in load
    except:  raise OwlReadyOntologyParsingError("Cannot download '%s'!" % f)
owlready2.base.OwlReadyOntologyParsingError: Cannot download 'http://ontofox.hegroup.org/CHEBI_module11.owl'!
1

There are 1 answers

0
Samantra On

Assuming you have a local copy of CHEBI_module11.owl dependence (ex. SOME_DIR/HEBI_module11.owl), add its location into onto_path (as stated in the docs):

onto_path.append("SOME_DIR")

before doing my_ontology.load(). That tells Owlready2 to look for files in SOME_DIR. The path can be relative or absolute (like c:/data/ontologies).

The current Python's working directory is not scanned by default but can be set so with onto_path.append(".").

If a required ontology is described by URI not ending with a usual filename, like "http://rdf.webofcode.org/woc/", the local filename (woc in this case) should not have an extension.