Search code examples
pythonontologyprotegeowlready

Delete individuals with owlready2



I am using owlready2 I load my ontology and I tried to delete the individuals of a class :

from owlready2 import *
onto = get_ontology("file://C:/Users/stef/Desktop/my_onto.owl").load()

country_list=onto.search(type=onto.Country)
len(country_list) ----> Out[27]: 219

for indiv in country_list :
    destroy_entity(indiv)

onto.search(type=onto.Country)-----> Out[29]: []

onto.save

it seems to me that the individuals in the class Country are deleted But when I open the ontology with protégé I found the individuals
someone tell me what I am missing !


Solution

  • I have fixed this issue by replacing this line

    onto.save
    

    by this :

    onto.save(file = "file://C:/Users/stef/Desktop/my_onto.owl")