how does `set_name` work?

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

how does `set_name` work?

qai222
Thanks for the excellent package! I'm using owlready for a large ontology and I want to learn more about the behavior of `set_name`

If I rename the property after creating a relation, the name of the object property gets updated as expected

    a = dummy_class(name="a")
    b = dummy_class(name="b")
    setattr(a, dummy_property.name, [b,])
    print(a.get_properties())
    # {onto.dummy_property}

    dummy_property.set_name("lalala")
    print(f"property name has been set to: {dummy_property.name}")
    print(a.get_properties())
    # property name has been set to: lalala
    # {onto.lalala}

but if I rename the property **before** creating the relation, owlready still takes the old name

    a = dummy_class(name="a")
    b = dummy_class(name="b")
    dummy_property.set_name("lalala")
    print(f"property name has been set to: {dummy_property.name}")
    # property name has been set to: lalala

    setattr(a, dummy_property.name, [b,])
    print(a.get_properties())
    # set()

    setattr(a, "dummy_property", [b,])
    print(a.get_properties())
    # {onto.lalala}

is this intended behavior?

Also, if I have a large ontology and I want to rename both its classes and properties (just so I can write human readable code in python, keep IRI unchanged), what is the best practice? So far I just append a `set_name` to each class and property, for example

    ChemicalName = onto.search_one(iri="http://purl.allotrope.org/ontologies/result#AFR_0002292")
    ChemicalName.set_name(ChemicalName, "ChemicalName")

maybe I should use `python_name` for properties?
Reply | Threaded
Open this post in threaded view
|

Re: how does `set_name` work?

Jiba
Administrator
Hi,

The problem is due to the fact that you changed "name", but not "python_name", and Owlready uses python_name for attribute.

I've modified the development version of Owlready (on Bitbucket) so as, if name is modified and python_name is identical, both are modified. This should fix your problem.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: how does `set_name` work?

qai222
Thanks! That solved my problem.