Created
June 29, 2012 04:29
-
-
Save tatiana/3015780 to your computer and use it in GitHub Desktop.
SPARQLWrapper example: List who (musicians) have genre Metal
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 | |
# List all instances (eg. bands) with genre Metal | |
query = """ | |
PREFIX db: <http://dbpedia.org/resource/> | |
PREFIX dbonto: <http://dbpedia.org/ontology/> | |
SELECT DISTINCT ?who | |
FROM <http://dbpedia.org> | |
WHERE { | |
?who dbonto:genre db:Metal . | |
} | |
""" | |
sparql = SPARQLWrapper("http://dbpedia.org/sparql") | |
sparql.setQuery(query) | |
sparql.setReturnFormat(JSON) | |
results = sparql.query().convert() | |
for result in results["results"]["bindings"]: | |
print(result["who"]["value"]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment