How to rollback changes of property values in an ontology?

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

How to rollback changes of property values in an ontology?

blmoistawinde
Hello,
I want to rollback some changes of property values at runtime, like:

onto = get_ontology("pizza.owl").load()
test_pizza = onto.Pizza("test_pizza_owl_identifier")
test_pizza.has_topping = []
commit()
test_pizza.has_topping = [ onto.CheeseTopping(), onto.TomatoTopping() ]
rollback()
print(test_pizza.has_topping)    # again is []

I've tried 2 ways for the pseudo `commit()` and `rollback()`, but they all failed.

1. backup file
onto.save("backup1.owl")
test_pizza.has_topping = [ onto.CheeseTopping(), onto.TomatoTopping() ]
onto = get_ontology("backup1.owl").load(reload=True)
test_pizza = onto.search_one(type=onto.Pizza)
test_pizza.has_topping # [pizza.cheesetopping2, pizza.tomatotopping2]

2. database commit
onto.world.graph.db.commit()
# changes here
onto.world.graph.db.rollback()
# same as 1.

Are there any existing solutions for this? Thanks a lot!

Best regards,
blmoistawinde
Reply | Threaded
Open this post in threaded view
|

Re: How to rollback changes of property values in an ontology?

Jiba
Administrator
Hello,

The rollback is currently not supported. You can rollback the database, and it cancels the changes, however Owlready maintain cached values at many level (property values but also individual's classes, etc). A rollback operation would require to undo all changes in the cached values, too.

However, if you are only interested in individual property values, you can clear the cached value with del :


onto = get_ontology("pizza.owl").load()
test_pizza = onto.Pizza("test_pizza_owl_identifier")
test_pizza.has_topping = []
commit()
test_pizza.has_topping = [ onto.CheeseTopping(), onto.TomatoTopping() ]
rollback()
print(test_pizza.has_topping)    # => [cheese1, tomato1] : cached values

del test_pizza.has_topping    # clear cache
print(test_pizza.has_topping)    # => []


Hope this help,
Jiba