Cleaning python instances before closing a triple store

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

Cleaning python instances before closing a triple store

alevray
Hi,

I have a problem when I reopen a World for my ontology, then the instances of Class I created still exists.
How can I clean up before doing a .close() on my world so that next time when opening it only what I have created as an ontology class or instance... remains but not my python classes?

Here is an example:
I have a class Concept that creates an ontology class and a class KB that have a list of Concept
Now I open an empty ontology as default_world and in KB instance
I created various Concept (added to the listOfConcept)
Then I save and close the world

I open the world I just closed and if I look inside my listOfConcept there are still there.

Here is the result of my code
DKB "XP_2" has been initialised ## I have load the ontology
Context is now set for Malcolm Atkinson
Test ## I have created a concept
Thermometer ## second concept
[<Concept.Concept object at 0x1050c6e10>, <Concept.Concept object at 0x105132470>] ## That's my listOfConcept
The DKB is now closed ## Here I do save and close

DKB XP_2 has been retrieved and is connected under Malcolm Atkinson context ## I reload the sqlite3 file
[<Concept.Concept object at 0x1050c6e10>, <Concept.Concept object at 0x105132470>] ## That's still my listOfConcept

The DKB is now closed


Reply | Threaded
Open this post in threaded view
|

Re: Cleaning python instances before closing a triple store

GoMa
Try creating a new world by

new_world = owlready2.World()

and then load your ontology as usual by onto = new_world.get_ontology('FilePath').load()
Reply | Threaded
Open this post in threaded view
|

Re: Cleaning python instances before closing a triple store

Jiba
Administrator
In reply to this post by alevray
Hi,

Any instance of a class created is automatically stored in the ontology (and the quadstore).

If you want to remove a created instance, you can use destroy_entity(instance). You can also reload the ontology in a new world (as proposed by GoMa), to have it in its original state.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Cleaning python instances before closing a triple store

alevray
Hi,

I actually realised that if I create two main files, one to load the owl file and save the sqlite3 and the second one to reopen the sqlite3 I don't have this problem. Is it normal that in the same main it would keep in memory my python instances even after the close?

Especially I did use a new world to reopen the sqlite3 db

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Cleaning python instances before closing a triple store

Jiba
Administrator
Hi,

Normally, each world has his own cache, so changing world should empty the cache. However, any object loaded may remain in local variable, if you stored them in such variables.

If the problem persist, coul you send me a small working code example that I can use to reproduce it?

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Cleaning python instances before closing a triple store

alevray
Hi Jiba,

I don't have the problem as I know use two different main file to do my tests. I think the problem was due to object loaded and I could still access the data of these. That's what I wanted cleaned when I close my world.

Thanks,
Amélie