open-discourse icon indicating copy to clipboard operation
open-discourse copied to clipboard

Add unique Wikidata item to all former and recent Bundestag politicians

Open tifa365 opened this issue 4 years ago • 7 comments

Add Wikidata items to all Bundestag politicians to allow for further querying of related data. Wikidata item links are already downloaded from Wikidata Query Service as a csv file, as attached below. The items can (optionally) be split from the urls and matched with the correct names in the database of Bundestag politicians. The csv data might be incomplete and all unique items need to be double-checked to guarantee correctness.

Update:

Took the time to recheck the query with Wikidata. This seems to be the correct one.

For the Python code (copied from Wikidata):

# pip install sparqlwrapper
# https://rdflib.github.io/sparqlwrapper/

import sys
from SPARQLWrapper import SPARQLWrapper, JSON

endpoint_url = "https://query.wikidata.org/sparql"

query = """SELECT ?mdb ?mdbLabel WHERE {
  ?mdb wdt:P31 wd:Q5;
       p:P39 ?statement.
  ?statement ps:P39 wd:Q1939555.
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}
 }"""


def get_results(endpoint_url, query):
    user_agent = "WDQS-example Python/%s.%s" % (sys.version_info[0], sys.version_info[1])
    # TODO adjust user agent; see https://w.wiki/CX6
    sparql = SPARQLWrapper(endpoint_url, agent=user_agent)
    sparql.setQuery(query)
    sparql.setReturnFormat(JSON)
    return sparql.query().convert()


results = get_results(endpoint_url, query)

for result in results["results"]["bindings"]:
    print(result)

tifa365 avatar Dec 28 '20 19:12 tifa365

Hi @tifa365

Thank you for the issue and the data! I will definitely take a look at how we can merge the wikidata data into our politicians frame!

Cheers

JabobKrauskopf avatar Dec 29 '20 13:12 JabobKrauskopf