Can Owlready2 handle redirects for a resource's imports?

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

Can Owlready2 handle redirects for a resource's imports?

gr-fl
Hi all,

I'm a new-to-owlready2 user trying to load an ontology; unfortuantely owlready2 doesn't seem capable of following redirects for imports.

See this example in `Debt.rdf`, from https://github.com/edmcouncil/fibo/blob/master/FBC/DebtAndEquities/Debt.rdf#L4

````
<!ENTITY fibo-be-le-lp "https://spec.edmcouncil.org/fibo/ontology/BE/LegalEntities/LegalPersons/">
````

In this case, the above redirects to another URL (can be seen with a wget):

wget https://spec.edmcouncil.org/fibo/ontology/master/latest/BE/LegalEntities/LegalPersons/
... redirects to https://spec.edmcouncil.org/fibo/ontology/master/latest/BE/LegalEntities/LegalPersons.rdf

If I try to load this ontology:
Code to reproduce:
```
from owlready2 import *

o = get_ontology('https://spec.edmcouncil.org/fibo/ontology/master/latest/FBC/DebtAndEquities/Debt/Debt')
o.load()
```
Then I get:

 withproxy python test_owlready2.py
* Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation
Traceback (most recent call last):
  File "/users/is/grfl/pyenvs/myenv/lib/python3.6/site-packages/owlready2/namespace.py", line 1051, in load
    try:     fileobj = urllib.request.urlopen(url or f)
  File "/users/is/gfl/pyenvs/myenv/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/users/is/grfl/pyenvs/myenv/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/users/is/grfl/pyenvs/myenv/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/users/is/grfl/pyenvs/myenv/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/users/is/grfl/pyenvs/myenv/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/users/is/grfl/pyenvs/myenv/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_owlready2.py", line 4, in <module>
    o.load()
  File "/users/is/grfl/pyenvs/myenv/lib/python3.6/site-packages/owlready2/namespace.py", line 1111, 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 "/users/is/grfl/pyenvs/myenv/lib/python3.6/site-packages/owlready2/namespace.py", line 1111, 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 "/users/is/grfl/pyenvs/myenv/lib/python3.6/site-packages/owlready2/namespace.py", line 1052, in load
    except:  raise OwlReadyOntologyParsingError("Cannot download '%s'!" % (url or f))
owlready2.base.OwlReadyOntologyParsingError: Cannot download 'https://spec.edmcouncil.org/fibo/ontology/master/latest/BE/LegalEntities/LegalPersons'!


Possible cause:
- the the absence of "/" on the redirected URL (if you notice the stack trace's last line, the URL is missing the slash), this can be seen in
https://github.com/pwin/owlready2/blob/master/namespace.py#L1157

NOTE: This issue was originally documented here : https://github.com/edmcouncil/fibo/issues/1847 but determined not to be an issue with FIBO.

Let me know if you have any ideas!
Reply | Threaded
Open this post in threaded view
|

Re: Can Owlready2 handle redirects for a resource's imports?

Jiba
Administrator
Hi,

To fix the problem, in the development version of Owlready, I've automatically added a trailing / when the URL is not found and it does not end by /, .owl or .rdf. I can now load the Debt ontology and its imports successfully.

Thank you for reporting this problem,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Can Owlready2 handle redirects for a resource's imports?

gr-fl
Have you released this change? I'd rather not maintain my own fork of owlready2
Reply | Threaded
Open this post in threaded view
|

Re: Can Owlready2 handle redirects for a resource's imports?

gr-fl
Ah! I just checked your bitbucket repo and I see the trailing slash added in 5f815a6 and bd52c61. Thanks for doing this! I'll play around with it and see how it goes