Lec06 Rdfsquery
Lec06 Rdfsquery
axiomatic semantics
a few predefined predicates are used as for all axioms are implicitly universally quantified
expressing relationships between the constants
PropVal(P, R, V) a triple:
object-attribute-value
! a predicate with 3 arguments, is used to or in other words:
represent an RDF statement with resource R, resource-property-value
property P and value V (values are resources or literals)
! an RDF statement (triple) (R, P, V) is or
represented as PropVal(P, R, V) subject-property-object
Resource is the most general class: every class the predicate in an RDF statement must be a
and every property is a resource property
Type(subClassOf, Property)
PropVal(subClassOf, ?c, ?c') ↔
= PropVal(type, subClassOf, Property) (Type(?c, Class) ∧ Type(?c', Class) ∧
∀?x (Type(?x, ?c) → Type(?x, ?c')))
Type(subPropertyOf, Property)
PropVal(subPropertyOf, ?p, ?p') ↔
= PropVal(type, subPropertyOf, Property) (Type(?p, Property) ∧ Type(?p', Property) ∧
∀?r ∀?v (PropVal(?p, ?r, ?v) →
PropVal(?p', ?r, ?v)))
if the domain of P is D, then for every P(x,y), x∈D if the range of P is R, then for every P(x,y), y∈R
THEN E also contains the triple (?x, rdf:type, ?v) THEN E also contains the triple (?y, rdf:type, ?u)
XML query language (XPath) not suitable the simplest graph pattern is the triple pattern:
like an RDF triple, but with the possibility of a
SPARQL variable instead of an RDF term in the subject,
predicate, or object positions (?x, ?p, ?y)
(SPARQL Protocol and RDF Query Language)
is based on matching graph patterns
combining triple patterns gives a basic graph pattern,
where an exact match to a graph is needed to fulfill
a pattern
SPARQL SPARQL
example example (2)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> to retrieve all instances of a particular class (e.g. course) :
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> (declaration of rdf, rdfs prefixes omitted for brevity)
SELECT ?c
WHERE
PREFIX uni: <http://www.mydomain.org/uni-ns#>
{
SELECT ?i
?c rdf:type rdfs:Class . WHERE
} {
?i rdf:type uni:course .
this query retrieves all triple patterns, where: }
-the property is rdf:type
-the object is rdfs:Class - it retrieves all classes
SPARQL SPARQL
select-from-where – query structure select-from-where
we restrict the second pattern only to those triples, the resource of the previous query is equivalent to
which is in the variable ?x
(a semicolon indicates that the following triple shares its subject with the
previous one) SELECT ?x ?y
WHERE
retrieve all lecturers and their phone numbers: {
?x rdf:type uni:Lecturer .
SELECT ?x ?y
WHERE ?x uni:phone ?y .
}
{ ?x rdf:type uni:Lecturer ;
uni:phone ?y . }
SPARQL SPARQL
explicit join optional patterns
retrieve the name of all courses taught by the lecturer with ID 949352 <uni:lecturer rdf:about= 949352 >
<uni:name>Mike Knight</uni:name>
</uni:lecturer>
SELECT ?n
WHERE <uni:professor rdf:about= 94318 >
{ <uni:name>John Smith</uni:name>
?x rdf:type uni:Course ; <uni:email>[email protected]</uni:email>
uni:isTaughtBy :949352 . </uni:professor>
?c uni:name ?n .
FILTER (?c = ?x) . one has only name, the other has name and email address
}
SPARQL SPARQL
optional patterns (2) optional patterns (3)
if we ask for lecturers and their email addresses as a solution we can adapt the query to use an optional pattern
! provides a foundation for representing and ! RDF Schema is a primitive ontology language
processing metadata (offers certain modelling primitives with fixed
meaning)
! has a graph-based data model
! key concepts of RDF Schema are class, subclass
! has an XML-based syntax relations, property, subproperty relations, and
! allows incremental building of knowledge, and its domain and range restrictions
sharing and reuse ! there arequery languages for RDF and RDFS,
! is domain independent including SPARQL