FROM clause in SPARQL queries

拈花ヽ惹草 提交于 2020-02-25 02:53:45

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/31314594/from-clause-in-sparql-queries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!