Skip to content Skip to sidebar Skip to footer

How To Add Special Categories In Sparqlwrapper In Python

I am using the following sparql query using sparqlwrapper as follows. from SPARQLWrapper import SPARQLWrapper, JSON sparql = SPARQLWrapper('http://live.dbpedia.org/sparql') sparql.

Solution 1:

I am rewriting what @StanislavKralin mentioned in the above comment. I always try to use full URL in the SPARQL code, particularly when there is special character in SPARQL query.

from SPARQLWrapper import SPARQLWrapper, JSON
sparql = SPARQLWrapper("http://live.dbpedia.org/sparql")
sparql.setReturnFormat(JSON)
my_category = '<http://dbpedia.org/resource/Category:Elasticity_(physics)>'
sparql.setQuery(f" ASK {{ {my_category}  skos:broader{{1,3}} dbc:Medicine }} ")
results = sparql.query().convert()
print(results['boolean'])

Post a Comment for "How To Add Special Categories In Sparqlwrapper In Python"