import requests


def run_sparql_query(query_string):
    """
    Runs the given SPARQL query and returns the results as a list of maps.
    
    Each element of the resulting list contains a mapping from query variables to their binding.
    If the SPARQL query does not return any results (because the result set is empty or because the query is broken),
    this function returns an empty list.
    
    For the query "SELECT ?s WHERE {?s rdf:type sem:Event} LIMIT 1", the result looks like this:
    [{'s': 'http://en.wikinews.org/wiki/Bone_marrow_transplant_potentially_linked_to_cure_of_patient_with_AIDS#ev30'}]
    """
    req = requests.get('http://knowledgestore2.fbk.eu/nwr/wikinews/sparql', params={"query":query_string})
    
    try:    
        json = req.json()
        if 'results' not in json.keys() or 'bindings' not in json['results'].keys():
            return []
        bindings = json['results']['bindings']   
    
        result = []
        for binding in bindings:
            local_map = {}
            for key, value in binding.items():
                local_map[key] = value['value']
            result.append(local_map)
        return result
    except ValueError:
        print("Warning! Couldn't parse JSON!")
        return []