Excluding Blank Nodes from SPARQL query results
Asked Answered
C

1

9

I am using RDFLib to query on the Semantic Dicom Ontology. I am querying for owl:Class in the graph constructed from the above ontology. RDFLib returns results which contain blank nodes and I wish to exclude such queries. My query -

from rdflib import Graph
g = Graph()
g.parse('dicom.owl')
q = """SELECT ?c WHERE {?c rdf:type owl:Class}"""
qres = g.query(q)

dicom.owl is the Semantic Dicom Ontology downloaded in my machine.

Some of the results that I receive - Results of owl class queries

How can I modify my query to exclude all the blank nodes?

Connolly answered 22/5, 2017 at 10:52 Comment(0)
H
16
from rdflib import Graph
g = Graph()
g.parse('dicom.owl')
q = """SELECT ?c WHERE { ?c rdf:type owl:Class .
       FILTER (!isBlank(?c)) }"""
qres = g.query(q)

Take a look at this family of SPARQL functions:

Haldane answered 22/5, 2017 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.