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

classic Classic list List threaded Threaded
6 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