Closed world prevents new datatype declarations

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

Closed world prevents new datatype declarations

Robert
Dear Jiba,

First of all Thank You for this valuable library! I use it trying to implement a knowledge based personal assistant. ;o)

I have an issue calling "declare_datatype" once one world is closed. The following code snippet is a minimal example to reproduce this behavior:

>>>
import owlready2 as or2

class AnyURI(object):
    def __init__(self, value):
        self.value = value
    @staticmethod
    def parser(iri):
        return AnyURI(iri)
    @staticmethod
    def unparser(any_uri):
        return any_uri.value

w1 = or2.World()
w2 = or2.World()
w1.close()

or2.declare_datatype(AnyURI, 'http://www.w3.org/2001/XMLSchema#anyURI', AnyURI.parser, AnyURI.unparser)
<<<

This raises: "sqlite3.ProgrammingError: Cannot operate on a closed database." happening in the declare_datatype function. I guess it is because w1 is still a part of or2.WORLDS and world.graph.read_only is False.

I worked around that problem by setting read_only to True after closing the world. Maybe this could be integrated directly into the close()-method of the World class. An alternative could be to remove this world from or2.WORLDS on closing. I tried both approaches, but the second sporadically still caused exceptions in my case.

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

Re: Closed world prevents new datatype declarations

Jiba
Administrator
Hello,

Thank you for reporting this problem. I fixed it in the development version,

Jiba