How to delete a relation

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

How to delete a relation

SPJ
Hi,

I was wondering whether there is a way to delete a relation in Owlready2.

For example, I have an individual "SPJ" and a data property "TestDataProp". I have created the relation

myonto.SPJ.TestDataProp = ["Test Data Property"]

I now need to delete this relation.

destroy_entity(myonto.SPJ) deletes the Individual. But I only need to delete a data property or an object property assigned to an indiviudual.

Really appreciate if you could help me with this.

Thanks.

SPJ
Reply | Threaded
Open this post in threaded view
|

Re: How to delete a relation

Jiba
Administrator
Hi,

You can simply remove the value from the list :

myonto.SPJ.TestDataProp.remove("Test Data Property")

Lists in Owlready are not "standard" Python lists but derived lists that update the ontology and the quadstore when modified.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to delete a relation

tomekldc
Hi Jiba,

Jiba wrote
myonto.SPJ.TestDataProp.remove("Test Data Property"
Is this fix still working for you ?

I'm trying to replace a Data Property value with your tip but it gave me an error :
"float' object has no attribute 'remove'" (float is my range of my Data Property)

Here's what I ran :
"aircraftOnto.wingcraft1.has_for_positionX.remove()"
where "wingcraft1" is my individual, "has_for_positionX" is the DProperty

Best regards,

TL

Reply | Threaded
Open this post in threaded view
|

Re: How to delete a relation

Jiba
Administrator
Hi,

I think your "has_for_positionX" property is functional. For functional properties, Owlready does not use list, so you cannot use the remove() method.

To delete the relation, just assign None to it, as follows:

wingcraft1.has_for_positionX = None

Jiba