Skip to main content

SPARQL Query Language for RDF

Popularity Report

Total Popularity Score: 0

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Rank

Related Lists

Bookmark History

Saved by 42 people (19 private), first by anonymouse user on 2006-03-24


Public Sticky notes

SPARQL Query Language for RDF

Highlighted by cosentino

4 Graph Patterns

Highlighted by cosentino

Complex graph patterns can be made by combining simpler graph patterns.

Highlighted by cosentino

Definition: Group Graph Pattern

A group graph pattern GP is a set of graph patterns, GPi.

A solution of Group Graph Pattern GP on graph G is any solution S such that, for every element GPi of GP, S is a solution of GPi.

Highlighted by cosentino

4.1 Group Graph Patterns

Highlighted by cosentino

OPTIONAL and UNION graph patterns can lead to query results where a variable may be bound in some solutions, but not in others.

Highlighted by cosentino

4.2 Unbound variables

Highlighted by cosentino

queries that allow information to be added to the solution where the information is available, but not to have the solution rejected because some part of the query pattern does not match.

Highlighted by cosentino

Optional matching provides this facility; if the optional part does not lead to any solutions, variables can be left unbound.

Highlighted by cosentino

OPTIONAL { pattern }

Highlighted by cosentino

OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) }

Highlighted by cosentino

Optional patterns can occur inside any group graph pattern, including a group graph pattern which itself is optional

Highlighted by cosentino

The outer optional graph pattern must match for any nested optional pattern to be matched.

Highlighted by cosentino

The UNION keyword is the syntax for pattern alternatives.

Highlighted by cosentino

PREFIX dc10: <http://purl.org/dc/elements/1.0/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT ?title WHERE { { ?book dc10:title ?title } UNION { ?book dc11:title ?title } }

Highlighted by cosentino

Definition: Union Graph Pattern

A union graph pattern is a set of graph patterns GPi.

A union graph pattern matches a graph G with solution S if there is some GPi such that GPi matches G with solution S.

Highlighted by cosentino

7 RDF Dataset

Highlighted by cosentino

Many RDF data stores hold multiple RDF graphs, and record information about each graph, allowing an application to make queries that involve information from more than one graph.

Highlighted by cosentino

A SPARQL query is executed against an RDF Dataset which represents such a collection of graphs.

Highlighted by cosentino

Different parts of the query may be matched against different graphs

Highlighted by cosentino

There is one graph, the default graph, which does not have a name, and zero or more named graphs, each identified by IRI.

Highlighted by cosentino

Two useful arrangements are:

Highlighted by cosentino

to have information in the default graph that includes provenance information about the named graphs

Highlighted by cosentino

to include the information in the named graphs in the default graph as well.

Highlighted by cosentino

Example 1:

# Default graph
@prefix dc: <http://purl.org/dc/elements/1.1/> .

<http://example.org/bob>    dc:publisher  "Bob" .
<http://example.org/alice>  dc:publisher  "Alice" .
# Named graph: http://example.org/bob
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

_:a foaf:name "Bob" .
_:a foaf:mbox <mailto:bob@oldcorp.example.org> .
# Named graph: http://example.org/alice
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@work.example.org> .

Highlighted by cosentino

In this next example, the named graphs contain the same triples as before. The RDF dataset includes an RDF merge of the named graphs in the default graph, re-labeling blank nodes to keep them distinct.

# Default graph
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

_:x foaf:name "Bob" .
_:x foaf:mbox <mailto:bob@oldcorp.example.org> .

_:y foaf:name "Alice" .
_:y foaf:mbox <mailto:alice@work.example.org> .
# Named graph: http://example.org/bob
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

_:a foaf:name "Bob" .
_:a foaf:mbox <mailto:bob@oldcorp.example.org> .
# Named graph: http://example.org/alice
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@work.example> .

Highlighted by cosentino

Example 2:

RDF data can be combined by RDF merge [RDF-MT] of graphs so that the default graph can be made to include the RDF merge of some or all of the information in the named graphs.

Highlighted by cosentino

When querying a collection of graphs, the GRAPH keyword is used to match patterns against named graphs.

Highlighted by cosentino

This is by either using an IRI to select a graph or using a variable to range over the IRIs naming graphs.

Highlighted by cosentino

8.1 Accessing Graph Names

Highlighted by cosentino

restrict the matching applied to a specific graph by supplying the graph IRI.

Highlighted by cosentino

A variable used in the GRAPH clause may also be used in another GRAPH clause or in a graph pattern matched against the default graph in the dataset.

Highlighted by cosentino

Query patterns can involve both the default graph and the named graphs.

Highlighted by cosentino

A SPARQL query may specify the dataset to be used for matching.

Highlighted by cosentino

The FROM clauses give IRIs that the query processor can use to create the default graph and the FROM NAMED clause can be used to specify named graphs.

Highlighted by cosentino

The RDF dataset may also be specified in a SPARQL protocol request,

Highlighted by cosentino

A query processor may use these IRIs in any way to associate an RDF Dataset with a query.

Highlighted by cosentino

For example, it could use IRIs to retrieve documents, parse them and use the resulting triples as one of the graphs;

Highlighted by cosentino

alternatively, it might only service queries that specify IRIs of graphs that it already has stored.

Highlighted by cosentino

The FROM and FROM NAMED keywords allow a query to specify an RDF dataset by reference; they indicate that the dataset should include graphs that are obtained from representations of the resources identified by the given IRIs

Highlighted by cosentino

The dataset resulting from a number of FROM and FROM NAMED clauses is:

  • a default graph consisting of the merge of the graphs referred to in the FROM clauses
  • a set of (IRI, graph) pairs, one from each FROM NAMED clause.

Highlighted by cosentino

Each FROM clause contains an IRI that indicates the graph to be used to form the default graph.

Highlighted by cosentino

If a query provides more than one FROM clause, providing more than one IRI to indicate the default graph, then the default graph is based on the RDF merge of the graphs obtained from representations of the resources identified by the given IRIs.

Highlighted by cosentino

A query can supply IRIs for the named graphs in the RDF Dataset using the FROM NAMED clause.

Highlighted by cosentino

SELECT ?src ?name FROM NAMED <http://example.org/alice> FROM NAMED <http://example.org/bob> WHERE { GRAPH ?src { ?x foaf:name ?name } }

Highlighted by cosentino

The FROM NAMED syntax suggests that the IRI identifies the corresponding graph, but actually the relationship between a URI and a graph in an RDF dataset is indirect. The IRI identifies a resource, and the resource is represented by a graph (or, more precisely: by a document that serializes a graph).

Highlighted by cosentino

10 Query Result Forms

Highlighted by cosentino

SPARQL has four query result forms.

Highlighted by cosentino

SELECT
Returns all, or a subset of, the variables bound in a query pattern match.

Highlighted by cosentino

CONSTRUCT
Returns an RDF graph constructed by substituting variables in a set of triple templates.

Highlighted by cosentino

ASK
Returns a boolean indicating whether a query pattern matches or not.

Highlighted by cosentino

DESCRIBE
Returns an RDF graph that describes the resources found.

Highlighted by cosentino

The SPARQL query language consists of the syntax and semantics for asking and answering queries against RDF graphs. SPARQL contains capabilities for querying by triple patterns, conjunctions, disjunctions, and optional patterns. It also supports constraining queries by source RDF graph and extensible value testing. Results of SPARQL queries can be ordered, limited and offset in number, and presented in several different forms.

Highlighted by audreyh

The SPARQL query language consists of the syntax and semantics for asking and answering queries against RDF graphs.

Highlighted by cosentino

RDF is a directed, labeled graph data format for representing information in the Web

Highlighted by titter

express queries across diverse data sources,

Highlighted by titter

SPARQL query

Highlighted by titter

set of triple patterns

Highlighted by titter

basic graph pattern.

Highlighted by titter

basic graph pattern matches

Highlighted by titter

ubgraph

Highlighted by titter

SELECT clause

Highlighted by titter

identifies

Highlighted by titter

variables to appear in the query results

Highlighted by titter

WHERE clause

Highlighted by titter

basic graph pattern to match against the data graph

Highlighted by titter

result of a query is a solution sequence, corresponding to the ways in which the query's graph pattern matches the data. There may be zero, one or multiple solutions to a query.

Highlighted by titter

SPARQL has several query forms

Highlighted by titter

SELECT query form returns variable bindings

Highlighted by titter

CONSTRUCT query form returns an RDF graph.

Highlighted by titter

graph is built based on a template which is used to generate RDF triples based on the results of matching the graph pattern of the query

Highlighted by titter

SPARQL FILTERs

Highlighted by titter

functions like regex can test RDF literals

Highlighted by titter

SPARQL is based around graph pattern matching. More complex graph patterns can be formed by combining smaller patterns in various ways:

Highlighted by titter

Basic graph patterns are sets of triple patterns

Highlighted by titter

combining graph patterns so that one of several alternative graph patterns may match

Highlighted by titter

UNION

Highlighted by titter

A SPARQL query is executed against an RDF Dataset which represents a collection of graphs

Highlighted by titter

RDF data can be combined by the RDF merge

Highlighted by titter

RDF is a directed, labeled graph data format for representing information in the Web. RDF is often used to represent, among other things, personal information, social networks, metadata about digital artifacts, as well as to provide a means of integration over disparate sources of information. This specification defines the syntax and semantics of the SPARQL query language for RDF.

The SPARQL query language for RDF is designed to meet the use cases and requirements identified by the RDF Data Access Working Group in RDF Data Access Use Cases and Requirements [UCNR].

The SPARQL query language is closely related to the following specifications:

Highlighted by compwoman

11.2.2 Effective Boolean Value (EBV)

Effective boolean value is used to calculate the arguments to the logical functions logical-and, logical-or, and fn:not, as well as evaluate the result of a FILTER expression.

The XQuery Effective Boolean Value rules rely on the definition of XPath's fn:boolean. The following rules reflect the rules for fn:boolean applied to the argument types present in SPARQL Queries:

  • The EBV of any literal whose type is xsd:boolean or numeric is false if the lexical form is not valid for that datatype (e.g. "abc"^^xsd:integer).
  • If the argument is a typed literal with a datatype of xsd:boolean, the EBV is the value of that argument.
  • If the argument is a plain literal or a typed literal with a datatype of xsd:string, the EBV is false if the operand value has zero length; otherwise the EBV is true.
  • If the argument is a numeric type or a typed literal with a datatype derived from a numeric type, the EBV is false if the operand value is NaN or is numerically equal to zero; otherwise the EBV is true.
  • All other arguments, including unbound arguments, produce a type error.

An EBV of true is represented as a typed literal with a datatype of xsd:boolean and a lexical value of "true"; an EBV of false is represented as a typed literal with a datatype of xsd:boolean and a lexical value of "false".

Highlighted by marido