Download presentation
Presentation is loading. Please wait.
Published byAnnabelle Gilbert Modified over 8 years ago
1
Lecture 8: RDF& SPARQL Dr. Taysir Hassan A. Soliman December 13, 2015 INF411 Information Engineering Information Systems Dept. Faculty of Computers & Information
2
Agenda Semantic web 3.0 RDF SPARQL
3
(In)famous “Layer Cake” Data Exchange Semantics+reasoning Relational Data ? ? ??? Relationship between layers is not clear Uniform Resource Identifier (URI) is a string of characters used to identify the name of a resource. stringcharactersidentifyresource NS – Name Space – OWL DL extends “DL subset” of RDF
4
4 Semantic Web Content: New “Users” applications agents
5
Semantic web The Semantic Web is an extension of the Web through standards by the World Wide Web Consortium (W3C).WebWorld Wide Web Consortium The standards promote common data formats and exchange protocols on the Web, most fundamentally the Resource Description Framework (RDF).WebResource Description Framework
6
According to the W3C, "The Semantic Web provides a common framework that allows data to be shared and reused across application, enterprise, and community boundaries“ The term was coined by Tim Berners-Lee for a web of data that can be processed by machines.Tim Berners-Lee
7
Semantic Web 3.0 Technology Is connective intelligence; connecting data, concepts, applications and ultimately people. (Nova Spivack) Principally, the Semantic Web is a Web 3.0 web technology - a way of linking data between systems or entities that allows for rich, self-describing interrelations of data available across the globe on the web.
8
RIF is the W3C Rule Interchange Format. It's an XML language for expressing Web rules that computers can execute. RIF provides multiple versions, called dialects. It includes a RIF Basic Logic Dialect (RIF-BLD) and RIF Production Rules Dialect (RIF PRD).
9
Semantic Web Rule Language (SWRL) based on a combination of the OWL DL and OWL Lite sublanguages of the OWL Web Ontology Language with the Unary/Binary Datalog RuleML sublanguages of the Rule Markup Language.
10
How is it different ? Today, much of the data we get from the web is delivered to us in the form of web pages - HTML documents that are linked to each other through the use of hyperlinks. Humans or machines can read these documents, but other than typically seeking keywords in a page, machines have difficulty extracting any meaning from these documents themselves.
11
How do we represent the data? RDF is a common acronym within the semantic web community because it forms one of the basic building blocks for forming the web of semantic data. RDF defines graph database. Graph databases build the semantic web, globally.
12
12 XML: document = labelled tree course teachertitlestudents namehttp............... = XML Schema: grammars for describing legal trees and datatypes node = label + attr/values + contents So: why not use XML to represent semantics?
13
In XML: there must be a hierarchy Example of XML document Ahmed Khaled Reminder Don't forget our meeting on Friday!
14
Different kinds of Databases http://www.linkeddatatools.com/
15
Data Graph In a data graph, there is no concept of roots (or a hierarchy). A graph consists of resources related to other resources, with no single resource having any particular intrinsic importance over another. http://www.linkeddatatools.com/
16
An Example of a Data Graph Bengie is a dog. Bonnie is a cat. Bengie and Bonnie are friends.
17
two things - identified by "Thing 1" and "Thing 2" – have the properties name,animalType and friends With. we can see that "Thing 1"'s name is Bengie, and "Thing 2"'s name is Bonnie. "Thing 1" is a dog, and "Thing 2" is a cat. And finally, both are friends with each other (implied by the friendsWithproperty pointing in both directions).
18
RDF example The arrows in the above diagram are properties, sometimes in RDF terminology called predicates. Subject is the T-shirt Predicate (property) is the color Object is white
19
RDF, whilst the foundation of defining data structures for the semantic web, does not in itself describe the semantics, or meaning, behind the data http://www.linkeddatatools.com/
20
Graph Data The data are represented in RDF The metadata are in RDFS / OWL Query Syntax is SPARQL http://www.linkeddatatools.com/
21
Sharing with Semantic Web Models Vocabulary - A collection of terms given a well- defined meaning that is consistent across contexts. Ontology - Allows you to define contextual relationships behind a defined vocabulary. It is the cornerstone of defining a knowledge domain. A formal syntax for defining ontologies is OWL (Web Ontology Language) which is an extension to RDFS (RDF Schema).OWL (Web Ontology Language) http://www.linkeddatatools.com/
23
What is RDF? (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 written in XML RDF is a part of the W3C's Semantic Web Activity RDF is a W3C Recommendation from 10. February 2004
24
RDF is used for Describing properties for shopping items, such as price and availability Describing time schedules for web events Describing information about web pages (content, author, created and modified date) Describing content and rating for web pictures Describing content for search engines Describing electronic libraries http://www.w3.org/2009/Talks/0615-qbe/
25
RDF Resource, Property, and Property Value A Resource is anything that can have a URI, such as "http://www.w3schools.com/rdf" A Property is a Resource that has a name, such as "author" or "homepage" A Property value is the value of a Property, such as "Jan Egil Refsnes" or "http://www.w3schools.com" (note that a property value can be another resource) http://www.w3.org/2009/Talks/0615-qbe/
26
Jan Egil Refsnes http://www.w3schools.com
27
RDF Elements The main elements of RDF are the root element,, and the element, which identifies a resource. 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:
28
RDF Element...Description goes here...
29
Element The element identifies a resource with the about attribute. The element contains elements that describe the resource:
30
Bob Dylan UK Columbia 10.90 1985
31
The elements, artist, country, company, price, and year, are defined in the http://www.recshop.fake/cd# namespace. This namespace is outside RDF (and not a part of RDF). RDF defines only the framework. The elements, artist, country, company, price, and year, must be defined by someone else (company, organization, person, etc).
32
Properties as Attributes The property elements can also be defined as attributes (instead of elements):
33
Properties as Resources
34
RDF Containers RDF containers are used to describe group of things. The following RDF elements are used to describe groups:,, and.
35
The Element John Paul George Ringo
36
Element George John Paul Ringo
37
The Element CD Record Tape
38
RDF Schema and application classes RDF Schema (RDFS) is an extension to RDF. RDF describes resources with classes, properties, and values. In addition, RDF also needs a way to define application-specific classes and properties. Application-specific classes and properties must be defined using extensions to RDF.
39
RDF Schema (RDFS) RDF Schema does not provide actual application-specific classes and properties. Instead RDF Schema provides the framework to describe application-specific classes and properties. Classes in RDF Schema are much like classes in object oriented programming languages. This allows resources to be defined as instances of classes, and subclasses of classes.
40
Example of RDFS
41
What is Metadata ? Metadata is a term you will come across again and again when harnessing semantic web technologies. "Metadata" is not a complex term or concept - it simply means "data about data" (taken from the Greek meta- meaning "after").
42
Initiatives The Dublin Core Metadata Initiative (DCMI) has created some predefined properties for describing documents. RDF is metadata (data about data). RDF is used to describe information resources.
43
SPARQL SELECT ?title WHERE { ?title. } http://www.w3.org/TR/rdf-sparql-query/
44
44 Example q1 contains a query: SELECT ?x WHERE (?x,, "John Smith") The outcome is: x =============================
45
45 Example Return all the resources that have property FN and the associated values: SELECT ?x, ?fname WHERE (?x,, ?fname) The outcome is: x | fname ================================================ | "John Smith" | "Sarah Jones" | "Matt Jones"
46
46 Example Return the first name of Jones: SELECT ?givenName WHERE (?y,, "Jones"), (?y,, ?givenName) The outcome is: givenName ========= "Matthew" "Sarah"
47
47 URI Prefixes : USING RDQL has a syntactic convenience that allows prefix strings to be defined in the USING clause : SELECT ?x WHERE (?x, vCard:FN, "John Smith") USING vCard FOR SELECT ?givenName WHERE (?y, vCard:Family, "Smith"), (?y, vCard:Given, ?givenName) USING vCard FOR
48
48 Filters RDQL has a syntactic convenience that allows prefix strings to be defined in the USING clause : SELECT ?resource WHERE (?resource, info:age, ?age) AND ?age >= 24 USING info FOR
49
SPARQL SPARQL is a recursive acronym standing for – SPARQL Protocol and RDF Query Language It provides facilities to [Staab 2006]: – extract information in the form of URIs, blank nodes, plain and typed literals. – extract RDF subgraphs. – construct new RDF graphs based on information in the queried graphs
50
SPARQL A SPARQL query comprises, in order: Prefix declarations, for abbreviating URIs Dataset definition, stating what RDF graph(s) are being queried A result clause, identifying what information to return from the query The query pattern, specifying what to query for in the underlying dataset Query modifiers, slicing, ordering, and otherwise rearranging query results
51
Results of SPARQL queries The results of SPARQL queries can be returned and/or rendered in a variety of formats:XML. SPARQL specifies an XML vocabulary for returning tables of results.XML vocabulary JSON. A JSON "port" of the XML vocabulary, particularly useful for Web applications.JSON "port" RDF. Certain SPARQL result clauses trigger RDF responses, which in turn can be serialized in a number of ways (RDF/XML, etc.)RDF/XML
52
HTML. When using an interactive form to work with SPARQL queries. Often implemented by applying an XSL transform to XML results.
53
Dataset: Friend of a Friend (FOAF) FOAF is a standard RDF vocabulary for describing people and relationships FOAF FOAF integrates three kinds of network: social networks of human collaboration, friendship and association; representational networks that describe a simplified view of a cartoon universe in factual terms, and information networks that use Web-based linking to share independently published descriptions of this inter-connected world. @prefix foaf:
54
Graph Patterns Basic Graph Pattern – set of Triple Patterns Group Pattern - a set of graph patterns must all match Value Constraints - restrict RDF terms in a solution Optional Graph Patterns.- additional patterns may extend the solution Alternative Graph Pattern – two or more possible patterns are tried Patterns on Named Graphs - patterns are matched against named graphs
55
Basic Graph Pattern Set of Triple Patterns – Triple Pattern – similar to an RDF Triple (subject, predicate, object), but any component can be a query variable; literal subjects are allowed – Matching a triple pattern to a graph: bindings between variables and RDF Terms Matching of Basic Graph Patterns – A Pattern Solution of Graph Pattern GP on graph G is any substitution S such that S(GP) is a subgraph of G. xv rdf:typerdf:Property rdf:type rdf:type rdf:Property SELECT ?x ?v WHERE { ?x ?x ?v } ?book dc:title ?title
56
Basic Graph Pattern - Multiple Matches PREFIX foaf: SELECT ?name ?mbox WHERE { ?x foaf:name ?name. ?x foaf:mbox ?mbox } @prefix foaf:. _:a foaf:name "Johnny Lee Outlaw". _:a foaf:mbox. _:b foaf:name "Peter Goodguy". _:b foaf:mbox. namembox "Johnny Lee Outlaw" "Peter Goodguy" Group Graph Pattern (set of graph patterns) also! Data Query Query Result
57
Basic Graph Pattern - Blank Nodes PREFIX foaf: SELECT ?x ?name WHERE { ?x foaf:name ?name } @prefix foaf:. _:a foaf:name "Alice". _:b foaf:name "Bob". xname _:c“Alice“ _:d“Bob” Data Query Query Result
58
Graph Patterns Basic Graph Pattern – set of Triple Patterns Group Pattern - a set of graph patterns must all match Value Constraints - restrict RDF terms in a solution Optional Graph Patterns.- additional patterns may extend the solution Alternative Graph Pattern – two or more possible patterns are tried Patterns on Named Graphs - patterns are matched against named graphs
59
Group Pattern PREFIX foaf: SELECT ?name ?mbox WHERE { ?x foaf:name ?name. ?x foaf:mbox ?mbox } PREFIX foaf: SELECT ?name ?mbox WHERE { {?x foaf:name ?name; foaf:mbox ?mbox } }
60
Graph Patterns Basic Graph Pattern – set of Triple Patterns Group Pattern - a set of graph patterns must all match Value Constraints - restrict RDF terms in a solution Optional Graph Patterns.- additional patterns may extend the solution Alternative Graph Pattern – two or more possible patterns are tried Patterns on Named Graphs - patterns are matched against named graphs
61
Value Constraints PREFIX dc: PREFIX ns: SELECT ?title ?price WHERE { ?x ns:price ?price. FILTER ?price < 30. ?x dc:title ?title. } @prefix dc:. @prefix :. @prefix ns:. :book1 dc:title "SPARQL Tutorial". :book1 ns:price 42. :book2 dc:title "The Semantic Web". :book2 ns:price 23. titleprice "The Semantic Web"23 Data Query Query Result
62
62 Regular expressions can be used PREFIX dc: PREFIX ldap: PREFIX foaf: SELECT ?name ?name2 { ?doc dc:title ?title. FILTER regex(?title, “SPARQL”). ?doc dc:creator ?reseacher. ?researcher ldap:email ?email. ?researcher ldap:name ?name } “Find the name and email addresses of authors of a paper about SPARQL”
63
Graph Patterns Basic Graph Pattern – set of Triple Patterns Group Pattern - a set of graph patterns must all match Value Constraints - restrict RDF terms in a solution Optional Graph Patterns.- additional patterns may extend the solution Alternative Graph Pattern – two or more possible patterns are tried Patterns on Named Graphs - patterns are matched against named graphs
64
Optional graph patterns PREFIX dc: PREFIX ns: SELECT ?title ?price WHERE { ?x dc:title ?title. OPTIONAL { ?x ns:price ?price. FILTER ?price < 30 }} @prefix dc:. @prefix :. @prefix ns:. :book1 dc:title "SPARQL Tutorial". :book1 ns:price 42. :book2 dc:title "The Semantic Web". :book2 ns:price 23. titleprice “SPARQL Tutorial“ "The Semantic Web"23 Data Query Query Result
65
Multiple Optional Blocks PREFIX foaf: SELECT ?name ?mbox ?hpage WHERE { ?x foaf:name ?name. OPTIONAL { ?x foaf:mbox ?mbox }. OPTIONAL { ?x foaf:homepage ?hpage } } @prefix foaf:. @prefix rdf:. @prefix rdfs:. _:a foaf:name "Alice". _:a foaf:homepage. _:b foaf:name "Bob". _:b foaf:mbox. Data Query Query Result nameMboxhpage “Alice“ “Bob“
66
Graph Patterns Basic Graph Patterns – set of Triple Patterns Group Patterns - a set of graph patterns must all match Value Constraints - restrict RDF terms in a solution Optional Graph Patterns.- additional patterns may extend the solution Alternative Graph Patterns – two or more possible patterns are tried Patterns on Named Graphs - patterns are matched against named graphs
67
Alternative Graph Patterns PREFIX dc10: PREFIX dc11: SELECT ?x ?y WHERE { { ?book dc10:title ?x } UNION { ?book dc11:title ?y } } @prefix dc10:. @prefix dc11:. _:a dc10:title "SPARQL Query Language Tutorial". _:b dc11:title "SPARQL Protocol Tutorial". _:c dc10:title "SPARQL". _:c dc11:title "SPARQL (updated)". Data Query Query Result xy "SPARQL (updated)" "SPARQL Protocol Tutorial" "SPARQL" "SPARQL Query Language Tutorial"
68
© Copyright 2001 -2006 TopQuadrant Inc., “Semantic Technology and EA”, slide 68 This is an Example of Ontology within an Enterprise
69
References http://www.w3.org/2009/Talks/0615-qbe/ Protege Ontology Libraries http://protegewiki.stanford.edu/index.php/Protege_Ontology_Library Protege tutorial http://www.co-ode.org/resources/tutorials/ Protege Website http://protege.stanford.edu/doc/users.html http://protege.stanford.edu/ http://www.linkeddatatools.com/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.