Skip to content

Instantly share code, notes, and snippets.

@wikier
Last active August 29, 2015 14:04
Show Gist options
  • Save wikier/857f88534c3d3a910b87 to your computer and use it in GitHub Desktop.
Save wikier/857f88534c3d3a910b87 to your computer and use it in GitHub Desktop.
SPARQLWrapper example
from SPARQLWrapper import SPARQLWrapper, JSON
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label
WHERE { <http://dbpedia.org/resource/Asturias> rdfs:label ?label }
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print(result["label"]["value"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment