Download presentation
Presentation is loading. Please wait.
Published byVanessa Austin Modified over 9 years ago
1
Database Management Systems Course 236363 Faculty of Computer Science Technion – Israel Institute of Technology Lecture 10: RDF and SPARQL
2
The Semantic Web 2 “The Semantic Web is an extension of the current web in which information is given well-defined meaning, better enabling computers and people to work in cooperation.” Tim Berners-Lee, James Hendler and Ora Lassila, Scientific American, May 2001 “The Web was designed as an information space, with the goal that it should be useful not only for human-human communication, but also that machines would be able to participate and help. One of the major obstacles to this has been the fact that most information on the Web is designed for human consumption, and even if it was derived from a database with well defined meanings (in at least some terms) for its columns, that the structure of the data is not evident to a robot browsing the web. Leaving aside the artificial intelligence problem of training machines to behave like people, the Semantic Web approach instead develops languages for expressing information in a machine processable form.” Tim Berners-Lee, Semantic Web Road map, 1998
3
3 More Technically... Vision: Web data will entail semantics in a manner that is understood (and processed, and linked) automatically by computers The “Semantic Web” is the technical infrastructure –Unambiguous names for resources that may also bind data to real world objects (URI) –A common data model to describe/link resources (RDF) –Expressive language to access to data (SPARQL) –Languages for defining common vocabularies and rules for automated reasoning (e.g., politician is person) (RDFS, OWL) Data providers should collaborate: properly publish their data and link it to existing data
4
RDF and SPARQL Recommendations RDF –“Resource Description Framework” –1997: first public draft; 1999: recommendation (revised 2004); 2014: RDF1.1 SPARQL –Query language for RDF –“SPARQL Protocol and RDF Query Language” Yes, recursive definition –2004: first public draft; 2008: recommendation; 2013: SPARQL1.1 4
5
Some Freely Available RDF Repositories DBPedia (~1.2b triples) –“a crowd-sourced community effort to extract structured information from Wikipedia and make this information available on the Web” Freebase (~340m triples) –“A community-curated DB of well-known people, places, and things” DBLP (~58m triples) –Computer science bibliography WordNet (~3m triples) –English lexical db: synonyms, antonyms, POS,... GeoNames (~94m triples) –“Covers all countries, contains over eight million placenames” Yago (~120m triples) –Information from Wikipedia, Wordnet, Geonames 5
6
There’s More! Linked! 6 http://lod-cloud.net/
7
RDF Example from DBPedia 7 http://dbpedia.org/resource/ Technion_Israel_Institute_of_ Technology 13253 http://dbpedia.org/ property/students http://dbpedia.org/ property/president http://dbpedia.org/reso urce/Peretz_Lavie http://dbpedia.org/ ontology/birthYear 1949 http://dbpedia.org/ ontology/birthPlace http://dbpedia.org/reso urce/Petah_Tikva http://dbpedia.org/ ontology/birthPlace http://dbpedia.org/reso urce/Israel http://dbpedia.org/ ontology/country
8
In XML Syntax 8 http://dbpedia.org/resource/ Technion_Israel_Institute_of_ Technology http://dbpedia.org/page/Technion_–_Israel_Institute_of_Technology 13253 http://dbpedia.org/ property/students http://dbpedia.org/ property/president http://dbpedia.org/reso urce/Peretz_Lavie <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dbp="http://dbpedia.org/property/" xmlns:dbo="http://dbpedia.org/ontology/”> 13253 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dbp="http://dbpedia.org/property/" xmlns:dbo="http://dbpedia.org/ontology/”> 13253
9
Querying (SPARQL) 9 http://dbpedia.org/resource/ Technion_Israel_Institute_of_ Technology http://dbpedia.org/page/Technion_–_Israel_Institute_of_Technology 13253 http://dbpedia.org/ property/students http://dbpedia.org/ property/president http://dbpedia.org/reso urce/Peretz_Lavie PREFIX dbp: PREFIX dbr: SELECT ?inst { ?inst dbp:president dbr:Peretz_Lavie } PREFIX dbp: PREFIX dbr: SELECT ?inst { ?inst dbp:president dbr:Peretz_Lavie } inst http://dbpedia.org/resource/Technion_Isra el_Institute_of_Technology
10
The sameAs Property 10 SELECT DISTINCT ?url { ?c dbo:type dbr:City. ?c dbp:name ?city. ?c owl:sameAs ?url. FILTER ( str(?city)="Haifa") } SELECT DISTINCT ?url { ?c dbo:type dbr:City. ?c dbp:name ?city. ?c owl:sameAs ?url. FILTER ( str(?city)="Haifa") } url http://fr.dbpedia.org/resource/Haïfa http://it.dbpedia.org/resource/Haifa http://ja.dbpedia.org/resource/ ハイファ http://ko.dbpedia.org/resource/ 하이파 http://nl.dbpedia.org/resource/Haifa http://pl.dbpedia.org/resource/Hajfa http://pt.dbpedia.org/resource/Haifa http://wikidata.dbpedia.org/resource/Q41621 http://wikidata.org/entity/Q41621 http://sws.geonames.org/294801/ http://gadm.geovocab.org/id/1_1406 http://rdf.freebase.com/ns/m.0fg1g http://yago-knowledge.org/resource/Haifa These URIs can be used for getting Haifa information from other RDF resources!
11
RDF Components URI vocabulary –Uniquely identify an object / type / concept –Basically, a string that can encode (hierarchies of) concepts in domains Description of directed graphs –With URIs for node and edge labels –Edge = triple Schema definition –Extend the vocabulary with reasoning with inheritance and inclusion 11
12
Additional Quotes from Scientific A. 05/01 Two important technologies for developing the Semantic Web are already in place: eXtensible Markup Language (XML) and the Resource Description Framework (RDF). XML lets everyone create their own tags... Meaning is expressed by RDF, which encodes it in sets of triples, each triple being rather like the subject, verb and object of an elementary sentence. –... These triples can be written using XML tags. RDF [...] makes assertions that particular things (people, Web pages or whatever) have properties (such as "is a sister of," "is the author of") with certain values (another person, another Web page). 12
13
Ontologies Originally, a philosophical discipline –Science of Being (Aristotle, Metaphysics, IV, 1) –What characterizes being? Eventually, what is being? –An ontology is a formal specification of a shared conceptualization (T. R. Gruber) Practically speaking, in the world of Semantic Web: –A public collection of entity and relationship names –An agreed-upon meaning (usually based on textual descriptions and context, e.g., HTML table or furniture table) –Identified by a known namespace URI –Rules on behavior (e.g., FOL) 13
14
Pubilc Ontologies Best practice is to define data using existing ontologies Famous examples: –Dublin Core (media, Web resources) –FOAF: Friend of a Friend (people/social) –The Music Ontology –Good Relations (e-commerce) Used by Best Buy for their RDF catalog 14
15
Main Lecture Resources Lecture notes by Marcelo Arenas –RDF y SPARQL: Dos componentes básicos para la Web de datos –http://web.ing.puc.cl/~marenas/talks/valladolid13.pdfhttp://web.ing.puc.cl/~marenas/talks/valladolid13.pdf Lecture notes by Yaron Kanza –The Semantic Web –http://webcourse.cs.technion.ac.il/236369/Winter2014- 2015/ho/WCFiles/10-SemanticWeb-x6.pdfhttp://webcourse.cs.technion.ac.il/236369/Winter2014- 2015/ho/WCFiles/10-SemanticWeb-x6.pdf 15
16
Introduction Uniform Resource Identifiers RDF SPARQL Formal Definition RDF Schema Outline 16
17
URI Uniform Resource Identifier Syntax has a specification in W3C –RFC 2396RFC 2396 A URL is a URI that points to a location on the network (e.g., server on the network) –e.g., http://www.admin.technion.ac.il/telbook/empbycode.asp –A general URI needs not be an actual URL e.g., urn:isbn:0-486-27557-4 But, RDF requires URI to be dereferenceable –That is, they should point to a phisical description of the entity they represent
18
Relevant Quotes from S. A. 05/2001 Because RDF uses URIs to encode this information in a document, the URIs ensure that concepts are not just words in a document but are tied to a unique definition that everyone can find on the Web. For example, imagine that we have access to a variety of databases with information about people, including their addresses. If we want to find people living in a specific zip code, we need to know which fields in each database represent names and which represent zip codes. RDF can specify that “(field 5 in database A) (is a field of type) (zip code),” using URIs rather than phrases for each term. 18
19
Example Revisited 19 http://dbpedia.org/resource/ Technion_Israel_Institute_of_ Technology http://dbpedia.org/page/Technion_–_Israel_Institute_of_Technology 13253 http://dbpedia.org/ property/students http://dbpedia.org/ property/president http://dbpedia.org/reso urce/Peretz_Lavie <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dbp="http://dbpedia.org/property/" xmlns:dbo="http://dbpedia.org/ontology/"> 13253 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dbp="http://dbpedia.org/property/" xmlns:dbo="http://dbpedia.org/ontology/"> 13253
20
Terminology 20 <root xmlns:h="http://www.w3.org/TR/html4/" xmlns:f="http://www.w3schools.com/furniture"> prefixh local nametable qualified nameh:table namespace URIhttp://www.w3.org/TR/html4/ expanded namehttp://www.w3.org/TR/html4/table Semantically, a URI always represents the expanded name
21
Example Revisited 21 http://dbpedia.org/resource/ Technion_Israel_Institute_of_ Technology 13253 http://dbpedia.org/ property/students http://dbpedia.org/ property/president http://dbpedia.org/reso urce/Peretz_Lavie http://dbpedia.org/ ontology/birthYear 1949 http://dbpedia.org/ ontology/birthPlace http://dbpedia.org/reso urce/Petah_Tikva http://dbpedia.org/ ontology/birthPlace http://dbpedia.org/reso urce/Israel http://dbpedia.org/ ontology/country
22
Namespaces in Other Formats The idea of a namespace carries over the other RDF formats (later) The namespace is usually termed “prefix” 22
23
Example Revisited (Clearer Now) 23 dbr:Technion_Israel_Institute_ of_Technology 13253 dbp:students dbp:president dbr:Peretz_Lavie dbo:birthYear 1949 dbo:birthPlace dbr:Petah_Tikva dbo:birthPlace dbr:Israel dbo:country @prefix dbp:. @prefix dbr:. @prefix dbo:.
24
Introduction Uniform Resource Identifiers RDF SPARQL Formal Definition RDF Schema Outline 24
25
RDF Graph An RDF graph is a set of triples –Example: (dbr:technion, dbp:oresident, dbr:Lavie) (dbr:technion, dbp:students, 13253) Formally, we assume two sets: – U is a set of URIs, L is a set of literals An RDF triple is a member of U × U × (U ∪ L) An RDF graph is a finite set of RDF triples subject object predicate U U UL
26
Running Example: RDF Graph 26 dbr:Nate_Huffmandbp:teamdbr:Maccabi_TelAviv dbr:Nate_Huffmandbp:teamdbr:Toronto_Raptors dbr:Nate_Huffmandbo:height2.159 dbr:Gal_Mekeldbp:teamdbr:Maccabi_TelAviv dbr:Gal_Mekeldbp:teamdbr:Dallas_Mavericks dbr:Lior_Eliyahudbp:teamdbr:Maccabi_TelAviv dbr:Lior_Eliyahudbo:height2.05 URI literal
27
Our Model is a Simplification We do not represent blank nodes –These are nodes without URIs We do not represent datatypes –e.g., integer, float, string, date,... Further reading for interest: RDF books, online tutorials, W3C 27
28
Representing RDF Graphs There are several formats for representing RDF triples –We have seen examples of RDF/XML Namespaces, Description,... –JSON-LD LD stands for Linked Data –N-Triple Straightforward triples –Turtle More compact than N-Triple 28
29
Representation Examples 29 dbp:country dbr:Israel ; dbp:staff 870 ; dbp:budget "US$381 million"@en ; dbp:president dbr:Peretz_Lavie ; dbp:undergrad 9564 ; dbp:established 1912 ; dbp:students13253 ; dbp:country dbr:Israel ; dbp:staff 870 ; dbp:budget "US$381 million"@en ; dbp:president dbr:Peretz_Lavie ; dbp:undergrad 9564 ; dbp:established 1912 ; dbp:students13253 ; Turtle "622"^^. "13253"^^.. "622"^^. "13253"^^.. N-Triple { "@graph": [ { "@id": "http://dbpedia.org/resource/Technion_%E2%80%93_Israel_ Institute_of_Technology", "http://dbpedia.org/property/president" : [ { "@id": "http://dbpedia.org/resource/Peretz_Lavie"} ], "http://dbpedia.org/property/staff" : [ 870 ], "http://dbpedia.org/property/students" : [ 13253 ] ] } { "@graph": [ { "@id": "http://dbpedia.org/resource/Technion_%E2%80%93_Israel_ Institute_of_Technology", "http://dbpedia.org/property/president" : [ { "@id": "http://dbpedia.org/resource/Peretz_Lavie"} ], "http://dbpedia.org/property/staff" : [ 870 ], "http://dbpedia.org/property/students" : [ 13253 ] ] } JSON-LD
30
Introduction Uniform Resource Identifiers RDF SPARQL Formal Definition RDF Schema Outline 30
31
Query Language for RDF? To query RDF, we can use existing languages –SQL (over the triple relation) –XQuery (over RDF/XML) But: –We want QLs that are simpler and intuitive on graphs (triples) e.g., graph patterns should be easily phrased –The open-world nature of the semantic Web makes incompleteness a first-class citizen We should easily allow for optional information when exists (not NULL reasoning)
32
SPARQL Query Types SELECT –Returns mappings ASK –Boolean – exists at least one mapping? DESCRIBE –Includes a detailed description of found URIs CONSTRUCT –Construct a new RDF via the query We restrict to SELECT ! –But the main idea is very similar on all 32
33
SPARQL Examples 33 SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n } Maccabi players + nationalities SELECT ?x ?n ?h { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n OPTIONAL { ?x dbo:height ?h } } Add height optionally (left o. join) SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n. ?x dbo:height ?h. FILTER(?h>2) } Restrict to players >2m SELECT ?x ?n ?h ?t { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n OPTIONAL { ?x dbp:team ?t. ?t rdf:type yago:NBA} OPTIONAL { ?x dbo:height ?h } } Add both height and NBA memberships optionally
34
Try it on http://dbpedia.org/sparql 34 SELECT distinct ?x ?t ?h { ?x dbp:team. ?x dbp:nationality ?n OPTIONAL { ?x dbp:team ?t. ?t rdf:type yago:NationalBasketballAssociationTeams } OPTIONAL { ?x dbo:height ?h } SELECT distinct ?x ?t ?h { ?x dbp:team. ?x dbp:nationality ?n OPTIONAL { ?x dbp:team ?t. ?t rdf:type yago:NationalBasketballAssociationTeams } OPTIONAL { ?x dbo:height ?h }
35
Introduction Uniform Resource Identifiers RDF SPARQL Formal Definition RDF Schema Outline 35
36
RDF Query Model Next, we will see a formal definition of the SPARQL syntax and semantics Our definition covers the core of SPARQL, but omits many details –Does not cover blank nodes –Does not list the plethora of functions and Boolean predicates used for filtering As usual, more details in books, online tutorials, W3C, etc. 36
37
Basic SPARQL Query 37 The semantics is based on the notion of a mapping A mapping is a function μ that maps a set of variables, denoted vars(μ), to URIs and literals μ : vars(μ) ⟶ U ∪ L When applying a graph pattern P to an RDF graph G, the result is a set of mappings, denoted by P(G) The result of the query is the restriction (projection) of these mappings to ?x, ?y,... SELECT ?x,?y,... { graph-pattern }
38
Triple Patterns The simplest (atomic) pattern is a triple pattern Semantics of a triple pattern t : t(G) = { μ : vars(t) ⟶ U∪L | μ(t) ∈ G} That is, t(G) contains all of the mappings μ such that: – vars(μ) consists of the variables in t, and –When replacing each variable ?x with the constant μ(?x), the triple t becomes a triple in G In the definition we denote the new triple as μ(t) 38 S P O URI / variable URI / variable / literal
39
Example 1 39 dbr:Nate_Huffmandbp:teamdbr:Maccabi_TelAviv dbr:Nate_Huffmandbp:teamdbr:Toronto_Raptors dbr:Nate_Huffmandbo:height2.159 dbr:Gal_Mekeldbp:teamdbr:Maccabi_TelAviv dbr:Gal_Mekeldbp:teamdbr:Dallas_Mavericks dbr:Lior_Eliyahudbp:teamdbr:Maccabi_TelAviv dbr:Lior_Eliyahudbo:height2.05 ?x dbp:team ?t xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal Mekeldbr:Maccabi_TelAviv dbr:Gal Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv { ?x ⟶ dbr:Nate_Huffman, ?t ⟶ dbr:Maccabi_TelAviv} { ?x ⟶ dbr:Nate_Huffman, ?t ⟶ dbr:Toronto_Raptors} { ?x ⟶ dbr:Gal_Mekel, ?t ⟶ dbr:Maccabi_...} { ?x ⟶ dbr:Gal_Mekel, ?t ⟶ dbr:Dallas_Mavericks} { ?x ⟶ dbr:Lior_Eliyahu, ?t ⟶ dbr:Maccabi_TelAviv}
40
Example 2 40 dbr:Nate_Huffmandbp:teamdbr:Maccabi_TelAviv dbr:Nate_Huffmandbp:teamdbr:Toronto_Raptors dbr:Nate_Huffmandbo:height2.159 dbr:Gal_Mekeldbp:teamdbr:Maccabi_TelAviv dbr:Gal_Mekeldbp:teamdbr:Dallas_Mavericks dbr:Lior_Eliyahudbp:teamdbr:Maccabi_TelAviv dbr:Lior_Eliyahudbo:height2.05 dbr:Nate_Huffman ?p ?o po dbp:teamdbr:Maccabi_TelAviv dbp:teamdbr:Toronto_Raptors dbo:height2.159
41
Terminology Two mappings μ 1 and μ 2 are compatible if they agree on their common values ?x ∈ ( vars(μ 1 ) ∩ vars(μ 2 ) ) ⟹ μ 1 (?x)=μ 2 (?x) The join μ 1 ⨝μ 2 of two compatible mappings μ 1 and μ 2 is the mapping μ with: – vars(μ) = vars(μ 1 ) ∪ vars(μ 2 ) – μ(?x)=μ i (?x) whenever ?x∈vars(μ i ) The projection π X (μ) of a mapping μ to a set X of variables is the mapping λ with: – vars(λ) = vars(μ) ∩ X – λ(?x)=μ(?x) for all ?x in vars(λ) 41
42
Example: Compatibility and Join 42 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv xt dbr:Nate_Huffmandbr:Toronto_Raptors xt0 dbr:Nate_Huffmandbr:Toronto_Raptors xh dbr:Nate_Huffman2.159 x0t dbr:Gal_Mekeldbr:Dallas_Mavericks x0t0 dbr:Gal_Mekeldbr:Dallas_Mavericks incompatible compatible comp. compatible incompatible xth dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 xtx0t0 dbr:Nate_Huffma n dbr:Maccabi_TelAvivdbr:Gal_Mekeldbr:Dallas_Mavericks xtt0 dbr:Nate_Huffmandbr:Maccabi_TelAvivdbr:Toronto_Raptors
43
Example: Projection 43 xt dbr:Nate_Huffmandbr:Toronto_Raptors xth dbr:Nate_Huffmandbr:Toronto_Raptors2.159 x0t dbr:Gal_Mekeldbr:Dallas_Mavericks x0t0 dbr:Gal_Mekeldbr:Dallas_Mavericks π {x,t} (μ) μ xt dbr:Nate_Huffmandbr:Toronto_Raptors xt dbr:Nate_Huffmandbr:Toronto_Raptors { } t dbr:Dallas_Mavericks
44
Equivalent Presentations of Mapping Sets 44 xtha dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 dbr:Nate_Huffmandbr:Toronto_Raptors2.159 dbr:Nate_Huffmandbr:Maccabi_TelAvivyago:NBA dbr:Nate_Huffmandbr:Toronto_Raptorsyago:EL dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05 dbr:Lior_Eliyahudbr:Maccabi_TelAvivyago:EL xth dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 dbr:Nate_Huffmandbr:Toronto_Raptors2.159 dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05 xta dbr:Nate_Huffmandbr:Maccabi_TelAvivyago:NBA dbr:Nate_Huffmandbr:Toronto_Raptorsyago:EL dbr:Lior_Eliyahudbr:Maccabi_TelAvivyago:EL Collection of complete tables Missing Values The same!
45
Algebraic Operations Let Ω 1 and Ω 2 be two sets of matches Join: Ω 1 ⨝Ω 2 = {μ 1 ⨝μ 2 | μ i ∈Ω i ⋀ compatible(μ 1,μ 2 )} Difference: Ω 1 -Ω 2 = {μ 1 ∈Ω 1 | no μ 2 ∈Ω 2 is compatible with μ 1 } Left outer join: Ω 1 Ω 2 = (Ω 1 ⨝Ω 2 ) ∪ (Ω 1 -Ω 2 ) Projection: π X (Ω 1 ) = { π X (μ 1 ) | μ 1 ∈Ω 1 } Filter (selection) for a Boolean condition F over matches σ F (Ω 1 ) = {μ 1 ∈Ω 1 | μ 1 satisfies F} 45
46
Example: Join 46 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv xh dbr:Nate_Huffman2.159 dbr:Lior_Eliyahu2.05 ⨝= xth dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 dbr:Nate_Huffmandbr:Toronto_Raptors2.159 dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05
47
Example: 2xJoin 47 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv xh dbr:Nate_Huffman2.159 dbr:Lior_Eliyahu2.05 ta dbr:Toronto_Raptorsyago:NBA dbr:Maccabi_TelAvivyago:EL ⨝ xtha dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159yago:EL dbr:Nate_Huffmandbr:Toronto_Raptors2.159yago:NBA dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05yago:EL ⨝ =
48
Example: Difference (1) 48 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv xh dbr:Nate_Huffman2.159 dbr:Lior_Eliyahu2.05 - = xt dbr:Gal_Mekeldbr:Dallas_Mavericks
49
Example: Difference (2) 49 xh dbr:Lior_Eliyahu2.05 ta dbr:Dallas_Mavericksyago:NBA - = xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv
50
Example: Difference (3) 50 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv - = a yago:NBA yago:EL { }
51
Example: Left Outer Join (1) 51 xh dbr:Nate_Huffman2.159 dbr:Lior_Eliyahu2.05 = xth dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 dbr:Nate_Huffmandbr:Toronto_Raptors2.159 dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv
52
Example: Left Outer Join (2) 52 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv dbr:Utah_Jazz ta yago:NBA dbr:Maccabi_TelAvivyago:EL = xta dbr:Nate_Huffmandbr:Maccabi_TelAvivyago:EL dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAvivyago:EL dbr:Utah_Jazzyago:NBA
53
Example: Join, Difference, Outer Join (1) 53 xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv xh dbr:Nate_Huffman2.159 dbr:Lior_Eliyahu2.05 ta dbr:Toronto_Raptorsyago:NBA dbr:Maccabi_TelAvivyago:EL ⨝= xtha dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 dbr:Nate_Huffmandbr:Toronto_Raptors2.159 dbr:Nate_Huffmandbr:Maccabi_TelAvivyago:NBA dbr:Nate_Huffmandbr:Toronto_Raptorsyago:EL dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05 dbr:Lior_Eliyahudbr:Maccabi_TelAvivyago:EL
54
Example: Join, Difference, Outer Join (2) 54 xh dbr:Nate_Huffman2.159 dbr:Lior_Eliyahu2.05 ta dbr:Toronto_Raptorsyago:NBA dbr:Maccabi_TelAvivyago:EL - xt dbr:Gal_Mekeldbr:Dallas_Mavericks xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv =
55
Example: Join, Difference, Outer Join (3) 55 xh dbr:Nate_Huffman2.159 dbr:Lior_Eliyahu2.05 ta dbr:Toronto_Raptorsyago:NBA dbr:Maccabi_TelAvivyago:EL xtha dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 dbr:Nate_Huffmandbr:Toronto_Raptors2.159 dbr:Nate_Huffmandbr:Maccabi_TelAvivyago:NBA dbr:Nate_Huffmandbr:Toronto_Raptorsyago:EL dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05 dbr:Lior_Eliyahudbr:Maccabi_TelAvivyago:EL dbr:Gal_Mekeldbr:Dallas_Mavericks xt dbr:Nate_Huffmandbr:Maccabi_TelAviv dbr:Nate_Huffmandbr:Toronto_Raptors dbr:Gal_Mekeldbr:Dallas_Mavericks dbr:Lior_Eliyahudbr:Maccabi_TelAviv =
56
Projection Example 56 xtha dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159 dbr:Nate_Huffmandbr:Toronto_Raptors2.159 dbr:Nate_Huffmandbr:Maccabi_TelAvivyago:NBA dbr:Nate_Huffmandbr:Toronto_Raptorsyago:EL dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05 dbr:Lior_Eliyahudbr:Maccabi_TelAvivyago:EL dbr:Gal_Mekeldbr:Dallas_Mavericks π ?x,?h = xh dbr:Nate_Huffman2.159 dbr:Nate_Huffman dbr:Lior_Eliyahu2.05 dbr:Lior_Eliyahu dbr:Gal_Mekel
57
Filter Example 57 xtha dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159yago:EL dbr:Nate_Huffmandbr:Toronto_Raptors2.159yago:NBA dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05yago:EL dbr:Gal_Mekeldbr:Maccabi_TelAvivyago:EL dbr:Gal_Mekeldbr:Dallas_Mavericks = σ ?a=yago:EL xtha dbr:Nate_Huffmandbr:Maccabi_TelAviv2.159yago:EL dbr:Lior_Eliyahudbr:Maccabi_TelAviv2.05yago:EL dbr:Gal_Mekeldbr:Maccabi_TelAvivyago:EL
58
SPARQL Filter Language Atomic binary predicates (+scalar functions) – bound(?x) Satisfied by μ if ?x is in vars(μ) – ?x=?y, ?x=“Technion” Satisfied by μ if involved variables are bound and equality holds – regex(str(?mbox), “@work.example”) Composition via Boolean operators – and, or, not 58
59
SPARQL Basic Syntax 59 Pattern P Semantics: P(G) triple pattern tt(G) P 1. P 2 P 1 (G) ⨝ P 2 (G) {P 1 } MINUS {P 2 }P 1 (G) - P 2 (G) P 1 OPTIONAL {P 2 }P 1 (G) ⟕ P 2 (G) {P 1 } UNION {P 2 }P 1 (G) ∪ P 2 (G) {P 1 FILTER ( F )}σ F P 1 (G) SELECT ?x 1,...,?x k WHERE {P 1 }π {x 1,...,x k } (P 1 (G)) optional
60
Examples Revisited 60 SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n } triple, join, projection SELECT ?x ?n ?h { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n OPTIONAL { ?x dbo:height ?h } } triple, join, projection, l.o.join SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n. ?x dbo:height ?h. FILTER(?h>2) } triple, join, projection, filter SELECT ?x ?n ?h ?t { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n OPTIONAL { ?x dbp:team ?t. ?t rdf:type yago:NBA} OPTIONAL { ?x dbo:height ?h } } triple, join, projection, l.o.join
61
Ex. 1 61 SELECT ?president { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. } SELECT ?president { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. } Lincoln Nixon Clinton Roosevelt dbr:Abraham_Lincolndbo:partydbr:Republican_Party dbr:Abraham_Lincolndbo:partydbr:Whig_Party dbr:Abraham_Lincolndbo:professiondbr:Lawyer dbr:Abraham_Lincolnrdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Rooseveltdbo:professiondbr:Lawyer dbr:Franklin_D._Rooseveltdbo:partydbr:Democratic_Party dbr:Franklin_D._Rooseveltrdf:type yago:PresidentsOfTheUnitedStates dbr:Richard_Nixondbo:partydbr:Republican_Party dbr:Richard_Nixonrdf:type yago:PresidentsOfTheUnitedStates dbr:Bill_Clintondbo:professiondbr:Lawyer dbr:Bill_Clintonrdf:type yago:PresidentsOfTheUnitedStates
62
Ex. 2 62 SELECT ?president { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. OPTIONAL { ?president dbo:party ?party } } SELECT ?president { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. OPTIONAL { ?president dbo:party ?party } } Lincoln Nixon Clinton Roosevelt dbr:Abraham_Lincolndbo:partydbr:Republican_Party dbr:Abraham_Lincolndbo:partydbr:Whig_Party dbr:Abraham_Lincolndbo:professiondbr:Lawyer dbr:Abraham_Lincolnrdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Rooseveltdbo:professiondbr:Lawyer dbr:Franklin_D._Rooseveltdbo:partydbr:Democratic_Party dbr:Franklin_D._Rooseveltrdf:type yago:PresidentsOfTheUnitedStates dbr:Richard_Nixondbo:partydbr:Republican_Party dbr:Richard_Nixonrdf:type yago:PresidentsOfTheUnitedStates dbr:Bill_Clintondbo:professiondbr:Lawyer dbr:Bill_Clintonrdf:type yago:PresidentsOfTheUnitedStates
63
Ex. 3 63 SELECT ?president { { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. OPTIONAL { ?president dbo:party ?party } } MINUS {dbr:Richard_Nixon dbo:party ?party} } SELECT ?president { { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. OPTIONAL { ?president dbo:party ?party } } MINUS {dbr:Richard_Nixon dbo:party ?party} } Lincoln Nixon Clinton Roosevelt dbr:Abraham_Lincolndbo:partydbr:Republican_Party dbr:Abraham_Lincolndbo:partydbr:Whig_Party dbr:Abraham_Lincolndbo:professiondbr:Lawyer dbr:Abraham_Lincolnrdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Rooseveltdbo:professiondbr:Lawyer dbr:Franklin_D._Rooseveltdbo:partydbr:Democratic_Party dbr:Franklin_D._Rooseveltrdf:type yago:PresidentsOfTheUnitedStates dbr:Richard_Nixondbo:partydbr:Republican_Party dbr:Richard_Nixonrdf:type yago:PresidentsOfTheUnitedStates dbr:Bill_Clintondbo:professiondbr:Lawyer dbr:Bill_Clintonrdf:type yago:PresidentsOfTheUnitedStates
64
Ex. 4 64 dbr:Abraham_Lincolndbo:partydbr:Republican_Party dbr:Abraham_Lincolndbo:partydbr:Whig_Party dbr:Abraham_Lincolndbo:professiondbr:Lawyer dbr:Abraham_Lincolnrdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Rooseveltdbo:professiondbr:Lawyer dbr:Franklin_D._Rooseveltdbo:partydbr:Democratic_Party dbr:Franklin_D._Rooseveltrdf:type yago:PresidentsOfTheUnitedStates dbr:Richard_Nixondbo:partydbr:Republican_Party dbr:Richard_Nixonrdf:type yago:PresidentsOfTheUnitedStates dbr:Bill_Clintondbo:professiondbr:Lawyer dbr:Bill_Clintonrdf:type yago:PresidentsOfTheUnitedStates Write SPARQL queries that: 1.Find the presidents who were in one or more of Lincoln’s parties 2.Find the presidents who were in none of Lincoln’s parties 3.For each president in (1) and (2), add his dbp:spouse if exists You can send your answers for Ex. 1-4 to bennyk@cs to get feedback
65
From Graphs to Datasets An important ability in SPARQL is the ability to query multiple graphs (from multiple sources) This is formalized as follows An RDF dataset D is a pair (G 0,Ext), where: – G 0 is the default RDF graph – Ext is a finite mapping of URIs to RDF graphs These are the other graphs that can be referenced by means of URIs 65 Ext(u 1 )Ext(u 2 )Ext(u 3 ) G0G0
66
SPQRQL over RDF Datasets Let D=(G 0,Ext) be an RDF dataset, G be an RDF graph ( G=G 0 or G∈Ext ), and P be a graph pattern If u be a URI in the domain of Ext, then now Q={GRAPH u {P}} is also a graph pattern Q(G) = P(Ext(u)) Q={GRAPH ?x {P}} is now also a graph pattern Q(G) = ∪ u∈dom(Ext) ( {?x⟶u} ⨝ P(Ext(u)) ) We can define the eval of a pattern P' over D : P'(D) = P'(G 0 ) 66 Ignore G !
67
Adding Graph to Basic Syntax Pattern P Semantics: P(G) triple pattern tt(G) P 1. P 2 P 1 (G) ⨝ P 2 (G) {P 1 } MINUS {P 2 }P 1 (G) - P 2 (G) P 1 OPTIONAL {P 2 }P 1 (G) ⟕ P 2 (G) {P 1 } UNION {P 2 }P 1 (G) ∪ P 2 (G) {P 1 FILTER ( F )}σ F P 1 (G) SELECT ?x 1,...,?x k {P 1 }π {x 1,...,x k } (P 1 (G)) GRAPH u {P 1 }P 1 (Ext(u)) GRAPH ?x {P 1 } ∪ u∈dom(Ext) ( {?x⟶u} ⨝ P 1 (Ext(u)) )
68
Example 68 SELECT ?m ?g ?party FROM NAMED { ?city dbp:mayor ?m1 ?m1 owl:sameAs ?m OPTIONAL { GRAPH ?g {?m ex:isAffiliatedTo ?party} }} dbr:Ashdoddbp:mayordbr:Yehiel_Lasri owl:sameAsex:Yehiel_Lasri dbr:Haifadbp:mayordbr:Yona_Yahav owl:sameAsex:Yona_Yahav Default (i.e., G 0 ) ex:Yona_Yahavex:isAffiliatedToex:Kadima http://ex1.org/ ex:Yona_Yahavex:isAffiliatedToex:Laborhttp://ex2.org/ mgparty ex:Yehiel_Lasri ex:Yona_Yahavhttp://ex1.org/ex:Kadima ex:Yona_Yahavhttp://ex2.org/ex:Labor Ext
69
Try at http://lod2.openlinksw.com/sparql 69 PREFIX dbo: SELECT distinct ?h ?e { ?x owl:sameAs ?y. ?x rdfs:label ?h. GRAPH { ?y rdfs:label ?e. ?y rdf:type dbo:Animal } FILTER(LANG(?h) = "he" and LANG(?e) = "en") } he זעמן Coluber חדקן Acipenser חזיר יבלות Phacochoerus קורא Ammoperdix נץ Accipiter ערוד African wild ass
70
Additional Features (SPARQL 1.1) SELECT ?city, count(?x) AS ?c { ?x rdf:type dbo:Scientist. ?x dbo:birthPlace ?city. ?city dbo:country dbr:Israel. } GROUP BY ?city ORDER BY DESC(count(*)) Aggregate Queries select ?s { ?s rdf:type dbo:Scientist. ?s (dbo:doctoralAdvisor)+ dbr:Alonzo_Church. } Property Path cityc dbr:Tel_Aviv25 dbr:Haifa12 dbr:Rehovot5 dbr: Petah_Tikva4 dbr:Tiberias2 dbr:Safed1 dbr:Nazareth1 http://dbpedia.org/sparql s dbr:Alan_Turing dbr:Andrej_Bauer dbr:Angus_Macintyre dbr:Dana_Scott dbr:Dov_Gabbay dbr:J._Barkley_Rosser dbr:Jack_Copeland dbr:Jeff_Paris dbr:Kurt_Mehlhorn dbr:Martin_Davis dbr:Martin_Hyland s dbr:Michael_Fourman dbr:Michael_O._Rabin dbr:Paul_Ernest dbr:Peter_Mosses dbr:Robert_Lee_Constable dbr:Robin_Gandy dbr:Saharon_Shelah dbr:Stephen_Cole_Kleene dbr:Susanne_Albers dbr:William_Boone dbr:Yiannis_N._Moschovakis
71
Advisory Graph 71 dbr:Alonzo_Church dbo:doctoralAdvisor dbr:Alan_Turing dbr:Michael_O._Rabin dbr:Saharon_Shelah dbo:doctoralAdvisor dbr:Dov_Gabbay dbr:Robin_Gandy dbo:doctoralAdvisor dbr:Jeff_Paris
72
Introduction Uniform Resource Identifiers RDF SPARQL Formal Definition RDF Schema Outline 72
73
RDF Schema RDF Schema (RDFS) enriches RDF with semantics –Types/subtypes, classes/subclasses –Properties and sub-properties –Typing of properties A simple extension to describe ontologies –Very limited compared to other concepts –Monotone – does not say what “cannot” happen –Very different notion from SQL schema, DTD,... Not outside RDF, extends RDF Why is it useful? –General reasoning/integration power –Allows to automatically infer implicit information
74
Example (Wikipedia) 74 ex:dog1 ex:animal rdf:type ex:cat ex:cat1 rdf:type ex:cat ex:cat2 zoo:host SELECT ?x { ?x rdf:type ex:animal } SELECT ?x { ?x rdf:type ex:animal } x ex:dog1 rdf:typeex:animal ex:cat1rdf:typeex:cat ex:zoo1zoo:hostex:cat2
75
Example (Wikipedia) 75 ex:dog1 ex:animal rdf:type ex:cat ex:cat1 rdf:type rdfs:subClassOf ex:cat ex:cat2 zoo:host rdfs:range x ex:dog1 ex:cat1 ex:cat2 ex:dog1rdf:typeex:animal ex:cat1rdf:typeex:cat ex:zoo1zoo:hostex:cat2 ex:catrdfs:subClassOfex:animal zoo:hostrdfs:rangeex:animal SELECT ?x { ?x rdf:type ex:animal } SELECT ?x { ?x rdf:type ex:animal }
76
We Discuss Four RDFS Properties p rdfs:domain C –Example: ex:teaches rdfs:domain ex:professor p rdfs:range C –Example: ex:teaches rdfs:range ex:course p rdfs:subPropertyOf q –Example: ex:motherOf rdfs:subPropertyOf ex:parentOf C rdfs:subClassOf D –Example: ex:pizza rdfs:subClassOf ex:Food 76
77
Inference System for RDFS 77 Rules for inferring additional triples from existing RDF/RDFS triples: Given ⇒ Infer (p,rdfs:domain,C), (s,p,o)(s,rdf:type,C) (p,rdfs:range,C), (s,p,o)(o,rdf:type,C) (p,rdfs:subPropertyOf,q), (s,p,o)(s,q,o)(s,q,o) (C,rdfs:subClassOf,D), (s,rdf:type,C)(s,rdf:type,D) Transitivity (p,rdfs:subPropertyOf,q), (q,rdfs:subPropertyOf,r)(p,rdfs:subPropertyOf,r) (C,rdfs:subClassOf,D), (D,rdfs:subClassOf,E)(C,rdfs:subClassOf,E)
78
Example 78 dbr:Israelex:ministerex:Gila_Gamliel dbr:Israelex:finance_ministerex:Moshe_Kahlon ex:finance_ministerrdfs:subPropertyOfex:minister rdfs:rangedbr:politician rdfs:subClassOfdbo:person dbr:Israelex:ministerex:Moshe_Kahlon IL minister IL finance_minister ex:Gila_Gamlieldrf:typedbr:politician politician ex:Gila_Gamlieldrf:typedbo:person ex:Moshe_Kahlondrf:typedbr:politician ex:Moshe_Kahlondrf:typedbo:person person
79
RDFS Closure The RDFS closure of an RDF graph G is the graph obtained from G by iteratively adding triples inferred from the rules until impossible (fixpoint) –We denote this graph by cl(G) A SPARQL engine that supports RDFS gives the result of cl(G) P RDFS (G) = P(cl(G)) 79
80
Example 80 dbr:Moshe_Vardidbo:doctoralAdvisordbr:Catriel_Beeri dbo:doctoralAdvisorrdfs:domaindbo:Scientist dbr:Moshe_Vardidbo:birthPlacedbr:Haifa dbr:Ron_Kimmeldbo:birthPlacedbr:Haifa dbr:Ron_Kimmelrdf:typedbo:Scientist SELECT ?x { ?x rdf:type dbo:Scientist. ?x dbo:birthPlace dbr:Haifa } SELECT ?x { ?x rdf:type dbo:Scientist. ?x dbo:birthPlace dbr:Haifa } x dbr:Ron_Kimmel P(G) x dbr:Ron_Kimmel dbr:Moshe_Vardi P RDFS (G)
81
RDFS Expressiveness Limitations No negation –Cannot state disjointness (e.g., animals / people) Limited containment relationship –For example, every mammal is either an animal or a person No cardinality/inclusion constraints –Every mammal has exactly two biological parents –Every course has at least one lecturer No logical constraints on relations –For example, inverse (parent/child), transitivity
82
Beyond RDFS: OWL OWL (Web Ontology Language) is designed to provide rich expressiveness for ontology specification and reasoning –“OWL is now the most used KR language in the history of AI…” (Jim Hendler) Several classes (different expressiveness/complexity tradeoffs) –OWL Full, OWL DL, OWL Lite –In all versions, specs are in RDF 82
83
Examples foaf:made owl:inverseOf foaf:maker ex:friend rdf:type owl:SymmetricProperty geo:located rdf:type owl:TransitiveProperty Additional properties: – owl:FunctionalProperty, owl:ComplementOf, owl:IntersectionOf 83
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.