简体   繁体   中英

FROM clause in SPARQL queries

Good morning. If we consider this query SPARQL, for example:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?name
WHERE {
  ?x rdf:type foaf:Person .
  ?x foaf:name ?name
}
ORDER BY ?name

The query is taken from this link

My question is: it does not have any FROM CLAUSE. So how can it query the dataset? Finally, must I set a FROM CLAUSE when I have to do a SPARQL query?

In the example at http://librdf.org/query you supply the URI for a source file in the text box above the SPARQL query. The text above it suggests two possible sources to use. To see how this is used enter one of them and run the query. You could also have a look at the 'Run this query' links associated with the other examples.

More generally a query submitted to a remote SPARQL endpoint in the query parameter of the URL will use the default graph of the endpoint. Often this is the union of all, or some, of the named graphs in the store being queried. A specific named graph can be specified in a query using FROM NAMED or in the URL using a 'graph=' parameter.

When you send a SPARQL query to an endpoint, it's executed against the "default graph". What the default graph is depends on the endpoint; it's implementation dependent. Using FROM and FROM NAMED allow you to specify what graphs you want to use. The way that FROM and FROM NAMED work is described more in 13.2 Specifying RDF Datasets in the SPARQL 1.1 specification. The relevant parts include:

A SPARQL query may specify the dataset to be used for matching by using the FROM clause and the FROM NAMED clause to describe the RDF dataset. If a query provides such a dataset description, then it is used in place of any dataset that the query service would use if no dataset description is provided in a query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM