Created
June 28, 2012 22:19
-
-
Save tatiana/3014365 to your computer and use it in GitHub Desktop.
SPARQLWrapper example: List all predicates of DBPedia Band class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from SPARQLWrapper import SPARQLWrapper, JSON | |
query = """ | |
SELECT distinct ?subject | |
FROM <http://dbpedia.org> | |
{ | |
?subject rdfs:domain ?object . | |
<http://dbpedia.org/ontology/Band> rdfs:subClassOf ?object | |
OPTION (TRANSITIVE, t_distinct, t_step('step_no') as ?n, t_min (0) ). | |
}""" | |
sparql = SPARQLWrapper("http://dbpedia.org/sparql") | |
sparql.setQuery(query) | |
sparql.setReturnFormat(JSON) | |
results = sparql.query().convert() | |
for result in results["results"]["bindings"]: | |
print(result["subject"]["value"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Tatiana,
Thanks for your nice work. If I want to print the query result in JSON format, I have to put the variable name manually in the print statement which is a major drawback of this approach. Is there any way to print the result as just tabular/text format? For example please see the attached image