Open main menu

Thieol

Joined 26 November 2012
Babel user information
fr-N Cet utilisateur a pour langue maternelle le français.
en-3 This user has advanced knowledge of English.
de-2 Dieser Benutzer beherrscht Deutsch auf fortgeschrittenem Niveau.
it-1 Questo utente può contribuire con un livello elementare in italiano.
Users by language

Bot request: Wikidata:Requests for permissions/Bot

Wikidata statistics
Wikidata-logo.svg
  Number of pages 62,964,756  
  User total 3,587,010  
  Active users list 20,525  
  Administrators 60  
  Users/administrator 342  


Creating SPARQL-WIKIDATA queries in pythonEdit

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"]
  • Enjoy !