2 Problems regarding ontology loading and browsing

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

2 Problems regarding ontology loading and browsing

kleegrewec
I am working on a software that should convert owl ontologies into other modeling frameworks like dtdl for example. For the owl ontology loading and parsing I use owlready2. But I have currently 2 open questions when working with owlread2 that I need some help on.

1. I need to receive a map of the defined prefixes with the related iris. I cannot find any hint how to do this.
2. I am not able to load imported ontologies that are not dowloadable using their http iris. I checked out some posting in this forum but was not able to resolve my issue.

For the first problem I would like to know how to retrieve the defined prefixes from an ontology that was loaded into owlready2.

For the second question I need more detailed information about ontology loading. From the postings mentioned above I got information that I can download ontologies to local folders and load them from there. So I tried the following.

- I downloaded the imported ontology from the internet and placed it the local folder /my/ontology/folder as production.owl.
- I added the folder to the owlready2 system using onto_path.append("/my/ontology/folder")
- I also placed my primary ontology that I want to convert in this folder since this can not be downloaded too.

loading my primary ontology works fine using the command:

conversion_ontology = get_ontology("http://my.ontologies.com/plm/production/isa95/1.0/isa95.owl")

but loading the imported ontology fails with the error:
-------------------8<----------------------------------------

Traceback (most recent call last):
  File "/home/username/Development/software/.venv/lib/python3.10/site-packages/owlready2/namespace.py", line 960, in load
    fileobj = urllib.request.urlopen("%s/" % (url or f)) # Add missing trailing /, e.g. for https://spec.edmcouncil.org/fibo/ontology/master/latest/BE/LegalEntities/LegalPersons
  File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 308: Permanent Redirect

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/username/Development/software/src/main.py", line 12, in <module>
    conversion_ontology.load(only_local=True)
  File "/home/username/Development/software/.venv/lib/python3.10/site-packages/owlready2/namespace.py", line 1017, 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 "/home/username/Development/software/.venv/lib/python3.10/site-packages/owlready2/namespace.py", line 1017, 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 "/home/username/Development/software/.venv/lib/python3.10/site-packages/owlready2/namespace.py", line 962, in load
    raise OwlReadyOntologyParsingError("Cannot download '%s/'!" % (url or f))
owlready2.base.OwlReadyOntologyParsingError: Cannot download 'http://my.ontologies.com/plm/foundation/production/0.7/'!
 
-------------------8<----------------------------------------------------------

The import statement in my primary ontology looks loke this:

<owl:imports rdf:resource="http://my.ontologies.com/plm/foundation/production/0.7"/>

the content of /my/ontology/folder is:

ls -l /my/ontology/folder

-rw-r--r-- 1 kleegrewec kleegrewec 155720 Feb  2 14:23 isa95.owl
-rw-r--r-- 1 kleegrewec kleegrewec  12609 Feb  1 13:06 production.owl

Any help to overcome one or both of the problems is appreciated by me,

best regards, Christian
Reply | Threaded
Open this post in threaded view
|

Re: 2 Problems regarding ontology loading and browsing

Jiba
Administrator
Hi,

For the first problem, Owlready does not use prefix internally, and thus you cannot get a list of prefixes. I think you have only two options: either parse the beginning of the OWL file manually and extract the prefixes yourself, or generate a new prefix table from the IRI used in the ontology.

For the second problem, the problem is that the local file name ("production.owl") does not match the last part of the IRI of the ontology (which is "0.7"). You can either rename the local file to "0.7.owl", or use the PREDEFINED_ONTOLOGIES dict to map the ontology IRI to its local (full) filename, e.g.:

PREDEFINED_ONTOLOGIES["http://my.ontologies.com/plm/foundation/production/0.7"] = "/my/ontology/folder/production.owl"

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: 2 Problems regarding ontology loading and browsing

kleegrewec
Thanks a lot for this answer, I will try both of the solutions

Christian