Exclude empty nodes from SPARQL query results

I use RDFLib to query the semantic Dicom ontology . I am querying for owl: Class in a graph built from the above ontology. RDFLib returns results containing empty nodes, and I want to exclude such queries. My request is

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 on my machine.

Some results that I get are Owl query results

How can I modify my query to exclude all empty nodes?

+5
source share
1 answer
 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 SPARQL family of functions:

+7
source

Source: https://habr.com/ru/post/1268095/


All Articles