Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Management Systems

Similar presentations


Presentation on theme: "Database Management Systems"— Presentation transcript:

1 Database Management Systems
Faculty of Computer Science Technion – Israel Institute of Technology Database Management Systems Course Lecture 9: RDF and SPARQL

2 The Semantic Web “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 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
“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

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

6 There’s More! Linked!

7

8 RDF Example from DBPedia
13253 1949

9 In XML Syntax 13253 <?xml version="1.0" encoding="utf-8" ?> <rdf:RDF xmlns:rdf=" xmlns:rdfs=" xmlns:dbp=" xmlns:dbo=" <rdf:Description rdf:about=" <dbp:students rdf:datatype=" <dbp:president rdf:resource=" /> </rdf:Description> </rdf:RDF>

10 Querying (SPARQL) SELECT ?inst { ?inst dbp:president dbr:Peretz_Lavie
13253 PREFIX dbp:< PREFIX dbr:< SELECT ?inst { ?inst dbp:president dbr:Peretz_Lavie } inst

11 The owl:sameAs Property
url SELECT DISTINCT ?city { ?c dbo:type dbr:City. ?c dbp:name ?cn. FILTER ( str(?cn)="Haifa"). ?c owl:sameAs ?city. } These URIs can be used for getting Haifa information from other RDF resources!

12 RDF Components URI vocabulary Description of directed graphs
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 over inheritance, domain/range of properties, …

13 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).

14 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)

15 Public 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

16 Main Lecture Resources
Lecture notes by Marcelo Arenas RDF y SPARQL: Dos componentes básicos para la Web de datos Lecture notes by Yaron Kanza The Semantic Web

17

18 URI Uniform Resource Identifier Syntax has a specification in W3C
RFC 2396 A URL is a URI that points to a location on the network (e.g., server on the network) e.g., A general URI needs not be an actual URL e.g., urn:isbn:

19 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.

20 Example Revisited 13253 <?xml version="1.0" encoding="utf-8" ?> <rdf:RDF xmlns:rdf=" xmlns:rdfs=" xmlns:dbp=" xmlns:dbo=" <rdf:Description rdf:about=" <dbp:students rdf:datatype=" <dbp:president rdf:resource=" /> </rdf:Description> </rdf:RDF>

21 Semantically, a URI always represents the expanded name
Terminology <root xmlns:h=" xmlns:f=" <h:table> prefix h local name table qualified name h:table namespace URI expanded name Semantically, a URI always represents the expanded name

22 Example Revisited http://dbpedia.org/ontology/country
13253 1949

23 Example Revisited (Clearer Now)
@prefix dbp: < . @prefix dbr: < . @prefix dbo: < . dbo:country dbr:Israel dbr:Petah_Tikva dbo:birthPlace dbo:birthPlace dbr:Technion_Israel_Institute_of_Technology dbr:Peretz_Lavie dbp:president dbo:birthYear dbp:students 1949 13253

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 predicate subject object U U U L

26 Running Example: RDF Graph
dbr:Nate_Huffman dbp:team dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbo:height 2.159 dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu 2.05 URI literal

27 Our Model is a Simplification
It does not represent blank nodes These are nodes without URIs It does not model datatypes e.g., integer, float, string, date, ... Further reading for interest: RDF books, online tutorials, W3C dbr:Israel dbo:country dbo:address dbr:Technion_Israel_Institute_of_Technology dbo:zip 32000 dbo:city dbr:Haifa

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

29 Representation Examples
< < . < dbpedia.org/property/students>"13253"^^< . < < . N-Triple { [ { " " : [ { " ] , " : [ 870 ] , " : [ ] ] } Turtle < dbp:country dbr:Israel ; dbp:staff 870 ; dbp:budget "US$381 ; dbp:president dbr:Peretz_Lavie ; dbp:undergrad ; dbp:established ; dbp:students ; JSON-LD

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 We restrict to SELECT! SELECT ASK DESCRIBE
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

33 SPARQL Examples SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv.
?x dbp:nationality ?n. ?x dbo:height ?h. FILTER(?h>2) } SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n } Maccabi players + nationalities 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} ?x dbo:height ?h } } 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) Add both height and NBA memberships optionally

34 Try it on http://dbpedia.org/sparql
SELECT distinct ?x ?t ?h { ?x dbp:team < OPTIONAL { ?x dbp:team ?t. ?t rdf:type yago:WikicatNationalBasketballAssociationTeams } ?x dbo:height ?h

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.

37 Basic SPARQL Query SELECT ?x,?y,... { graph-pattern }
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,...

38 Triple Patterns t(G) = { μ : vars(t) ⟶ U∪L | μ(t) ∈ G} S P O
URI / variable URI / variable URI / variable / literal 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)

39 Example 1 ?x dbp:team ?t dbr:Nate_Huffman dbp:team dbr:Maccabi_TelAviv
dbr:Toronto_Raptors dbo:height 2.159 dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu 2.05 ?x dbp:team ?t x t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu { ?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 dbr:Nate_Huffman ?p ?o dbr:Nate_Huffman dbp:team
dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbo:height 2.159 dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu 2.05 dbr:Nate_Huffman ?p ?o p o dbp:team dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbo:height 2.159

41 ?x ∈ (vars(μ1) ∩ vars(μ2)) ⟹ μ1(?x)=μ2(?x)
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 (natural) 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(λ)

42 Example: Compatibility and Join
dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors x t dbr:Nate_Huffman dbr:Toronto_Raptors x t0 dbr:Nate_Huffman dbr:Toronto_Raptors compatible incompatible x t dbr:Nate_Huffman dbr:Maccabi_TelAviv x0 t0 dbr:Gal_Mekel dbr:Dallas_Mavericks comp. x t x0 t0 dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Gal_Mekel dbr:Dallas_Mavericks compatible x h dbr:Nate_Huffman 2.159 incompatible x t h dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 x0 t dbr:Gal_Mekel dbr:Dallas_Mavericks

43 Example: Projection μ π{x,t}(μ) { } x t dbr:Nate_Huffman
dbr:Toronto_Raptors x t dbr:Nate_Huffman dbr:Toronto_Raptors x t h dbr:Nate_Huffman dbr:Toronto_Raptors 2.159 x t dbr:Nate_Huffman dbr:Toronto_Raptors x0 t dbr:Gal_Mekel dbr:Dallas_Mavericks t dbr:Dallas_Mavericks x0 t0 dbr:Gal_Mekel dbr:Dallas_Mavericks { }

44 Equivalent Presentations of Mapping Sets
x t h dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 dbr:Toronto_Raptors dbr:Lior_Eliyahu 2.05 Collection of complete tables x t a dbr:Nate_Huffman dbr:Maccabi_TelAviv yago:NBA dbr:Toronto_Raptors yago:EL dbr:Lior_Eliyahu The same! x t h a dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 dbr:Toronto_Raptors yago:NBA yago:EL dbr:Lior_Eliyahu 2.05 Missing Values

45 Algebraic Operations Ω1-Ω2 = {μ1∈Ω1 | no μ2∈Ω2 is compatible with μ1}
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}

46 Example: Join ⨝ = x t dbr:Nate_Huffman dbr:Maccabi_TelAviv
dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu x h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 = x t h dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 dbr:Toronto_Raptors dbr:Lior_Eliyahu 2.05

47 Example: 2xJoin ⨝ ⨝ = x t dbr:Nate_Huffman dbr:Maccabi_TelAviv
dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu x h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 t a dbr:Toronto_Raptors yago:NBA dbr:Maccabi_TelAviv yago:EL x t h a dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 yago:EL dbr:Toronto_Raptors yago:NBA dbr:Lior_Eliyahu 2.05 =

48 Example: Difference (1)
t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu x h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 - = x t dbr:Gal_Mekel dbr:Dallas_Mavericks

49 Example: Difference (2)
h dbr:Lior_Eliyahu 2.05 x t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu - = t a dbr:Dallas_Mavericks yago:NBA x t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors

50 Example: Difference (3)
t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu a yago:NBA yago:EL { } - =

51 Example: Left Outer Join (1)
dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu x h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 = x t h dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu 2.05

52 Example: Left Outer Join (2)
dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu dbr:Utah_Jazz t a dbr:Utah_Jazz yago:NBA dbr:Maccabi_TelAviv yago:EL = x t a dbr:Nate_Huffman dbr:Maccabi_TelAviv yago:EL dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu dbr:Utah_Jazz yago:NBA

53 Example: Join, Difference, Outer Join (1)
h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 x t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu = t a dbr:Toronto_Raptors yago:NBA dbr:Maccabi_TelAviv yago:EL x t h a dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 dbr:Toronto_Raptors yago:NBA yago:EL dbr:Lior_Eliyahu 2.05

54 Example: Join, Difference, Outer Join (2)
h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 x t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu - = t a dbr:Toronto_Raptors yago:NBA dbr:Maccabi_TelAviv yago:EL x t dbr:Gal_Mekel dbr:Dallas_Mavericks

55 Example: Join, Difference, Outer Join (3)
h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 x t dbr:Nate_Huffman dbr:Maccabi_TelAviv dbr:Toronto_Raptors dbr:Gal_Mekel dbr:Dallas_Mavericks dbr:Lior_Eliyahu = t a dbr:Toronto_Raptors yago:NBA dbr:Maccabi_TelAviv yago:EL x t h a dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 dbr:Toronto_Raptors yago:NBA yago:EL dbr:Lior_Eliyahu 2.05 dbr:Gal_Mekel dbr:Dallas_Mavericks

56 Projection Example π?x,?h = x t h a dbr:Nate_Huffman
dbr:Maccabi_TelAviv 2.159 dbr:Toronto_Raptors yago:NBA yago:EL dbr:Lior_Eliyahu 2.05 dbr:Gal_Mekel dbr:Dallas_Mavericks π?x,?h = x h dbr:Nate_Huffman 2.159 dbr:Lior_Eliyahu 2.05 dbr:Gal_Mekel

57 Filter Example σ?a=yago:EL = x t h a dbr:Nate_Huffman
dbr:Maccabi_TelAviv 2.159 yago:EL dbr:Toronto_Raptors yago:NBA dbr:Lior_Eliyahu 2.05 dbr:Gal_Mekel dbr:Dallas_Mavericks σ?a=yago:EL = x t h a dbr:Nate_Huffman dbr:Maccabi_TelAviv 2.159 yago:EL dbr:Lior_Eliyahu 2.05 dbr:Gal_Mekel

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), Composition via Boolean operators and, or, not

59 SPARQL Basic Syntax Pattern P Semantics: P(G) triple pattern t t(G)
P1 . P2 P1(G) ⨝ P2(G) {P1} MINUS {P2} P1(G) - P2(G) P1 OPTIONAL {P2} P1(G) ⟕ P2(G) {P1} UNION {P2} P1(G) ∪ P2(G) {P1 FILTER ( F )} σFP1(G) SELECT ?x1,...,?xk WHERE {P1} π{x1,...,xk}(P1(G)) optional

60 Examples Revisited SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv.
?x dbp:nationality ?n. ?x dbo:height ?h. FILTER(?h>2) } SELECT ?x ?n { ?x dbp:team dbr:Maccabi_TelAviv. ?x dbp:nationality ?n } triple, join, projection 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} ?x dbo:height ?h } } 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 triple, join, projection, l.o.join

61 Ex. 1 dbr:Abraham_Lincoln dbo:party dbr:Republican_Party dbr:Whig_Party dbo:profession dbr:Lawyer rdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Roosevelt dbr:Democratic_Party dbr:Richard_Nixon dbr:Bill_Clinton SELECT ?president { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. } Lincoln Roosevelt Nixon Clinton ?

62 Ex. 2 dbr:Abraham_Lincoln dbo:party dbr:Republican_Party dbr:Whig_Party dbo:profession dbr:Lawyer rdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Roosevelt dbr:Democratic_Party dbr:Richard_Nixon dbr:Bill_Clinton SELECT ?president { ?president rdf:type yago:PresidentsOfTheUnitedStates. ?president dbo:profession dbr:Lawyer. OPTIONAL { ?president dbo:party ?party } } Lincoln Roosevelt Nixon Clinton ?

63 Ex. 3 dbr:Abraham_Lincoln dbo:party dbr:Republican_Party dbr:Whig_Party dbo:profession dbr:Lawyer rdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Roosevelt dbr:Democratic_Party dbr:Richard_Nixon dbr:Bill_Clinton 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 Roosevelt Nixon Clinton ?

64 Ex. 4 Write SPARQL queries that:
dbr:Abraham_Lincoln dbo:party dbr:Republican_Party dbr:Whig_Party dbo:profession dbr:Lawyer rdf:type yago:PresidentsOfTheUnitedStates dbr:Franklin_D._Roosevelt dbr:Democratic_Party dbr:Richard_Nixon dbr:Bill_Clinton Write SPARQL queries that: Find the presidents who were in one or more of Lincoln’s parties Find the presidents who were in none of Lincoln’s parties For each president in (1) and (2), add his dbp:spouse if exists

65

66 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 (G0,Ext), where: G0 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 G0 Ext(u1) Ext(u2) Ext(u3)

67 SPQRQL over RDF Datasets
Let D=(G0,Ext) be an RDF dataset, G be an RDF graph (G=G0 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'(G0) Ignore G!

68 Adding Graph to Basic Syntax
Pattern P Semantics: P(G) triple pattern t t(G) P1 . P2 P1(G) ⨝ P2(G) {P1} MINUS {P2} P1(G) - P2(G) P1 OPTIONAL {P2} P1(G) ⟕ P2(G) {P1} UNION {P2} P1(G) ∪ P2(G) {P1 FILTER ( F )} σFP1(G) SELECT ?x1,...,?xk {P1} π{x1,...,xk}(P1(G)) GRAPH u {P1} P1(Ext(u)) GRAPH ?x {P1} ∪u∈dom(Ext)({?x⟶u} ⨝ P1(Ext(u)))

69 Example Default (i.e., G0) dbr:Ashdod dbp:mayor dbr:Yehiel_Lasri
owl:sameAs ex:Yehiel_Lasri dbr:Haifa dbr:Yona_Yahav ex:Yona_Yahav ex:Yona_Yahav ex:isAffiliatedTo ex:Kadima ex:Yona_Yahav ex:isAffiliatedTo ex:Labor SELECT ?m ?g ?party FROM NAMED < FROM NAMED < { ?city dbp:mayor ?m1 ?m1 owl:sameAs ?m OPTIONAL { GRAPH ?g {?m ex:isAffiliatedTo ?party} }} m g party ex:Yehiel_Lasri ex:Yona_Yahav ex:Kadima ex:Labor Ext

70 Mammals from dbpedia.org
Mammals in Hebrew: SELECT distinct ?x { ?x dbp:classis dbr:Mammal. } SELECT distinct ?x, ?h { ?x dbp:classis dbr:Mammal. ?x rdfs:label ?h. FILTER(LANG(?h) = "he") } x x h

71 Mammals from dbpedia.org + Linked
SELECT distinct ?x, ?h { ?x dbp:classis dbr:Mammal. ?x owl:sameAs ?y. GRAPH ?g { ?y rdfs:label ?h . FILTER(LANG(?h) = "he") } x h "אנומלור "גחן "סלנויה חומת "מושק "ארמדיל חשוף-זנב "איילון "ויסקאשה

72 Beautifying SELECT distinct str(?e) as ?eng, str(?h) as ?heb {
?x dbp:classis dbr:Mammal. ?x owl:sameAs ?y. ?x rdfs:label ?e. GRAPH ?g { ?y rdfs:label ?h. } FILTER(LANG(?h)="he" && LANG(?e)="en")

73

74 Additional Features (SPARQL 1.1)
Aggregate Queries Property Path 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(*)) select ?s { ?s rdf:type dbo:Scientist. ?s (dbo:doctoralAdvisor)+ dbr:Alonzo_Church. } 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 city c dbr:Tel_Aviv 30 dbr:Haifa 16 dbr:Rehovot 6 dbr: Petah_Tikva 4 dbr:Tiberias 2 dbr:Safed 1 dbr:Nazareth

75 Advisory Graph dbr:Alonzo_Church dbo:doctoralAdvisor dbr:Alan_Turing
dbr:Robin_Gandy dbr:Jeff_Paris dbr:Michael_O._Rabin dbo:doctoralAdvisor dbr:Saharon_Shelah dbr:Dov_Gabbay

76

77 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

78 Example (Wikipedia) SELECT ?x { ?x rdf:type ex:animal } ex:dog1
ex:cat1 ex:cat ex:zoo1 zoo:host ex:cat2 SELECT ?x { ?x rdf:type ex:animal } x ex:dog1 rdf:type ex:dog1 ex:animal rdf:type ex:cat1 ex:cat ex:cat2 ex:zoo1 zoo:host

79 Example (Wikipedia) SELECT ?x { ?x rdf:type ex:animal } ex:dog1
ex:cat1 ex:cat ex:zoo1 zoo:host ex:cat2 rdfs:subClassOf rdfs:range SELECT ?x { ?x rdf:type ex:animal } x ex:dog1 ex:cat1 ex:cat2 rdf:type ex:dog1 ex:animal rdfs:subClassOf rdfs:range rdf:type ex:cat1 ex:cat ex:cat2 ex:cat zoo:host

80 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

81 Inference System for RDFS
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) (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)

82 Example dbr:Israel ex:minister ex:Gila_Gamliel ex:finance_minister
ex:Moshe_Kahlon rdfs:subPropertyOf rdfs:range dbr:politician rdfs:subClassOf dbo:person dbr:Israel ex:minister ex:Moshe_Kahlon ex:Gila_Gamliel drf:type dbr:politician ex:Gila_Gamliel drf:type dbo:person ex:Moshe_Kahlon drf:type dbr:politician ex:Moshe_Kahlon drf:type dbo:person IL minister IL finance_minister politician IL minister person politician person

83 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) PRDFS(G) = P(cl(G))

84 Example SELECT ?x { PRDFS(G) ?x rdf:type dbo:Scientist.
dbr:Moshe_Vardi dbo:doctoralAdvisor dbr:Catriel_Beeri rdfs:domain dbo:Scientist dbo:birthPlace dbr:Haifa dbr:Ron_Kimmel rdf:type SELECT ?x { ?x rdf:type dbo:Scientist. ?x dbo:birthPlace dbr:Haifa } PRDFS(G) x dbr:Ron_Kimmel dbr:Moshe_Vardi P(G) x dbr:Ron_Kimmel

85 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

86 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

87 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


Download ppt "Database Management Systems"

Similar presentations


Ads by Google