I'm using the following query to get the link / URI to the correct titled resource given an incorrect title:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?redirectsTo WHERE {
?x rdfs:label "Environmental Protection Agency"@en .
?x dbo:wikiPageRedirects ?redirectsTo
}
Using the dbpedia endpoint this is not a problem and returns the correct link to the article, United States Environmental Protection Agency
I'm using the python SPARQLWrapper library to send the sparql query but when I do this exact same query using python:
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
# First check if this entity redirects to another entity
sparql.setQuery("""
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX db: <http://dbpedia.org/resource/>
SELECT ?redirectsTo WHERE {
?x rdfs:label "%s"@en .
?x dbo:wikiPageRedirects ?redirectsTo
}
""" % entity)
sparql.setReturnFormat(JSON)
uri_result = sparql.query().convert()['results']['bindings']
print(uri_result)
I get an empty list of results with no redirects. However, this query does work in python for some things - Obama will give the link for Barack Obama for example
I've heard that the sparql web interface uses a different dataset? If so how can I use this within my python script
Thanks