Database Reference
In-Depth Information
5.2
FOUNDATIONS
5.2.1 rDF anD sParQl
RDF [1] is the W3C recommended standard model for representing knowledge about
arbitrary resources, for example, articles, authors. An RDF data set consists of a set of
RDF triples in the form ( subject, predicate, object ) that can be interpreted as “ subject has
property predicate with value object .” URIs (Uniform Resource Identifier) are globally
unique identifiers used to represent resources in RDF (e.g., URLs are a subset of URIs).
For clarity of presentation, we use a simplified RDF notation without URI prefixes in
the following. It is possible to visualize an RDF data set as directed, labeled graph where
every triple corresponds to an edge (predicate) from subject to object. Figure 5.1 shows
an RDF graph with information about users and their friendship relationships.
SPARQL is the W3C recommended declarative query language for RDF. A
SPARQL query defines a graph pattern P that is matched against an RDF graph G .
This is done by replacing the variables in P with elements of G such that the resulting
graph is contained in G (pattern matching). The most basic constructs in a SPARQL
query are Triple Patterns , that is, RDF triples where subject, predicate, and object
can be variables (? v ), for example, (? s , p, ? o ). A set of triple patterns concatenated
by AND (.) is called a Basic Graph Pattern (BGP). In general, a SPARQL 1.0 graph
pattern can be defined recursively as follows:
• A BGP is a graph pattern.
• If P , P ′ are graph patterns, then
{ P }.{ P ′}, { P } UNION { P ′} and { P } OPTIONAL { P ′} are also graph
patterns.
• If P is a graph pattern and R is a filter condition, then
P F I LT ER ( R ) is also a graph pattern.
If P is a graph pattern, u an URI and ? v a variable, then
GRAPH u { P } and GRAPH ? v { P } are also graph patterns.
FILTER can be used to restrict the values of variables and OPTIONAL allows to
add additional information to the result of a query. If the desired information does
not exist, the optional variables remain unbound in the query result. UNION can
be used to define two alternative graph patterns where the query results must match
at least one of the patterns. A SPARQL query can also address several RDF graphs
"27"
"peter@abc.de"
Example SPARQL Query
SELECT *
WHERE {
{ ?person knows Peter
?person age ?age }
OPTIONAL { ?person mbox ?mb }
FILTER (?age >= 18)
}
age
mbox
knows
Peter
John
knows
knows
knows
Sarah
Bob
age
age
"17"
mbox
"32"
"bob@abc.de"
FIGURE 5.1
RDF graph and SPARQL query.
 
Search WWH ::




Custom Search