def METHOD_NAME(query):
    sparql_endpoint = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql'
    s = SPARQLWrapper(sparql_endpoint)
    # run the query
    s.setQuery(query)
    s.setReturnFormat(JSON)
    results = s.query().convert()
    for row in results['results']['bindings']:
        if "subject" in row:
            # replace the ?subject variable with the wikidata id
            row['wikidata'] = { "value": re.search(r'/(Q\d+)', row['subject']['value']).group(1) }
            del row["subject"]
        # clean up the google entity id
        if 'google_entity_id' in row:
            row['google_entity_id']["value"] = 'kg:' + row['google_entity_id']["value"]
        # clean up the wikipedia and ballotpedia results
        if "wikipedia" in row:
            row["wikipedia"]["value"] = \
                unquote(row["wikipedia"]["value"])\
                .replace("https://en.wikipedia.org/wiki/", "")\
                .strip().replace('_',' ')
        if "ballotpedia" in row:
            row["ballotpedia"]["value"] = row["ballotpedia"]["value"].strip().replace('_',' ')
        # clean up the votesmart id
        if "votesmart" in row:
            try:
                row["votesmart"]["value"] = int(row["votesmart"]["value"])
            except ValueError:
                print("invalid value", row["votesmart"]["value"])
                continue
    # return a simple list of dicts of results
    return [
        {
            k: row[k]['value']
            for k in row
        }
        for row in results['results']['bindings']
    ]