Insufficient check for loading ontology from file.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Insufficient check for loading ontology from file.

NicolasRouquette
Suppose we have a folder like this:

/data/example
/data/example.owl        Suppose the ontology has IRI: http://example
/data/example/toto.owl

If we do the following:

onto_path.append("/data")
onto = get_ontology("http://example").load()

This fails. The reason is that the logic in namespace:

def _get_onto_file(base_iri, name, mode = "r", only_local = False):
  if base_iri.endswith("#") or base_iri.endswith("/"): base_iri = base_iri[:-1]
  if base_iri.startswith("file://"): return urllib.parse.unquote(base_iri[7:])
 
  for dir in onto_path:
    filename = os.path.join(dir, base_iri.rsplit("/", 1)[-1])
    if os.path.exists(filename): return filename                         # insufficient check!
    for ext in ["", ".nt", ".ntriples", ".rdf", ".owl"]:
      filename = os.path.join(dir, "%s%s" % (name, ext))
      if os.path.exists(filename): return filename
  if (mode.startswith("r")) and not only_local: return base_iri
  if (mode.startswith("w")): return os.path.join(onto_path[0], "%s.owl" % name)
  raise FileNotFoundError

The test should be:

    if os.path.exists(filename) and os.path.isfile(filename): return filename

- Nicolas.
Reply | Threaded
Open this post in threaded view
|

Re: Insufficient check for loading ontology from file.

NicolasRouquette
I tested my fix and found that there were additional places where the same file check was missing.
I've updated the PR with these additional checks.

- Nicolas.
Reply | Threaded
Open this post in threaded view
|

Re: Insufficient check for loading ontology from file.

Jiba
Administrator
Thank you for reporting and fixing this problem !

I've integrated your fix in the development version of Owlready,

Jiba