error_on_undefined_entity=False not working with sparql query on read-only DB

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

error_on_undefined_entity=False not working with sparql query on read-only DB

Pascal
When I load an ontology from a DB using:

db_path = "./quadstore.sqlite3"
world = World(filename=db_path, exclusive=False, read_only=True)


and try to run a query using:

world.sparql(query, error_on_undefined_entities=False)


I get the error:

File ".../.venv/lib/python3.11/site-packages/owlready2/triplelite.py", line 362, in _abbreviate
    self.execute("INSERT INTO resources VALUES (?,?)", (storid, iri))
sqlite3.OperationalError: attempt to write a readonly database


The query only runs if I put the read_only flag to False when loading the ontology from the DB.

Why is that? I don't understand why these two concepts are related. Am I doing something wrong?

P.S. if it's of any help, the reason why I'm trying to use error_on_undefined_entities is because I need to query some entities with the same UUID but a different IRI. I just want to retrieve them wherever a match is found. If there's a different way of doing this I would also appreciate any workaround.

Thanks for your help
Reply | Threaded
Open this post in threaded view
|

Re: error_on_undefined_entity=False not working with sparql query on read-only DB

Jiba
Administrator
The use of "error_on_undefined_entities=False" allows to query entities that are not yet defined in the quadstore. However, OWL and RDF identify entities by IRI, while Owlready uses Store-ID (storid), which are integer numbers. Before performing the query, Owlready needs to create a Store-ID for the given IRI, which requires to write in the database (in the "resources" table).

To avoid the problem, you can either remove "read_only=True" to allow writing, or verify before performing the query whether the entity exists (using Word[iri]). If the entity does not exist, you could perform a different query that does not use this entity, or no query at all if the missing entity is mandatory.

Jiba