Destroy entity not working properly

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

Destroy entity not working properly

Neha
hello,

I have a function which purpose is to delete the concepts from an ontology. The concepts to be deleted are the ones not present in the parameter (concepts) provided.

    def del_concepts(self, file_name, concepts):
        onto = get_ontology(self.link).load()

        all_classes=list(onto.classes())
        print(concepts)
        for i in (all_classes):
            if i not in concepts:
                destroy_entity(i)
        onto.save(file=file_name, format="rdfxml")

However, when it reaches a certain concept, I get this error message:

File "C:\Program Files\Python39\lib\site-packages\owlready2\prop.py", line 941, in destroy_entity
    e.namespace.world.graph.destroy_entity(e.storid, destroyer, relation_updater, undoer_objs, undoer_datas)
  File "C:\Program Files\Python39\lib\site-packages\owlready2\triplelite.py", line 933, in destroy_entity
    relation_updater(destroyed_storids, s, ps)
  File "C:\Program Files\Python39\lib\site-packages\owlready2\prop.py", line 907, in relation_updater
    update_relation(destroyed_storids, storid, relations)
  File "C:\Program Files\Python39\lib\site-packages\owlready2\prop.py", line 925, in update_relation
    if o._equivalent_to._indirect:
AttributeError: 'NoneType' object has no attribute '_indirect'

Can someone tell me what I am doing wrong?
Reply | Threaded
Open this post in threaded view
|

Re: Destroy entity not working properly

Jiba
Administrator
Hello,

This is typically the kind of bugs that is very difficult to fix without a working example. Could you please send me your ontology, or at least a part of it that is sufficient to reproduce the problem ?

Thank you,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Destroy entity not working properly

w4ng
 

Hello,

I get the same problem,  I get some err information as
'''
'NoneType' object has no attribute '_indirect'
'NoneType' object has no attribute '_indirect'
'<' not supported between instances of 'NoneType' and 'int'
'NoneType' object has no attribute '_indirect'
'<' not supported between instances of 'NoneType' and 'int'
'<' not supported between instances of 'NoneType' and 'int'
'<' not supported between instances of 'NoneType' and 'int'
'<' not supported between instances of 'NoneType' and 'int'
'<' not supported between instances of 'NoneType' and 'int'
'<' not supported between instances of 'NoneType' and 'int'
'''
I think that is Duplicate Deletions and References problem, If you want to delete this concept, but this concept has other relationship. e.g. is_a or subclass of other class node, it will return the error information.
about answer:
I save the mult-class-node as a list, at end I del all mult-class, it works.

Wang
L
Reply | Threaded
Open this post in threaded view
|

Re: Destroy entity not working properly

L
In reply to this post by Jiba
if  a class who  has  subclass, when you delete the class ,its  subclass will be deleted at the same time.  You can't delete the subclass  twice , so that some error happen.
Reply | Threaded
Open this post in threaded view
|

Re: Destroy entity not working properly

Jiba
Administrator
Hi,

I tried what you described (delete a class, then its subclass) but I am not able to reproduce your problem. Here is my code:

from owlready2 import *

onto = get_ontology ("https://test.org/test.owl")

with onto:
    class C(Thing): pass
    class D(C): pass

default_world.graph.dump()
print()

destroy_entity(C)

default_world.graph.dump()
print()

destroy_entity(D)

default_world.graph.dump()
print()

Could you provide me a similar example that show the problem?

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Destroy entity not working properly

rami_dhouib
In reply to this post by Neha
im here having the same error after 1 year nearly ,
TypeError: '<' not supported between instances of 'NoneType' and 'int' .
its weird im just deleting 1 class with :
a1 = get_namespace("http://w3id.org/gbo#")
destroy_entity(a1.component)
Reply | Threaded
Open this post in threaded view
|

Re: Destroy entity not working properly

Jiba
Administrator
Hi,

Can you give me the error traceback, please?

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Destroy entity not working properly

rami_dhouib
File "C:\Users\ramid\OneDrive\Desktop\Konclude-v0.7.0-1135-Windows-x64-MSVC-Dynamic-Qt5.15.2\reasoning.py", line 9, in <module>
    destroy_entity(a1.component)
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\prop.py", line 986, in destroy_entity
    e.namespace.world.graph.destroy_entity(e.storid, destroyer, relation_updater, undoer_objs, undoer_datas)
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\triplelite.py", line 974, in destroy_entity
    relation_updater(destroyed_storids, s, ps)
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\prop.py", line 946, in relation_updater
    update_relation(destroyed_storids, storid, relations)
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\prop.py", line 954, in update_relation
    o.is_a.reinit([i for i in parents if not i is None and not i is NamedIndividual])
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\util.py", line 76, in reinit
    def reinit(self, l):          old = list(self); super().__init__(l)       ; self._callback(self._obj, old)
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\entity.py", line 241, in _class_is_a_changed
    old = frozenset(old)
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\class_construct.py", line 322, in __hash__
    def __hash__(self): return hash((self.type, self.property, self.value, self.cardinality))
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\class_construct.py", line 359, in __getattr__
    v = self.__dict__["value"] = self.ontology.world._to_python(v, None, default_to_none = True)
  File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\namespace.py", line 274, in _to_python
    if   o < 0: return self._parse_bnode(o)
TypeError: '<' not supported between instances of 'NoneType' and 'int'

My email is ramidhouib389@gmail.com , I can send you the Ontology there .(I embedded it here but I cant see it)
You can access it also here :https://github.com/RAMIDhouib1998/ontology