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 -
How can I modify my query to exclude all the blank nodes?
OPTIONAL is a binary operator that combines two graph patterns. The optional pattern is any group pattern and may involve any SPARQL pattern types. If the group matches, the solution is extended, if not, the original solution is given (q-opt3. rq).
Dataset: Friend of a Friend (FOAF) @prefix card: <http://www.w3.org/People/Berners-Lee/card#> .
The term “NULL” actually does not occur in the SPARQL spec, perhaps because it doesn't really have a good rep in the database world. Instead the spec talks about bound and unbound variables.
The CONSTRUCT query form returns an RDF graph. The graph is built based on a template which is used to generate RDF triples based on the results of matching the graph pattern of the query.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With