Implementing Worlds problems

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

Implementing Worlds problems

Demian
Hi Jiba, congrats with your book! If only i could read french i would use it surely!

Anyway i've read this part https://owlready2.readthedocs.io/en/latest/world.html#persistent-world-storing-the-quadstore-in-an-sqlite3-file-database.
And I was trying to using worlds like this:

"manager class"

def __init__(self)
         ..........................
        self.my_world = World()
        self.big_world = World()
        self.big_world.set_backend(filename=PATH_DB, exclusive=True)
        self.onto = self.my_world.get_ontology(iri)

I create the ontology in my_world and i store in .owl file.
I need the same base ontology for reasoning on different scenarios but i'm missing something.

here it is what i'm trying to do

for .....
     new world with base ontology

     adding classes and Property for this particular situation

     reasoning
 
     storing result (not .owl)

  Repeat x times (where x is the number of situation)


I've had some problems:

Database is locked
Database is closed
TypeError: issubclass() arg 1 must be a class


And here some method of my "manager" class


    def save_base_world(self):
        #self.onto.save(os.path.dirname(__file__) + "/.idea/onto.owl")
        self.onto.destroy()
        #self.my_world.save()
        #self.my_world.close()

    def create_new_world(self):
        #self.big_world = World(filename=PATH_DB)
        self.onto = self.big_world.get_ontology("file://" + os.path.dirname(__file__) + "/.idea/onto.owl").\
            load() #True, None, True

    def close_new_world(self):
        self.onto.destroy()
        self.big_world.save()
        self.big_world.graph.commit()
        connect(PATH_DB).close()
        #self.big_world.close()


Thanks for your time

Demian







Reply | Threaded
Open this post in threaded view
|

Re: Implementing Worlds problems

Jiba
Administrator
Hi,

Are you using different database files for each world? In your code examples, the variable PATH_DB suggests that it is a constant... However, you need to use different databases, one per world.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Implementing Worlds problems

Demian
Hi,

Maybe i misunderstood the proper use of back-end. I use the same one for the second world and I specify it every time. Maybe this is also wrong.

If i would reload the same ontology what is the best way to do it ?
Storing it to a file and the loading it ?
Reply | Threaded
Open this post in threaded view
|

Re: Implementing Worlds problems

Jiba
Administrator
Hi,

If you want to load several independent copies of the same ontology, you need to put each copy in its own world. Each world must have a separate SQLite3 database. These databases can be stored either in local files (with a different file for each), but also in memory (just don't specify a filename when creating the world).

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Implementing Worlds problems

Demian
Hi,

Thank you Jiba ! I did it !
Now one final question for you.
I store my ontology in a .owl file and then i load it on each world with world.get_ontology(...).
Is there a better way of getting there? Or is this the best solution?

Demian
Reply | Threaded
Open this post in threaded view
|

Re: Implementing Worlds problems

Jiba
Administrator
Hi,

If you want different copies of the ontology, you need to load it several time. You can speed up the loading by saving the ontology in the NTriple format (which is faster to read).

If the database of each world is stored in a local file, another possibility is to create a backup of the world file after loading the ontology (SQLite3 format), and to copy this backup file for each new world.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Implementing Worlds problems

Demian
Hello Jiba,

A "You can speed up the loading by saving the ontology in the NTriple format"

Thanks, it gained my some precious decimal of seconds!

B " another possibility is to create a backup... "

Fine idea, but rather complicated in my case. If this possibility  doesn't grant me much more efficiency i'll stick with option A.

Again thank you for your precious time,

Demian.