Of 38 lecture 6: rdf – axiomatic semantics and query.

38
of 38 lecture 6: rdf – axiomatic semantics and query

Transcript of Of 38 lecture 6: rdf – axiomatic semantics and query.

Page 1: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38

lecture 6: rdf – axiomatic semantics and query

Page 2: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 2

RDF and RDFSaxiomatic semantics

the meaning of the modeling primitives of RDF and RDF Schema is being translated into first-order logic

it provides a basis for reasoning support by automated reasoners

Page 3: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 3

RDF and RDFSaxiomatic semantics - approach

language primitives are represented by constants:Resource, Class, Property, subClassOf, etc.

a few predefined predicates are used as for expressing relationships between the constants

Page 4: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 4

RDF and RDFSaxiomatic semantics - approach

variable names begin with “?”

all axioms are implicitly universally quantified

Page 5: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 5

PropVal(P, R, V)

a predicate with 3 arguments, is used to represent an RDF statement with resource R, property P and value V

an RDF statement (triple) (R, P, V) is represented as PropVal(P, R, V)

RDF and RDFS a.semanticsbasic predicates

Page 6: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38

RDFbasic ideas – statements (from lecture 4)

a triple:object-attribute-value

or in other words: resource-property-value

(values are resources or literals)

or subject-property-object

ece 720, winter ‘12 6

Page 7: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 7

Type(R, T)

short for PropVal(type, R, T) specifies that the resource R has the

type T

Type(?r, ?t) PropVal(type, ?r, ?t)

RDF and RDFS a.semanticsbasic predicates

Page 8: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 8

constants: Class, Resource, Property, Literal all classes are instances of Class

Type(Class,Class)Type(Resource,Class)Type(Property,Class)Type(Literal,Class)

RDF and RDFS a.semanticsclasses

Page 9: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 9

Resource is the most general class: every class and every property is a resource

Type(?p,Property) Type(?p,Resource)Type(?c,Class) Type(?c,Resource)

RDF and RDFS a.semanticsclasses (2)

Page 10: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 10

the predicate in an RDF statement must be a property

PropVal(?p,?r,?v) Type(?p,Property)

RDF and RDFS a.semanticsclasses (3)

Page 11: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 11

type is a property

Type(type, Property)

is equivalent to

PropVal(type, type, Property)

RDF and RDFS a.semanticstype property

Page 12: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 12

type can be applied to resources (domain) and has a class as its value (range)

Type(?r, ?c) (Type(?r, Resource) Type(?c, Class))

RDF and RDFS a.semanticstype property (2)

Page 13: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 13

subClassOf is a property

Type(subClassOf, Property)

= PropVal(type, subClassOf, Property)

RDF and RDFS a.semanticssubclass

Page 14: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 14

if a class C is a subclass of a class C', then all instances of C are also instances of C':

PropVal(subClassOf, ?c, ?c') (Type(?c, Class) Type(?c', Class) ?x (Type(?x, ?c) Type(?x, ?c')))

RDF and RDFS a.semanticssubclass

Page 15: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 15

subPropertyOf is a property

Type(subPropertyOf, Property)

= PropVal(type, subPropertyOf, Property)

RDF and RDFS a.semanticssubproperty

Page 16: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 16

P is a subproperty of P', if P'(x,y) is true whenever P(x,y) is true:

PropVal(subPropertyOf, ?p, ?p') (Type(?p, Property) Type(?p', Property)

?r ?v (PropVal(?p, ?r, ?v)

PropVal(?p', ?r, ?v)))

RDF and RDFS a.semanticssubproperty

Page 17: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 17

if the domain of P is D, then for every P(x,y), xD

PropVal(domain, ?p, ?d) ?x ?y (PropVal(?p, ?x, ?y) Type(?x, ?d))

RDF and RDFS a.semanticsdomain and range

Page 18: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 18

if the range of P is R, then for every P(x,y), yR

PropVal(range, ?p, ?r) ?x ?y (PropVal(?p, ?x, ?y) Type(?y, ?r))

RDF and RDFS a.semanticsdomain and range

Page 19: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 19

can be used for automatic reasoning, but …

it needs first-order logic proof system to do so

RDF and RDFS a.semanticsissues

Page 20: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 20

semantics in terms of RDF triples instead of restating RDF in terms of first-order logicthe inference system consists of inference rules:

IF E contains certain triplesTHEN add to E certain additional triples

where E is an arbitrary set of RDF triples

RDF and RDFS semanticsinference rules

Page 21: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 21

IF E contains the triple (?x, ?p, ?y)THEN E also contains (?p, rdf:type, rdf:Property)

any resource ?p used in the property position can be inferred to be

a member of the class rdf:Property

RDF and RDFS semanticsinference rules – examples

Page 22: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 22

IF E contains the triples (?u, rdfs:subClassOf, ?v) and (?v,

rdfs:subClassOf, ?w)

THEN E also contains the triple (?u, rdfs:subClassOf, ?w)

encodes transitivity of the subclass relation

RDF and RDFS semanticsinference rules – examples

Page 23: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 23

IF E contains the triples (?x, rdf:type, ?u) and (?u, rdfs:subClassOf, ?v)

THEN E also contains the triple (?x, rdf:type, ?v)

RDF and RDFS semanticsinference rules – examples

Page 24: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 24

IF E contains the triples (?x, ?p, ?y) and (?p, rdfs:range, ?u)

THEN E also contains the triple (?y, rdf:type, ?u)

any resource ?y which appears as the value of a property ?p can be inferred to be a member of the range of ?p

(range definitions in RDF Schema are not used to restrict the range of a property, but rather to infer the membership of the range)

RDF and RDFS semanticsinference rules – examples

Page 25: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 25

XML query language (XPath) not suitable

SPARQL (SPARQL Protocol and RDF Query Language)is based on matching graph patterns

SPARQLa query language for RDF

Page 26: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 26

the simplest graph pattern is the triple pattern:like an RDF triple, but with the possibility of a variable instead of an RDF term in the subject, predicate, or object positions (?x, ?p, ?y)

combining triple patterns gives a basic graph pattern, where an exact match to a graph is needed to fulfill a pattern

SPARQLa query language for RDF

Page 27: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 27

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>SELECT ?cWHERE{

?c rdf:type rdfs:Class .}

this query retrieves all triple patterns, where:-the property is rdf:type-the object is rdfs:Class - it retrieves all

classes

SPARQLexample

Page 28: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 28

to retrieve all instances of a particular class (e.g. course) :(declaration of rdf, rdfs prefixes omitted for brevity)

PREFIX uni: <http://www.mydomain.org/uni-ns#>SELECT ?iWHERE{

?i rdf:type uni:course .}

SPARQLexample (2)

Page 29: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 29

SELECT specifies the projection: the number and order of retrieved data

FROM is used to specify the source being queried (optional)

WHERE imposes constraints on possible solutions in the form of graph pattern templates and boolean constraints

SPARQLselect-from-where – query structure

Page 30: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 30

retrieve all phone numbers of staff members

SELECT ?x ?yWHERE { ?x uni:phone ?y .}

here ?x and ?y are variables, and ?x uni:phone ?y represents a resource-property-value triple pattern

SPARQLselect-from-where

Page 31: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 31

we restrict the second pattern only to those triples, the resource of which is in the variable ?x(a semicolon indicates that the following triple shares its subject with the previous one)

retrieve all lecturers and their phone numbers:

SELECT ?x ?yWHERE

{ ?x rdf:type uni:Lecturer ;

uni:phone ?y . }

SPARQLimplicit join

Page 32: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 32

the previous query is equivalent to

SELECT ?x ?yWHERE{

?x rdf:type uni:Lecturer .?x uni:phone ?y .

}

SPARQLimplicit join (2)

Page 33: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 33

retrieve the name of all courses taught by the lecturer with ID 949352

SELECT ?nWHERE{

?x rdf:type uni:Course ;uni:isTaughtBy :949352 .

?c uni:name ?n .FILTER (?c = ?x) .

}

SPARQLexplicit join

Page 34: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38

<uni:lecturer rdf:about=“949352”><uni:name>Mike Knight</uni:name>

</uni:lecturer>

<uni:professor rdf:about=“94318”><uni:name>John Smith</uni:name><uni:email>[email protected]</uni:email>

</uni:professor>

one “has” only name, the other “has” name and email address

ece 720, winter ‘12 34

SPARQLoptional patterns

Page 35: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38

if we ask for lecturers and their email addresses

SELECT ?name ?emailWHERE{ ?x rdf:type uni:Lecturer ;

uni:name ?name ;uni:email ?email .

}

the result: John Smith, [email protected]

ece 720, winter ‘12 35

SPARQLoptional patterns (2)

Page 36: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38

as a solution we can adapt the query to use an optional pattern

SELECT ?name ?emailWHERE{ ?x rdf:type uni:Lecturer ;

uni:name ?name .OPTIONAL { x? uni:email ?email }

}

the result: Mike Knight, John Smith, [email protected]

ece 720, winter ‘12 36

SPARQLoptional patterns (3)

Page 37: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 37

provides a foundation for representing and processing metadata

has a graph-based data model

has an XML-based syntax

allows incremental building of knowledge, and its sharing and reuse

is domain independent

RDFsummary

Page 38: Of 38 lecture 6: rdf – axiomatic semantics and query.

of 38ece 720, winter ‘12 38

RDF Schema is a primitive ontology language (offers certain modelling primitives with fixed meaning)

key concepts of RDF Schema are class, subclass relations, property, subproperty relations, and domain and range restrictions

there arequery languages for RDF and RDFS, including SPARQL

RDFSsummary