Skip to content

Optimize SPARQL queries

Nicola Stoira requested to merge sphns-314 into master

These changes are related to the checks at INFO level. At other levels we still have the following queries that maybe could be improved (for the naming convention one it seems to me that the result is similar):

define_deprecated_unversioned_code_constraint:

"""PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
            PREFIX owl: <http://www.w3.org/2002/07/owl#>
            PREFIX sphn-loinc: <https://biomedit.ch/rdf/sphn-resource/loinc/>
            PREFIX sphn-hgnc: <https://biomedit.ch/rdf/sphn-resource/hgnc/>
            SELECT ?this (""" + property_path + """ as ?path) (?typeCode as ?value)
            WHERE {
            {
                ?this """ + property + """ ?oldCode .
                ?oldCode rdf:type ?typeCode .
                ?typeCode rdfs:subClassOf+ sphn-loinc:LOINC .
                ?typeCode rdfs:label ?label .
                FILTER(STRSTARTS(lcase(STR(?label)), "deprecated"))
            }
            UNION
            {
                ?this """ + property + """ ?oldCode .
                ?oldCode rdf:type ?typeCode .
                {
                    SELECT ?typeCode
                    WHERE {
                        ?typeCode rdf:type ?codeType .
                        FILTER(STRSTARTS(STR(?typeCode), "http://purl.obolibrary.org/obo/GENO_") || STRSTARTS(STR(?typeCode), "http://purl.obolibrary.org/obo/SO_"))
                    }
                }
                ?typeCode owl:deprecated ?isDeprecated .
                FILTER(?isDeprecated)
            }
            UNION
            {
                ?this """ + property + """ ?oldCode .
                ?oldCode rdf:type ?typeCode .
                ?typeCode rdfs:subClassOf+ sphn-hgnc:HGNC .
                ?typeCode rdfs:comment ?comment .
                FILTER(lcase(STR(?comment))="entry withdrawn" || lcase(STR(?comment))="symbol withdrawn")
            }
            }"""

define_shared_resource_naming_constraint:

"""PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                         SELECT ?this (""" + property_path + """ as ?path) (?code as ?value)
                         WHERE {
                             ?this """ + property + """ ?code .
                             FILTER(!REGEX(STR(?code), "^https://biomedit.ch/rdf/sphn-resource/.*-Code-.*$"))
                             }"""

define_unique_resource_naming_constraint:

"""PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                         PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                         SELECT ?this (?class as ?path) (?this as ?value)
                         WHERE {
                             ?this rdf:type ?class .
                             FILTER(!REGEX(STR(?this), "^https://biomedit.ch/rdf/sphn-resource/.*-%s-.*$"))
                             }""" % nameOfClassElement

@philip.krauss Could you check if you think some of those can be improved as well? Thanks.

Merge request reports