Glad if someone can clarify.
I always read that SQL and SPARQL are very similar. However, a lot o开发者_如何学Pythonf times i have seen sparql query without the FROM keyword. You would assume that you have to query the datasource 'FROM' somewhere in the database like how SQL behaves.
Example
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE
{
?person foaf:name ?name .
}
How does it know where to look for? Like in SQL, look in Database1 - table1
Cheers
SPARQL queries are execute against an RDF dataset, which has two parts:
- A single default graph: a set of triples with no name attached to them
- Zero or more named graphs: a set of triples identified by a name
You can specify the graph to query using the optional FROM
or FROM NAMED
clauses. Have a look at Specifying RDF Datasets. If you omit those clauses, then the query is executed on the default graph.
Graphs and RDF dataset storage is implementation dependent. For example, using Jena ARQ you use a QueryExecutionFactory
and you can initialize it in two ways:
- passing a
Model
, which becomes the default graph on which queries are executed - passing a
Dataset
, which can contain a single default graph and several named graphs
Code Examples for Jena ARQ are available here. Other implementation may be different.
It's closer to "look in Database1, all tables".
As all the data in RDF is triples (or quads if you look at the world that way) you can query across everything you have in one go, without having to worry about schema differences.
精彩评论