semantic web rdf website

Upload: gustavicich

Post on 04-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Semantic Web Rdf Website

    1/66

    Interoperabilityof Embedded Systems

    Introduction to Semantic Webtechnologies

    Postgraduate Degree inInformation Engineering

  • 8/13/2019 Semantic Web Rdf Website

    2/66

  • 8/13/2019 Semantic Web Rdf Website

    3/66

    What is RDF?

    RDF stands for Resource Description Framework

    RDF is a framework for describing resources on the web

    RDF is designed to be read and understood by computers

    RDF is not designed for being displayed to people RDF is a part of the W3C's Semantic Web Activity

    RDF is a W3C Recommendation since 2004

  • 8/13/2019 Semantic Web Rdf Website

    4/66

    RDF - Examples of Use

    RDF provides a common framework for expressinginformation so it can be exchanged between applicationswithout loss of meaning. Examples of use:

    Describing properties for shopping items, such as price andavailability

    Describing time schedules for web events

    Describing information about web pages (content, author, createdand modified date)

    Describing content and rating for web pictures

    Describing content for search engines

    Describing electronic libraries

    ...

  • 8/13/2019 Semantic Web Rdf Website

    5/66

    RDF is Written in XML?

    RDF is a data model

    Resources are identified using URIs

    Information is a set of statements (subject - predicate -object) Subject and predicate are always resources (i.e. identified by

    URIs)

    Objects may be URIs or literal

    Every RDF document corresponds to an oriented andlabeled graph

  • 8/13/2019 Semantic Web Rdf Website

    6/66

    RDF can be Written in XML

    Many serialization formats exist for the RDF data model:

    Notation 3 (N3)

    Turtle

    RDF/XML an XML-based syntax

    By using XML, RDF information can easily be exchanged betweendifferent types of computers using different types of operatingsystems and application languages

    During this course we will use the RDF/XML serialization format

  • 8/13/2019 Semantic Web Rdf Website

    7/66

    RDF and "The Semantic Web"

    The RDF language is a part of the W3C's SemanticWeb Activity

    W3C's "Semantic Web Vision" is a future where:

    Web information has exact meaning

    Web information can be understood and processed bycomputers

    Computers can integrate information from the web

  • 8/13/2019 Semantic Web Rdf Website

    8/66

    RDF is a W3C Recommendation

    RDF became a W3C Recommendation on February 2004

    RDF documents consists of set of triples defining a knowledge base

    Each triple have a subject a predicate and an object

    In RDF data sets each triple may belong to a named graph or to thedefault un-named graph.

  • 8/13/2019 Semantic Web Rdf Website

    9/66

    RDF Resource, Property, and PropertyValue

    RDF identifies things using Web identifiers ( URIs), and describes resources withproperties and property values

    This enables to represent RDF statements about resources as a graph of nodes andarcs representing the resources, and their properties and values

    A Resource is anything identified by a URI

    such as "http://www.w3.org/RDF/"

    A Property is a Resource that in triples is used to connect the subject with the object

    such as "http://example.org#author" or "http://www.example.com/homepage"

    A Property value is the value of a Property

    A literal such as Mario Rossi

    Or a resurce lice http:// www.arces.unibo.it "

    http://www.arces.unibo.it/http://www.arces.unibo.it/
  • 8/13/2019 Semantic Web Rdf Website

    10/66

    RDF URIs Unlike conventional hypertext, RDF URIs can refer to any identifiable

    thing

    including things that may not be directly retrievable on the Web

    RDF in addition to describing such things as Web pages can alsodescribe cars, businesses, people, news events, etc.

    In addition, RDF properties themselves have URIs, to preciselyidentify the relationships that exist between the linked items

    In RDF is also possible to define resources with unknown URI, thisresources are called blank nodes

  • 8/13/2019 Semantic Web Rdf Website

    11/66

    The following RDF document could describe the resource http://arces.it

    The example is simplified, rdf namespace is omitted

    RDF document and default namespace

    A set of statements begin

    Specify subject

    Subject

    Predicates

    Literal object

    Resource object

    RDF Resource, Property, and Property Value

    Mario Rossi

    http://www.unibo.it/home

    http://arces.it

    http://www.unibo.it/home

    Mario Rossi

    http://arces.it/http://arces.it/
  • 8/13/2019 Semantic Web Rdf Website

    12/66

    RDF Graphs

    The underlying structure of anyexpression in RDF is a collection oftriples

    each consisting of a subject, a

    predicate and an object A set of such triples form an RDF

    graph

    This can be illustrated by a node

    and directed -arc diagram in which each triple is

    represented as a node-arc-nodelink

  • 8/13/2019 Semantic Web Rdf Website

    13/66

    RDF Graphs The direction of the arc is

    significant: it always pointstoward the object

    The nodes of an RDF graph areits subjects and objects

    The assertion of an RDF triplesays that some relationship ,indicated by the predicate,holds between the thingsdenoted by subject and object

    The meaning of an RDFgraph is the conjunction(logical AND) of thestatements corresponding to

    all the triples it contains

  • 8/13/2019 Semantic Web Rdf Website

    14/66

    RDF Global Graph

    As Linked Data URIs are globally unique and can be dereferenced into sets of RDFtriples

    It is possible to imagine all LinkedData as one giant global graph

    Linked Data applications operate ontop of this giant global graph

    and retrieve parts of it bydereferencing URIs as required

    Merging is a very powerful feature of RDF

    Metadata may be defined by several(independent) parties and combinedby an application

  • 8/13/2019 Semantic Web Rdf Website

    15/66

    Blank nodes

    John Doe

    Mario Rossi

    http://ns#person_AC

    http://ns#person_AJohn Doe

    Mario Rossi

    http://ns#know

    http://ns#fullName>

    http://ns#homePage

    http://ns#fullName

  • 8/13/2019 Semantic Web Rdf Website

    16/66

    ReificationSyntactic sugar used:

    rdf:Statementrdf:subjectrdf:predicaterdf:object

    Given the triple < URI_sub, URI_pred, URI_obj> the reification is operated by creating a statementinstance and relating it to the subject, the predicate and the object of the statement to be reified. This

    allows to have a more abstract view of the knowledge base e.g. giving the possibility to assert that acertain statement is trustable or not.

    URI_sub URI_objURI_pred

    Ntriple syntax for reification _:statement_bn rdf:type rdf:Statement . _: statement_bn rdf:subject < URI_sub > . _: statement_bn rdf:predicate < URI_pred > . _: statement_bn rdf:object < URI_obj > .

    rdf:subject

    rdf:predicate

    rdf:object

    Rdf:Statementrdf:type

  • 8/13/2019 Semantic Web Rdf Website

    17/66

    RDF Example

    Suppose we have two records from a CD-list:

  • 8/13/2019 Semantic Web Rdf Website

    18/66

    RDF Example The first line of the RDF document is the

    XML declaration

    The XML declaration is followed by theroot element of RDF documents:

    The xmlns :rdf namespace , specifiesthat elements with the rdf prefix arefrom the namespace"http://www.w3.org/1999/02/22-rdf-syntax-ns#".

    The xmlns :cd namespace , specifiesthat elements with the cd prefix arefrom the namespace"http://www.recshop.fake/cd#".

    The element containsthe description of the resource identifiedby the rdf :about attribute

    The elements: ,, , etc. areproperties of the resource.

  • 8/13/2019 Semantic Web Rdf Website

    19/66

    RDF Example

    The graphical view of the RDF document:

  • 8/13/2019 Semantic Web Rdf Website

    20/66

    The Element

    is the root element of an RDF document

    It defines the XML document to be an RDF document

    It also contains a reference to the RDF namespace:

  • 8/13/2019 Semantic Web Rdf Website

    21/66

    The Element

    The < rdf :Description > element may identify the subjectresource with the about attribute

    It contains statements that describe the subject

  • 8/13/2019 Semantic Web Rdf Website

    22/66

    The Element

    The elements, artist, country, company, price, and year, are defined in thehttp://www.recshop.fake/cd# namespace

    This namespace is outside RDF (and not a part of RDF)

    The elements, artist, country, company, price, and year, must be defined by someoneelse (company, organization, person, etc. )

  • 8/13/2019 Semantic Web Rdf Website

    23/66

    Properties as Attributes

    The property elements can also be defined aspredicates

  • 8/13/2019 Semantic Web Rdf Website

    24/66

    Properties as Resources

    The statements objects can also be existingresources

    In the example, the property cd:artist identifies the

    object through the rdf:resource attribute

  • 8/13/2019 Semantic Web Rdf Website

    25/66

    The RDF Container Element

    RDF Container classes:

    rdf :Bag

    rdf :Seq

    rdf :Alt

    Note - We will talk about RDFS (RDF Schema) Vocabulary

    Description Language later Now let's focus on container elements

  • 8/13/2019 Semantic Web Rdf Website

    26/66

    The Element

    The < rdf :Bag> element is asubclass of rdfs:Container

    It is used to describe a list ofvalues that do not have to be ina specific order

    It may contain duplicate values

  • 8/13/2019 Semantic Web Rdf Website

    27/66

    The Element

    The < rdf :Seq > element is asubclass of rdfs:Container

    It is used to describe anordered list of values

    (for example inalphabetical order)

    It may contain duplicate

    values

  • 8/13/2019 Semantic Web Rdf Website

    28/66

    The Element

    It is used to describe a list ofalternative values

    the user is supposed to selectonly one of the values

    The first member of thecontainer the value of therdf:_1 property, is the default choice.

  • 8/13/2019 Semantic Web Rdf Website

    29/66

    RDF Terms

    In the previous examples we have talked about "listof values" when describing the container elements

    In RDF these "values" are called members

    So, we have the following:

    A container is a resource that contains things

    The contained things are called members

  • 8/13/2019 Semantic Web Rdf Website

    30/66

  • 8/13/2019 Semantic Web Rdf Website

    31/66

    The rdf:parseType="Collection" Attribute

    RDF List

  • 8/13/2019 Semantic Web Rdf Website

    32/66

    RDF ListOrdered opened and closed (using rdf:nil ) lists are represented in RDF through

    rdf:List rdf:first rdf:rest rdf:nil

    The example below represents the ordered and closed list 3, 2, 1.

    23 1

    _b1 _b2 _b3 rdf:nil

    rdf:first

    rdf:rest rdf:rest

    rdf:List

    rdf:type

    rdf:rest

  • 8/13/2019 Semantic Web Rdf Website

    33/66

    RDF Schema (RDFS)

    RDF Schema (RDFS) is an extension to RDF

    W3C references:

    Primer: http://www.w3.org/TR/2004/REC-rdf-primer-20040210/

    Concepts: http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/

    Syntax: http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/

    Semantics: http://www.w3.org/TR/2004/REC-rdf-mt-20040210/

    Vocabulary: http://www.w3.org/TR/2004/REC-rdf-schema-20040210/

    Test Cases: http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/

    http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-schema-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-mt-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/http://www.w3.org/TR/2004/REC-rdf-primer-20040210/
  • 8/13/2019 Semantic Web Rdf Website

    34/66

    RDF Schema

    RDF describes resources with properties, and values

    RDF is domain -independent

    RDF user communities need the ability to define

    application-specific classes and properties RDF Schema provides a mechanism for describing specific

    domains

  • 8/13/2019 Semantic Web Rdf Website

    35/66

    RDF Schema

    RDF Schema

    variously abbreviated as RDFS, RDF(S), RDF-S, or RDF/S

    is a set of classes and properties

    provides basic elements for the description ofontologies, otherwise called RDF vocabularies , intendedto structure RDF resources

    RDF Schema provides a type system for RDF

  • 8/13/2019 Semantic Web Rdf Website

    36/66

    RDF Schema

    The resources in the RDF Schema vocabulary have URI referenceswith the namespace

    http://www.w3.org/2000/01/rdf-schema#

    conventionally associated with the prefix rdfs:

    Vocabulary descriptions (schemas) written in the RDF Schemalanguage are legal RDF graphs

    RDF software that is not written to also process the additional RDFSchema vocabulary can still interpret a schema as a legal RDF graph consisting of various resources and properties

    But it will not "understand" the additional built-in meanings of theRDF Schema terms

  • 8/13/2019 Semantic Web Rdf Website

    37/66

    RDFS schema vocabulary: classes

    rdfs Resource: the class of everything

    rdfs Class: the class of all classes

    rdfs Literal: the class of literal values

    rdfs Datatype: the class of data types

    rdfs Container: the class of rdf containers i.e. rdf:Bag, rdf:Seq, rdf:Alt

    rdfs ContainerMembershipProperty: the class of rdf selectors i.e. the properties rdf:_1, rdf:_2, ...

    Classes describe abstract concepts or categories or set to which individualmay belong. An individual is bound to the classes it belongs to through the rdf:type property

    RDFS schema vocabulary: properties

  • 8/13/2019 Semantic Web Rdf Website

    38/66

    rdfs domain defines the domain of a property

    rdfs range: defines the range of a property

    rdfs subClassOf: associates a class with its super-class

    rdfs subPropetyOf: associates a property with its super-property

    rdfs member: superproperty of rdf:_1, rdf:_2, etc.rdfs label: associates a resource to a human readable label

    rdfs comment: ssociatres a resource to a human readable description

    rdfs seeAlso: associates a resource to another one which provides additional detai

    rdfs isDefinedBy: associates a resource to another one which provides the definition.

    RDFS schema vocabulary: properties

    Properties are relationships defined in the domain terminology and used tospecify domain assertions in the form of triples. Properties are represented aslabeled arcs when drawing of an RDF documents and the are always orientedtowards the statement object

  • 8/13/2019 Semantic Web Rdf Website

    39/66

    Classes

    The rdfs :subClassOf property may be used to statethat one class is a subclass of another

    Example

    In order to define a student class as a subclass of theclass person, you have to specify the statement:

    Classes

  • 8/13/2019 Semantic Web Rdf Website

    40/66

    The class rdfs :Literal is the class of literal values such as strings andintegers

    rdfs:Literal is an instance of rdfs:Class

    rdfs:Literal is a subclass of rdfs:Resource

    rdfs :Datatype is the class of datatypes

    All instances of rdfs:Datatype correspond to the RDF model of adatatype

    rdfs:Datatype is both an instance of and a subclass of rdfs:Class

    Each instance of rdfs:Datatype is a subclass of rdfs:Literal

  • 8/13/2019 Semantic Web Rdf Website

    41/66

    Properties

    Properties are instances of the class rdf :Property anddescribe a relation between subject resources and objectresources

    rdfs :range is an instance of rdf:Property that defines thesuper-class of the values of a property

    rdfs :domain is an instance of rdf:Property that is used todefine the super-class of the possible subjects for a given

    property

  • 8/13/2019 Semantic Web Rdf Website

    42/66

    Properties

    Example

    The property #attends can be used in statements whose subject

    belongs to the class #student and whose object belong to he class#course

  • 8/13/2019 Semantic Web Rdf Website

    43/66

    Containers

    RDF containers are resources that are used torepresent collections

    The rdfs :Container class is a super-class of the RDF

    Container classes (discussed earlier) rdf:Bag

    rdf:Seq

    rdf:Alt

    ll

  • 8/13/2019 Semantic Web Rdf Website

    44/66

    Collections

    RDF containers are open The RDF Collection vocabulary of classes and properties can describe

    a closed collection

    A collection is represented as a list of items

    rdf:List - used to build descriptions of lists and other list-likestructures (it is an instance of rdf:Class)

    rdf:first (it is an instance of rdf:Property)

    rdf:rest (it is an instance of rdf:Property)

    rdf:nil (it is an instance of rdf:Property)

    Sh SPARQL i l

  • 8/13/2019 Semantic Web Rdf Website

    45/66

    Short SPARQL tutorial

    Plenty of resources and tutorial can be found on the web like on W3C siteand in http://www.cambridgesemantics.com/semantic-university/sparql-by-example

    SPARQL queries data represented as an oriented graph: very different from

    relational databases data model. Usage is simple but the approach of accessing a new data model can be

    something hard the first times.

    SPARQL 1.1 is in development, it will add many features to the original

    specification. Some of its parts are currently supported by major semanticweb frameworks like Jena

    The main resource to learn SPARL grammar is:http://www.w3.org/TR/rdf-sparql-query/#rGraphTerm

    Short SPARQL tutorial

    http://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-examplehttp://www.cambridgesemantics.com/semantic-university/sparql-by-example
  • 8/13/2019 Semantic Web Rdf Website

    46/66

    A SPARQL Query is pure text.

    Queries can be classified in

    SELECT ASK

    CONSTRUCT

    DESCRIBE

    The SPARQL results set can be represented in XML by using the XML schema provided byW3C to wrap the results of SELECT and ASK queries

    XML is not mandatory but often useful when representing results

    The WHERE Clause

  • 8/13/2019 Semantic Web Rdf Website

    47/66

    The WHERE clause is the most important to be understood.

    It contains an abstract description of a graph calledGroupGraphPattern in the official grammar description

    Besides the operators defined on graphs is important to understandthat the basic expressive unit is that of the triples.

    Triples are specified with subject, predicate and object separated byspaces

    The WHERE Clause

  • 8/13/2019 Semantic Web Rdf Website

    48/66

    Triples are separated by .

    There are shortcuts to express triples with recurring subjects orobject by using ; and ,

    ; after the subject tell that couples of predicates and objects willfollw, sharing the same subject

    , after an object tell that another objects will follow sharing thesame subject and predicate

    The WHERE Clause

  • 8/13/2019 Semantic Web Rdf Website

    49/66

    IRI are eclosed between

    Qualified names does't need enclosing characters

    Strings are double quoted other data types may be not, in general theliterals are represented in this way: quoted_literal^^IRI details

    Details in the suggested internet address

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    50/66

    Initial knowledge base:

    Subject Predicate Object

    http://ns#uri_0 http://ns#name Alfredo

    http://ns#uri_0 http://ns#home http://ns/Alf_home.html

    http://ns#uri_0 http://ns#role Adminhttp://ns#uri_0 http://ns#age 31

    http://ns#uri_1 http://ns#name John

    http://ns#uri_1 http://ns#role User

    http://ns#uri_1 http://ns#age 44

    SPARQL ExamplesSELECT ?a ?b ?c WHERE { ?a ?b ?c }

  • 8/13/2019 Semantic Web Rdf Website

    51/66

    SELECT ?a ?b ?c WHERE { ?a ?b ?c }

    This query defines the variable a, b and c, which in the query must be

    preceded by ? or $ and then specifies in the WHERE clause thegraph pattern against which all the triples will be matched, eachtriple matching the graph pattern is included in the results. In thiscase all the triples match so the result will be the entire data set, if wesuppose N stated triples:

    a b c

    http://ns#uri_0 http://ns#name Alfredo

    http://ns#uri_0 http://ns#home http://ns/Alf_home.html

    http://ns#uri_0 http://ns#role Admin

    http://ns#uri_0 http://ns#age 31

    http://ns#uri_1 http://ns#name John

    http://ns#uri_1 http://ns#role User

    http://ns#uri_1 http://ns#age 44

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    52/66

    SELECT ?a WHERE { ?a ?b ?c } variables in the SELECT clause are theones included in the result set

    a

    http://ns#uri_0

    http://ns#uri_0

    http://ns#uri_0

    http://ns#uri_0

    http://ns#uri_1

    http://ns#uri_1

    http://ns#uri_1

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    53/66

    The triples in the WHERE clause are considered in a conjunctive wayby default: SELECT ?a ?b ?c WHERE { ?a ?b ?c . ?a ?c}

    a b chttp://ns#uri_0 http://ns#name Alfredo

    http://ns#uri_1 http://ns#name John

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    54/66

    Disjunction is obtained through the UNION pattern

    SELECT ?a ?c WHERE { { ?a ?c } UNION { ?a ?c } }

    a c

    http://ns#uri_0 Alfredo

    http://ns#uri_0 31

    http://ns#uri_1 John

    http://ns#uri_1 44

    SPARQL ExamplesFiltering is used to restrict the admitted values of

  • 8/13/2019 Semantic Web Rdf Website

    55/66

    Filtering is used to restrict the admitted values ofliterals

    SELECT ?a ?c WHERE { { ?a ?c }UNION { ?a ?c . FILTER regex(?c,John ) } }

    Many filtering options available, readdocumentation for detail

    a c

    http://ns#uri_0 Alfredohttp://ns#uri_0 31

    http://ns#uri_1 John

    http://ns#uri_1 44

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    56/66

    Optional patterns can be specified with the OPTIONALkeyword

    SELECT ?a ?c ?d WHERE { { ?a ?c } UNION {?a ?c} . OPTIONAL { ?a ?d } }

    a c d

    http://ns#uri_0 Alfredo http://ns/Alf_home.html

    http://ns#uri_0 31 http://ns/Alf_home.html

    http://ns#uri_1 John

    http://ns#uri_1 44

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    57/66

    ASK queries are used to receive the information if at leastone solution exists for the specified patterns

    ASK WHERE { { ?a ?c } UNION { ?a ?b } }

    true

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    58/66

    CONSTRUCT queries specifies at least two graph patterns: one is atemplate in which are present variables, like in a WHERE clause, butthe data set is not queried against this graph pattern. The second is anormal WHERE clause.

    What happens is that the data are queried against the WHERE clauseand the value of the variables, for each solution, are substituted into

    the template and the resulting graph (template with substitutedvalues) is returned as a query answer.

    Construct { ?a ?c } WHERE { { ?c ?a }

    SPARQL ExamplesDESCRIBE queries return an RDF graph representing a description of

  • 8/13/2019 Semantic Web Rdf Website

    59/66

    DESCRIBE queries return an RDF graph representing a description ofthe specified resource.

    The description is built using the rules decided by the SPARQL endpoint manager, there is no standard defining it

    DESCRIBE

    http://ns#Alf_home.htmlAdmin31Alfredo

    This is a possible response(by ARQ libraries)

    SPARQL Examples

  • 8/13/2019 Semantic Web Rdf Website

    60/66

    DESCRIBE ?x WHERE { ?x ?y }

    This is a possible response(by ARQ libraries)

    User44John

    http://ns/Alf_home.htmlAdmin

    31Alfredo

    SPARQL

  • 8/13/2019 Semantic Web Rdf Website

    61/66

    SPARQLOther samples

    Subquery : a SPARQL 1.1 query feature (not standardized yet)Select ?a ?b where { ?a ?b . { Select ?a Where { ?a ?c } } }

    a b

    http://ns#uri_0 31

    I want URI and age only for that URI with an associated home

    SPARQL

  • 8/13/2019 Semantic Web Rdf Website

    62/66

    Aggregates and Groups : a SPARQL 1.1 query feature (not standardized yet)

    We add to the knowledge base:

    Select (SUM(STRLEN(?b)) as ?RolesLenght) where { ?a ?b } Having (SUM(STRLEN(?b)) >0 )

    Select (SUM(STRLEN(?b)) as ?RolesLenght) where { ?a ?b } Group by ?bHaving ( SUM(STRLEN(?b)) >0 )

    Q

    Subject Predicate Object

    http://ns#uri_2 http://ns#name Mark

    http://ns#uri_2 http://ns#role User

    RolesLenght

    13The response is a single group of resultson which the functions STRLEN and SUMare Applied.

    RolesLenght

    8

    5

    The response is made up of as manygroups as the number of different roles.The STRLEN and SUM functions are

    applied separately on each group

    SPARQL

  • 8/13/2019 Semantic Web Rdf Website

    63/66

    QNegation:

    Many possible approaches such as

    OPTIONAL + !BOUND :Select ?a ?c Where { ?a ?c . Optional { ?a ?b } . Filter (!Bound(?b))

    a c

    http://ns#uri_1 John

    http://ns#uri_2 Mark

    I want URI and name only for that URI without an associated home.This solution is valid in standard SPARQL

    Not exists:Select ?a ?c Where { ?a ?c . Filter not exists { ?a ?b } }

    a c

    http://ns#uri_1 John

    http://ns#uri_2 Mark

    Same objective and result, but with a feature of SPARQL 1.1 Querylanguage

    SPARQL

  • 8/13/2019 Semantic Web Rdf Website

    64/66

    Q

    In this short tutorial we will not investigate the support for other features ofSPARQL among them the named graphs for which clear documentation can befound in the main documentation page. This because SIB versions currently doesn'tsupport natively them, so it is difficult to verify in concrete applications during thecourse

    http://www.w3.org/TR/rdf-sparql-query/

    RDF Summary

    http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/
  • 8/13/2019 Semantic Web Rdf Website

    65/66

    y

    RDF Schema (RDFS) provides basic vocabulary for RDF RDF also allows for the re -use , extendibility and

    refinement of established resource descriptionstandards since these will be available in machine -

    readable form Using RDFS it is for example possible to create

    hierarchies of classes and properties

    RDF knowledge bases can be queried using the SPARQLlanguage.

    Acknowledgments

  • 8/13/2019 Semantic Web Rdf Website

    66/66

    g

    This tutorial is based on the material developedwithin RECOCAPE, an FP7 international cooperationproject of the capacities programme.