How to get rdf file from sparql endpoin
I am new to opendata and need some help. Wikipedia has a sparql endpoint at this url: http://dbpedia.org/sparql Now I need to write a webservice to get some rdf file from dbpedia. What should I send to this endpoint to get the rdf file? thanks for the reference
source to share
Submit a CONSTRUCT request . Small example:
CONSTRUCT { ?s ?p ?o }
WHERE { ?s ?p ?o }
LIMIT 10
The WHERE clause works the same as the SELECT clause, except that the values fill the CONSTRUCT block as a kind of template. It's very flexible - you can either copy the instructions like here, or transform them into a completely different form.
source to share
What Danny answered is the correct general answer. But I would not recommend that you perform such a request on external services because of the expected result; do it on a specific resource
But of course, if you want to do it directly, without having to manually save the query results, from Python, for example, the code would look like this:
from SPARQLWrapper import SPARQLWrapper, XML
uri = "http://dbpedia.org/resource/Asturias"
query = "CONSTRUCT { <%s> ?p ?o } WHERE { <%s> ?p ?o }" % (uri, uri)
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery(query)
sparql.setReturnFormat(XML)
results = sparql.query().convert()
file = open("output.rdf", "w")
results.serialize(destination=file, format="xml")
file.flush()
file.close()
Of course, this can be done with just about any programming language you prefer.
source to share
I would recommend that you read Bob DuCharme's book Learning SPARQL . It covers some examples that also use the DBPedia endpoint.
PS: This is not Wikipedia. The SPARQL endpoint is the DBPedia SPARQL endpoint (Wikipedia itself does not provide its own SPARQL endpoint ATM). However, DBPedia data is based on Wikipedia data;)
source to share