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: 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

3 answers

Submit a CONSTRUCT request . Small example:

CONSTRUCT { ?s ?p ?o }
WHERE { ?s ?p ?o }


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.



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 = ""
query = "CONSTRUCT { <%s> ?p ?o } WHERE { <%s> ?p ?o }" % (uri, uri)

sparql = SPARQLWrapper("")
results = sparql.query().convert()

file = open("output.rdf", "w")
results.serialize(destination=file, format="xml")


Of course, this can be done with just about any programming language you prefer.



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;)



All Articles