Excluding Blank Nodes from SPARQL query results

安稳与你 提交于 2019-12-21 02:35:13

问题


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?


回答1:


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:

  • isIRI,
  • isBlank,
  • isLiteral, isNumeric.


来源:https://stackoverflow.com/questions/44111025/excluding-blank-nodes-from-sparql-query-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!