Strings are not escaped when searching for concepts in world via sqlite

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

Strings are not escaped when searching for concepts in world via sqlite

Kim Tang
Hello,

first of all, thank you so much for providing API access to SNOMED-CT via owlready2!

I am using owlready2 v.0.44 and noticed that strings have to be escaped before running a search in the SNOMED-CT ontology.

For example searching with the exact string for the Fully Qualified Name for the concept "Electrocardiogram: no myocardial ischemia (finding)" returns an error.

Concept:



Code to reproduce the error:
# Load SNOMED-CT ontology
from owlready2 import *
default_world.set_backend(filename = "pym.sqlite3")
PYM = get_ontology("http://PYM/").load()
SNOMEDCT_US = PYM["SNOMEDCT_US"]

# Search for the concept
SNOMEDCT_US.search('Electrocardiogram: no myocardial ischemia (finding)')

Error message (my call is slightly different but works as the code above):


While most SNOMED-CT concepts probably don't have special characters, several do (e.g., N&V - Nausea and vomiting SCTID: 16932000 ).

I already tried escaping strings with the python module "re" and the re.escape method and also tried using the punctuation submodule from string (from string import punctuation) to get a list of characters to escape, but unfortunately just using those does not work, since for instance paranthesis should remain unescaped in the string - otherwise the concept "Electrocardiogram: no myocardial ischemia (finding)" could not be found.

It would be nice if the owlready2 package could somehow be adjusted to catch these escape errors.
Reply | Threaded
Open this post in threaded view
|

Re: Strings are not escaped when searching for concepts in world via sqlite

Kim Tang
A small update, as I discovered that this problem goes a bit further.

The search functionality returns errors with certain characters but also keywords, which are probably used by SQLITE in queries, such as "NOT" or "OR":

NOT in search string error

OR in search string error

While a workaround for these cases can be to escape the individual characters or keywords, I am not sure how to handle cases with just special characters:

++++ not found

Here, the concept "++++" can not be retrieved despite the existing concept with that exact label.

How can this case be handled?
Reply | Threaded
Open this post in threaded view
|

Re: Strings are not escaped when searching for concepts in world via sqlite

Jiba
Administrator
Hello,

I fixed the problem with a more strict handling and escaping of FTS search, in the development version of Owlready on BitBucket.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Strings are not escaped when searching for concepts in world via sqlite

Kim Tang
Thank you! For now I will work with my temporary workaround but I am looking forward to using your fix with the next owlready2 version.