Register proerties with name and namespace

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

Register proerties with name and namespace

franzlst
Owlready2 registers all properties when loading them. For the map key, it only uses the name of the property. However, names are not unique, but only in combination with the namespace/ontology name.

This leads to problems when creating an ontology. I specifically import two ontolgies that both provide a property with the same name. When saving the ontology, Owlready2 uses the wrong namespace to prepend to the property name, making the generated ontology inconsistent.

I would have created an issue for this on BitBucket, but this does not seem to be possible.
Reply | Threaded
Open this post in threaded view
|

Re: Register proerties with name and namespace

Jiba
Administrator
Hi,

Are you sure that the problem occurs when *saving* the ontology, and not when creating relation using the property ?

If two properties have the same name, you may either rename one of them (using Property.python_name = "new_name"), or use the alternate syntax "Property[individual] = [value1, value2...]" where property is the Property object that can be obtained with the "Ontology.Property" syntax.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Register proerties with name and namespace

franzlst
Hi,

well I guess the problem occurs already when creating the relation, but there it is not so apparent. Just when saving the ontology, it becomes apparent which ontology owlready2 "chose".

I think your suggestion only works (reliably), when setting python_name for both properties.

Let's say I have ontoA with myProp and ontoB with myProp (both are imported via ontoC, which I load). When loading ontoA, Prop.namespace.world._props["myProp"] is set to ontoA.myProp. Then ontoB is loaded, setting Prop.namespace.world._props["myProp"] to ontoB.myProp, overriding the existing entry.

As I don't know, whether ontoA or ontoB was loaded first, I need to set the python_name for both properties.

Thank you for your suggestion, I think this solves the issue!