pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

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

pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

dromedary88
Hello, I have installed Pymedtermino2 and imported the UMLS data from umls-2020AA-metathesaurus.zip. When I try to load the snomed CT data using the following code:

from owlready2 import *
default_world.set_backend(filename = "pym.sqlite3")
PYM = get_ontology("http://PYM/").load()
SNOMEDCT_US = PYM["SNOMEDCT_US"]

I get this error:

ValueError: Cannot save existent quadstore in 'pym.sqlite3': File already exists! Use a new filename for saving quadstore or, for opening an already existent quadstore, do not create any triple before calling set_backend().

Can you help me to fix this? Sorry if it's a basic question.
Reply | Threaded
Open this post in threaded view
|

Re: pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

Jiba
Administrator
Hi,

This error means that you previously modified the quadstore before calling set_backed(). In this case, set_backend() tries to save the current quadstore in the given file, and fails because the file already exists.

You must not load or create ontology before calling set_backend() if you want to reuse the previously saved quadstore.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

anthropomorphism
I kept getting this error, and I've found some very surprising behaviour.

from owlready2.pymedtermino2 import umls

umls.default_world.set_backend(filename = "/home/username/pymedtermino.sqlite3")
print(umls.get_ontology("http://PYM/").load()["SNOMEDCT_US"][302509004])

# runs correctly; prints: SNOMEDCT_US["302509004"] # Entire heart

but adding an extra import:

from owlready2.pymedtermino2 import umls
from owlready2.pymedtermino2.model import MetaConcept as mc # <- this one here

umls.default_world.set_backend(filename = "/home/username/pymedtermino.sqlite3")
print(umls.get_ontology("http://PYM/").load()["SNOMEDCT_US"][302509004])


# fails with: ValueError: Cannot save existent quadstore in '/home/adam/pymedtermino.sqlite3': File already exists! 
# Use a new filename for saving quadstore or, for opening an already existent quadstore, do not create any triple before calling set_backend().


The work around is obvious (put the db load in front of the second import) but there's something odd going on in there.
Reply | Threaded
Open this post in threaded view
|

Re: pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

Jiba
Administrator
Hi,

Actually, loading owlready2.pymedtermino2.model create some ontologies (such as PYM), and thus modify the quadstore. Any modification to the quadstore should be done AFTER the call to set_backend()... I agree this is weird, but it is difficult to do otherwise.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

anthropomorphism
Fair enough. Could the error message at least be fixed, in that case? I spent a few confused hours going "what? I'm not creating any triples and I'm still getting this error" before realising that one of the import statements was somehow triggering the error.
Reply | Threaded
Open this post in threaded view
|

Re: pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

Jiba
Administrator
Ok, I'm trying to clarify the error message,

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

anthropomorphism
This post was updated on .
Is there any chance you can provide a list of "forbidden" modules? Or ideally find a way to stop this happening? I'm trying to use owlready2 in some software and this side-effect issue keeps breaking all our build tests as we have to keep track of which modules load which other modules and load them in the right order (in a way that generally you don't have to do with any other python modules).

It's a bit of a problem if module A imports owlready2.model, and module B imports module A and then module C needs to know that it can't import either module A or module B with all its other import statements, before it's opened the database.

Is there some idiom that I'm missing? Is there some kind of trickery with eval that one uses to get round this stuff?
Reply | Threaded
Open this post in threaded view
|

Re: pymedtermino ValueError: Cannot save existent quadstore in 'pym.sqlite3'

Jiba
Administrator
Hi,

To avoid such problem, the easiest solution is:

 * to define the quadstore backend (call to set_backend()) as early as possible -- anything done in the previous in-memory quadstore can be problematic.

 * to create ontology in the quadstore and save them. Call to get_ontology() need to write in the quadstore if the ontology does not exist. If it already exists, it does not need to write.

Jiba