How to persitently change base_iri such taht it is saved?

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

How to persitently change base_iri such taht it is saved?

cknoll
Hi,

if I change the `base_iri` attribute of an ontology this change is lost after saving to a file. How can I change the base_iri such that this change is permanent?

Minimal example:

import owlready2 as owr

# create ontology in the default_world
onto = owr.get_ontology("https://w3id.org/old/onto#")

with onto:
    class Node(owr.Thing):
        pass
    
fname = "tmp.owl.xml"

new_iri = "https://foo.bar/onto#"
onto.base_iri = new_iri
print(onto.base_iri)
onto.save(fname)


w = owr.World()
onto2 = w.get_ontology(fname).load()
print(onto2.base_iri)

This outputs

https://foo.bar/onto#
https://w3id.org/old/onto#

But I want the output

https://foo.bar/onto#
https://foo.bar/onto#


Best,
Carsten
Reply | Threaded
Open this post in threaded view
|

Re: How to persitently change base_iri such taht it is saved?

Jiba
Administrator
Hi,

I've added the support for Ontology.base_iri = ... in the development version.

By default, it will also rename all entities in the ontology. If you don't want that, you can use:

Ontology.set_base_iri("new_base_iri", rename_entities = False)

Jiba