6

I've been reading about SPARQL and RDF and please correct me if my reasoning about these technologies is wrong here.

Assuming that we have a local SPARQL database called LOCAL.. and url to remote RDF file called URL_RDF. Can I write a script lets say in PHP which will do a SPARQL query like this ?

Pseudo code.

SELECT * FROM LOCAL,URL_RDF WHERE LOCAL.id=URL_RDF.id

In other words can I combine sources within SPARQL query like this (remote file + local db) ?

AndroidGecko
  • 14,034
  • 3
  • 35
  • 49

1 Answers1

7

You can do this using the federation features in SPARQL 1.1. These are described at http://www.w3.org/TR/sparql11-federated-query, but to give you a quick impression of what it looks like, your example query would be something like this (still in pseudocode):

SELECT * WHERE {
  # the local part of the query
  ?s ?p ?id

  SERVICE <http://url/to/remote/data> {
    # The remote part of the query
    ?x ?y ?id
  }
}

Note that the URL would have to point to a SPARQL endpoint, i.e. a server that can respond to SPARQL queries, and not just a remote RDF file.

Jan
  • 729
  • 4
  • 14
  • Thanks Jan, Can I use raw rdf files at all? do I always need an endpoint? even if the query would relate only to URL_RDF. What if this URL_RDF file would be stored locally? Appreciate your help – AndroidGecko Oct 28 '11 at 08:48
  • You can't query RDF files directly, you always need a bit of software that interprets the RDF file and evaluates your query on this data. To do this, you typically use a "triple store". All triple stores allow you to load RDF files so that you can query them. If you have multiple data files you could just simply load all of them into a single triple store then run your queries. Or, you can use multiple triple stores and query across them using the SERVICE syntax described above. – Jan Oct 29 '11 at 08:37