Support load() to provide explicit ontology file locations

Posted by jo-fra on
URL: http://owlready.306.s1.nabble.com/Support-load-to-provide-explicit-ontology-file-locations-tp3197.html

Hi and first of all thanks for providing this library!

I am facing some limitations with the loading mechanism that is currently implemented in Owlready2.
It would be great to provide explicit location paths for the ontology files that should be loaded.

E.g. I have an ontology importing-ontology.rdf that is importing the top level ontology http://rds.posccaesar.org/ontology/lis14/ont/core via the version IRI http://rds.posccaesar.org/ontology/lis14/ont/core/1.0:

<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.example.com/importing-ontology/"
     xml:base="http://www.example.com/importing-ontology/"
     ...
    <owl:Ontology rdf:about="http://www.example.com/importing-ontology">
        <owl:imports rdf:resource="http://rds.posccaesar.org/ontology/lis14/ont/core/1.0"/>
    </owl:Ontology>
</rdf:RDF>

Loading it via
from owlready2 import get_ontology
onto = get_ontology("file://importing-ontology.rdf").load()
would fail because the version IRI does not resolve to the actual RDF/XML file that would be available at the URL http://rds.posccaesar.org/ontology/lis14/ont/core/1.0/LIS-14.rdf

As I read in the documentation and other threads there are two options currently:

1) Adapt the import to reference the actual RDF/XML file url:
       
<owl:imports rdf:resource="http://rds.posccaesar.org/ontology/lis14/ont/core/1.0/LIS-14.rdf"/>

2) Save the ontology locally under the filename 1.0.rdf and append the local directory to onto_path

I think both solutions are not ideal.

For 1) if I'm not responsible for importing-ontology but just consuming it, and it is using the original version IRI import, I don't like to modify the import statement, since I would have to save (and keep in sync) a duplicated version of the importing-ontology.

For 2) the versioning scheme forces us to save it locally with the filename 1.0.rdf
. If there is another imported ontology, that is using the same versioning scheme, it has to be saved under the same filename. Although the files could be located in different directories, only the first 1.0.rdf would be considered during loading.

Therefore, I think it would be better to have the possibility to provide (additional) explicit paths to local files or URLs e.g. by extending the API of the load() method. I gave it a quick try by extending it with an additional argument that expects a dictionary that maps the IRI to a file path, similar like the PREDEFINED_ONTOLOGIES constant.
Usage example:

from owlready2 import get_ontology

# For now append # character to the IRI,
# because during loading of imported ontology
# the method get_ontology() appends # by default.
# This is not ideal for this case and should be resolved somehow...
paths = {
    "http://rds.posccaesar.org/ontology/lis14/ont/core/1.0#": "http://rds.posccaesar.org/ontology/lis14/ont/core/1.0/LIS-14.rdf",  # Mapping to remote url of RDF/XML file
    # "http://rds.posccaesar.org/ontology/lis14/ont/core/1.0#": "./LIS-14_1.0.rdf",  # Works also for local files
}
onto = get_ontology("file://importing-ontology.rdf").load(ontology_paths=paths)

What do you think?