Bot request: Wikidata:Requests for permissions/Bot
Creating SPARQL-WIKIDATA queries in python
[edit]
For those of you who are interested in running SPARQL queries in python.
- this is a simple program you can run :
from SPARQLWrapper import SPARQLWrapper, JSON
sparql = SPARQLWrapper("https://wdqs-beta.wmflabs.org/bigdata/namespace/wdq/sparql")
sparql.setQuery("""
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX v: <http://www.wikidata.org/prop/statement/>
SELECT ?p ?w ?l ?wl WHERE {
wd:Q30 p:P6/v:P6 ?p .
?p wdt:P26 ?w .
OPTIONAL {
?p rdfs:label ?l FILTER (LANG(?l) = "en") .
}
OPTIONAL {
?w rdfs:label ?wl FILTER (LANG(?wl) = "en").
}
}""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
#print(result["p"]["value"]) + " " + result["w"]["value"]
print(result["l"]["value"]) + " : " + result["wl"]["value"]