KeyError in destroy_entity

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

KeyError in destroy_entity

Citlalli
Hello,

I'm trying to destroy some annotations properties and when a run a code like this

___________________________________________

onto = get_ontology('file://ontology_path).load()

ann_props = [ann for ann in onto.annotation_properties()]

for ann_prop in ann_props:
    if 'obo.RO_0002514' in str(ann_prop):
        destroy_entity(ann_prop)
__________________________________________
I get this error:
___________________________________________________
KeyError                                  Traceback (most recent call last)
/Users/citlallimejiaalmonte/Documents/ECCO/ontologies/MICRO/Fixing_logic/looking_for_error_insertion in <module>()
     30 for ann_prop in ann_props:
     31     if 'obo.RO_0002514' in str(ann_prop):
---> 32         destroy_entity(ann_prop)
     33
     34 # for ann_prop in ann_props:
/Users/citlallimejiaalmonte/Library/Enthought/Canopy/edm/envs/User/lib/python3.5/site-packages/owlready2/prop.py in destroy_entity(e)
    384         delattr(s, e._python_name)
    385
--> 386     del e.namespace.world._props[e._python_name]
    387     del e.namespace.world._reasoning_props[e._python_name]
    388
KeyError: 'RO_0002514'
_________________________________________________________

when I run almost the exact same code (only the entity name changed), I successfully destroy the entity.
_____________________________________________
onto = get_ontology('file://ontology_path).load()

ann_props = [ann for ann in onto.annotation_properties()]

for ann_prop in ann_props:
    if 'obo.BFO_0000054' in str(ann_prop):
        destroy_entity(ann_prop)

_______________________________________________

What is going on?

Also, I'm trying to remove these annotation properties to fix some "Illegal redeclaration of entities". In other words, I have an ontology which uses the same IRI for an object property and for an annotation property. I would like to destroy only the annotation property, is this possible?


Cheers
Reply | Threaded
Open this post in threaded view
|

Re: KeyError in destroy_entity

Jiba
Administrator
Hello,

You are right, there was a bug when detsroying assertion property. I fixed it in the development version.

Regarding the "Illegal redeclaration of entities" problem, I think you need to solve it at the RDF level (not OWL, because destroying the property in OWL will destroy it entirely).

Of course, the easiest solution is to manually edit the ontology file. You may also use RDFlib or Owlready to delete the undesired RDF triple.

Best regards,
Jiba