Download presentation
Presentation is loading. Please wait.
Published byOwen Shepherd Modified over 9 years ago
1
ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ, ΑΠΘ ΜΕΤΑΠΤΥΧΙΑΚΟ ΠΡΟΓΡΑΜΜΑ ΣΠΟΥΔΩΝ Κατεύθυνση Πληροφοριακών Συστημάτων - 1ο Εξάμηνο Σημασιολογικός Ιστός lpis.csd.auth.gr/mtpx/sw/index.htm Διδάσκων: Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ Μαθήματα: 5-6
2
Chapter 3 Describing Web Resources in RDF Grigoris Antoniou Frank van Harmelen
3
Chapter 3A Semantic Web Primer, 2nd Edition 3-3 Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data
4
Chapter 3A Semantic Web Primer, 2nd Edition 3-4 Drawbacks of XML XML is a universal metalanguage for defining markup It provides a uniform framework for interchange of data and metadata between applications However, XML does not provide any means of talking about the semantics (meaning) of data E.g., there is no intended meaning associated with the nesting of tags – It is up to each application to interpret the nesting.
5
Chapter 3A Semantic Web Primer, 2nd Edition 3-5 John Smith Algorithms aem153 aem202 … Nesting of tag A in B can be interpreted as: – Α is a part of Β – Α is a subset of Β – Α is a member of Β – Α is a property of Β Nesting of Tags in XML
6
Chapter 3A Semantic Web Primer, 2nd Edition 3-6 Nesting of Tags in XML David Billington is a lecturer of Discrete Maths David Billington Discrete Maths Opposite nesting, same information!
7
Chapter 3A Semantic Web Primer, 2nd Edition 3-7 Basic Ideas of RDF All information is represented as a set of Statements Basic building block (statement): object-attribute-value triple (or triplet) – Sentence about Billington is such a statement RDF has been given a syntax in XML – This syntax inherits the benefits of XML – Other syntactic representations of RDF possible
8
Chapter 3A Semantic Web Primer, 2nd Edition 3-8 Basic Ideas of RDF (2) The fundamental concepts of RDF are: – Resources (objects, sometimes values) – Properties (attributes) – Statements (triplets)
9
Chapter 3A Semantic Web Primer, 2nd Edition 3-9 Resources We can think of a resource as an object, a “thing” we want to talk about – E.g. authors, books, publishers, places, people, hotels Every resource has a URI, a Universal Resource Identifier A URI can be – a URL (Web address) or – some other kind of unique identifier
10
Chapter 3A Semantic Web Primer, 2nd Edition 3-10 URIs An identifier does not necessarily enable access to a resource. URI schemes have been defined not only for web- locations – E.g. telephone numbers, ISBN numbers (urn:isbn:960- 7013-28-Χ), geographic locations, etc. There has been a long discussion about the nature of URIs, even touching philosophical questions – E.g., what is an appropriate unique identifier for a person? – We assume that a URI is the identifier of a Web resource.
11
Chapter 3A Semantic Web Primer, 2nd Edition 3-11 Properties Properties describe relations between resources – E.g. “written by”, “age”, “title”, etc. Properties are a special kind of resources – Also identified by URIs Advantages of using URIs: – Α global, worldwide, unique naming scheme – Reduces the homonym problem of distributed data representation
12
Chapter 3A Semantic Web Primer, 2nd Edition 3-12 Statements Statements assert the properties of resources – Similar to a statement in natural language A statement is an object-attribute-value triple – It consists of a resource, a property, and a value – NL view: subject - predicate - object Values can be resources or literals – Literals are atomic values (strings)
13
Chapter 3A Semantic Web Primer, 2nd Edition 3-13 Three Views of a Statement A triple A piece of a graph A piece of XML code Thus an RDF document can be viewed as: A set of triples A graph (semantic net) An XML document
14
Chapter 3A Semantic Web Primer, 2nd Edition 3-14 Statements as Triples ( http://www.cit.gu.edu.au/~db, http://www.mydomain.org/site-owner, “David Billington” ) The triple (x,P,y) can be considered as a logical formula P(x,y) – Binary predicate P relates object x to object y – RDF offers only binary predicates (properties)
15
Turtle syntax Terse RDF Triple Language (Turtle) is a text based syntax for RDF. – The file extension used for Turtle text files is “.ttl” “David Billington”. 3-15 A Semantic Web Primer, 2nd EditionChapter 3
16
A Semantic Web Primer, 2nd Edition 3-16 Statements as Graphs A directed graph with labeled nodes and arcs – from the resource (the subject of the statement) – to the value (the object of the statement) Known in AI as a semantic net The value of a statement may be a resource – Ιt may be linked to other resources
17
Chapter 3A Semantic Web Primer, 2nd Edition 3-17 A Set of Triples as a Semantic Net
18
Note on the example In this case, David Bilington should be a resource – NOT a literal. 3-18 Lectures 4 & 5: Knowledge Representation on the Web: Semantic Networks & RDF
19
Chapter 3A Semantic Web Primer, 2nd Edition 3-19 Statements in XML Syntax Graphs are a powerful tool for human understanding but The Semantic Web vision requires machine- accessible and machine-processable representations There is a 3rd representation based on XML – But XML is not a part of the RDF data model – E.g. serialisation of XML is irrelevant for RDF
20
Chapter 3A Semantic Web Primer, 2nd Edition 3-20 Statements in XML (2) <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://www.mydomain.org/my-rdf-ns"> David Billington subject predicate object
21
Chapter 3A Semantic Web Primer, 2nd Edition 3-21 Statements in XML (3) An RDF document is represented by an XML element with the tag rdf:RDF The content of this element is a number of descriptions, which use rdf:Description tags. Every description makes a statement about a resource, identified in 3 ways: – an about attribute, referencing an existing resource – an ID attribute, creating a new resource – without a name, creating an anonymous resource
22
Chapter 3A Semantic Web Primer, 2nd Edition 3-22 Statements in XML (4) The rdf:Description element makes a statement about the resource http://www.cit.gu.edu.au/~db Within the description – the property is used as a tag – the content is the value of the property
23
Chapter 3A Semantic Web Primer, 2nd Edition 3-23 Data Types Data types are used in programming languages to allow interpretation In RDF, typed literals are used, if necessary ( “David Billington”, http://www.mydomain.org/age, “27”^^http://www.w3.org/2001/XMLSchema#integer)
24
Chapter 3A Semantic Web Primer, 2nd Edition 3-24 Data Types (2) ^^-notation indicates the type of a literal In practice, the most widely used data typing scheme will be the one by XML Schema – But the use of any externally defined data typing scheme is allowed in RDF documents XML Schema predefines a large range of data types – E.g. Booleans, integers, floating-point numbers, times, dates, etc.
25
Chapter 3A Semantic Web Primer, 2nd Edition 3-25 A Critical View of RDF: Binary Predicates RDF uses only binary properties – This is a restriction because often we use predicates with more than 2 arguments – But binary predicates can simulate these Example: referee(X,Y,Z) – X is the referee in a chess game between players Y and Z
26
Chapter 3A Semantic Web Primer, 2nd Edition 3-26 A Critical View of RDF: Binary Predicates (2) We introduce: – a new auxiliary resource chessGame – the binary predicates ref, player1, and player2 We can represent referee(X,Y,Z) as: ref(chessGame,X) player1(chessGame,Y) player2(chessGame,Z)
27
Chapter 3A Semantic Web Primer, 2nd Edition 3-27 A Critical View of RDF: Properties Properties are special kinds of resources – Properties can be used as the object in an object- attribute-value triple (statement) – They are defined independent of resources This possibility offers flexibility But it is unusual for modelling languages and OO programming languages – It can be confusing for modellers
28
Chapter 3A Semantic Web Primer, 2nd Edition 3-28 A Critical View of RDF: XML Syntax The XML-based syntax of RDF is well suited for machine processing It is not particularly human-friendly – The Semantic Web will not be programmed in RDF, but rather with user-friendly tools that will automatically translate higher representations (e.g. icons) into RDF.
29
Chapter 3A Semantic Web Primer, 2nd Edition 3-29 A Critical View of RDF: Summary RDF has its idiosyncrasies and is not an optimal modeling language but It is already a de facto standard It has sufficient expressive power – At least as for more layers to build on top Using RDF offers the benefit that information maps unambiguously to a model
30
Chapter 3A Semantic Web Primer, 2nd Edition 3-30 Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data
31
Chapter 3A Semantic Web Primer, 2nd Edition 3-31 XML-Based Syntax of RDF An RDF document consists of an rdf:RDF element – The content of that element is a number of descriptions A namespace mechanism is used – Disambiguation – Namespaces are expected to be RDF documents defining resources that can be reused – Large, distributed collections of knowledge
32
Chapter 3A Semantic Web Primer, 2nd Edition 3-32 Example of University Courses <!DOCTYPE rdf:RDF [ ]> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:uni="http://www.mydomain.org/uni-ns#"> David Billington Associate Professor 27
33
Chapter 3A Semantic Web Primer, 2nd Edition 3-33 Example of University Courses (2) Discrete Maths David Billington Programming III Michael Maher
34
Chapter 3A Semantic Web Primer, 2nd Edition 3-34 ENTITY definition Entities are like macros (e.g. #define) in programming languages If something is declared as an ENTITY, it can be used in the XML document with (&) in front and (;) at the back – E.g. &xsd;
35
Chapter 3A Semantic Web Primer, 2nd Edition 3-35 rdf:about versus rdf:ID An element rdf:Description has – An rdf:about attribute indicating that the resource has been “defined” elsewhere, or – An rdf:ID attribute indicating that the resource is defined here Formally, there is no such thing as “defining” an object in one place and referring to it elsewhere – Sometimes is useful (for human readability) to have a defining location, while other locations state “additional” properties
36
Chapter 3A Semantic Web Primer, 2nd Edition 3-36 Referencing with rdf:about For a correct RDF document, all occurrences of course and staff ID’s (e.g. CIT3112) should be represented by references to the external namespace
37
Referencing with rdf:about The use of “#” in front of a “local name” indicates that the resource is a part of the current document – The full URI of the resource is obtained by the URI of the current document, plus “#CIT3112” 3-37 A Semantic Web Primer, 2nd EditionChapter 3
38
A Semantic Web Primer, 2nd Edition 3-38 Property Elements Content of rdf:Description elements Knowledge Representation Grigoris Antoniou uni:courseName and uni:isTaughtBy define two property-value pairs for CIT3116 (two RDF statements) – read conjunctively
39
Chapter 3A Semantic Web Primer, 2nd Edition 3-39 Data Types The attribute rdf:datatype="&xsd;integer" is used to indicate the data type of the value of the age property David Billington Associate Professor 27
40
Chapter 3A Semantic Web Primer, 2nd Edition 3-40 Data Types (2) The age property has been defined to have "&xsd;integer" as its range – It is still required to indicate the type of the value of this property each time it is used – This is to ensure that an RDF processor can assign the correct type of the property value even if it has not "seen" the corresponding RDF Schema definition before – This scenario is quite likely to occur in the unrestricted WWW
41
Chapter 3A Semantic Web Primer, 2nd Edition 3-41 The rdf:resource Attribute The relationships between courses and lecturers (in the example) were not formally defined but existed implicitly through the use of the same name The use of the same name may just be a coincidence for a machine We can denote that two entities are the same using the rdf:resource attribute
42
Chapter 3A Semantic Web Primer, 2nd Edition 3-42 The rdf:resource Attribute (2) Discrete Mathematics David Billington Associate Professor
43
Chapter 3A Semantic Web Primer, 2nd Edition 3-43 Referencing Externally Defined Resources E.g., to refer the externally defined resource CIT1111: http://www.mydomain.org/uni-ns#CIT1111 as the value of rdf:about – www.mydomain.org/uni-ns is the URI where the definition of CIT1111 is found A description with an ID defines a fragment URI, which can be used to reference the defined description
44
The rdf:resource Attribute (3) Discrete Mathematics David Billington Associate Professor 3-44 A Semantic Web Primer, 2nd EditionChapter 3
45
A Semantic Web Primer, 2nd Edition 3-45 Nested Descriptions: Example Discrete Maths David Billington Associate Professor
46
Chapter 3A Semantic Web Primer, 2nd Edition 3-46 Nested Descriptions Descriptions may be defined within other descriptions Other courses, such as CIT3112, can still refer to the new resource with ID T949318 Although a description may be defined within another description, its scope is global
47
Chapter 3A Semantic Web Primer, 2nd Edition 3-47 Introducing some Structure to RDF Documents using the rdf:type Element In the examples, the descriptions fall into 2 categories: courses and lecturers. This is clear to human readers It has not been formally declared anywhere It is not accessible to machines In RDF it is possible to make such statements using the rdf:type element.
48
Chapter 3A Semantic Web Primer, 2nd Edition 3-48 Example of using the rdf:type Element Discrete Maths David Billington Associate Professor
49
Chapter 3A Semantic Web Primer, 2nd Edition 3-49 Abbreviated Syntax Simplification rules: 1. Childless property elements within description elements may be replaced by XML attributes 2. For description elements with a typing element we can use the name specified in the rdf:type element instead of rdf:Description These rules create syntactic variations of the same RDF statement – They are equivalent according to the RDF data model, although they have different XML syntax
50
Chapter 3A Semantic Web Primer, 2nd Edition 3-50 Abbreviated Syntax: Example <rdf:type rdf:resource="http://www.mydomain.org/ uni-ns#course"/> Discrete Maths
51
Chapter 3A Semantic Web Primer, 2nd Edition 3-51 Application of First Simplification Rule <rdf:Description rdf:ID="CIT1111" uni:courseName="Discrete Maths"> <rdf:type rdf:resource="http://www.mydomain.org/ uni-ns#course"/>
52
Chapter 3A Semantic Web Primer, 2nd Edition 3-52 Application of 2nd Simplification Rule <uni:course rdf:ID="CIT1111" uni:courseName="Discrete Maths">
53
Chapter 3A Semantic Web Primer, 2nd Edition 3-53 Container Elements Collect a number of resources or attributes about which we want to make statements as a whole E.g., we may wish to talk about the courses given by a particular lecturer The content of container elements are named rdf:_1, rdf:_2, etc. – Alternatively rdf:li
54
Chapter 3A Semantic Web Primer, 2nd Edition 3-54 Three Types of Container Elements rdf:Bag an unordered container, allowing multiple occurrences – E.g. members of the faculty board, documents in a folder rdf:Seq an ordered container, which may contain multiple occurrences – E.g. modules of a course, items on an agenda, an alphabetized list of staff members (order is imposed) rdf:Alt a set of alternatives – E.g. the document home and mirrors, translations of a document in various languages
55
Chapter 3A Semantic Web Primer, 2nd Edition 3-55 Example for a Bag <uni:lecturer rdf:ID="T949352" uni:name="Grigoris Antoniou" uni:title="Professor">
56
Chapter 3A Semantic Web Primer, 2nd Edition 3-56 Example for Alternative <uni:course rdf:ID="CIT1111" uni:courseName="Discrete Mathematics">
57
Chapter 3A Semantic Web Primer, 2nd Edition 3-57 rdf:ID Attribute for Container Elements <uni:lecturer rdf:ID="T949318" uni:name="David Billington">
58
RDF Collections A limitation of these containers is that there is no way to close them – “these are all the members of the container” – E.g. one may write the following and add one more course to David Billington 3-58 A Semantic Web Primer, 2nd EditionChapter 3
59
A Semantic Web Primer, 2nd Edition 3-59 RDF Collections (2) RDF provides support for describing groups containing only the specified members, in the form of RDF collections – list structure in the RDF graph – constructed using a predefined collection vocabulary: rdf:List, rdf:first, rdf:rest and rdf:nil It is like Prolog/LISP lists or linked lists in data structures
60
Chapter 3A Semantic Web Primer, 2nd Edition 3-60 RDF Collections (3) A list with 3 elements …
61
Chapter 3A Semantic Web Primer, 2nd Edition 3-61 RDF Collections (4) A list with 3 elements Shorthand syntax: – "Collection" value for the rdf:parseType attribute:
62
Parsing RDF/XML There are many RDF parsers, i.e. tools that take as input and RDF/XML document and output a set of RDF triples – These are called “explicit triplets” The most prominent one is the W3C RDF parser/validator – http://www.w3.org/RDF/Validator/ http://www.w3.org/RDF/Validator/ 3-62 A Semantic Web Primer, 2nd EditionChapter 3
63
W3C RDF Validation/Parsing 3-63 A Semantic Web Primer, 2nd EditionChapter 3
64
RDF Validation Results - Triples 3-64 A Semantic Web Primer, 2nd EditionChapter 3 "David Billington".http://www.mydomain.org/uni-ns#T949318http://www.mydomain.org/uni-ns#name "Associate Professor".http://www.mydomain.org/uni-ns#T949318http://www.mydomain.org/uni-ns#title http://www.mydomain.org/uni-ns#T949318 http://www.mydomain.org/uni-ns#age "27"^^. "Discrete Maths".http://www.mydomain.org/uni-ns#CIT1111http://www.mydomain.org/uni-ns#courseName http://www.mydomain.org/uni-ns#CIT1111 http://www.mydomain.org/uni-ns#isTaughtBy.http://www.mydomain.org/uni-ns#T949318
65
RDF Validation Results - Graph 3-65 A Semantic Web Primer, 2nd EditionChapter 3
66
@prefix uni:. @prefix rdf:. uni:CIT1111 uni:courseName "Discrete Maths"; uni:isTaughtBy uni:T949318. uni:T949318 uni:age "27"^^ ; uni:name "David Billington"; uni:title "Associate Professor". Turtle syntax 3-66 A Semantic Web Primer, 2nd Edition The sign “;” indicates that the subsequent triples share the same subject with the first triple This is how namespaces are declared Chapter 3
67
Turtle syntax (or N3) You can use – http://www.rdfabout.com/demo/validator/ http://www.rdfabout.com/demo/validator/ – http://rdf-translator.appspot.com/ http://rdf-translator.appspot.com/ Other features of Turtle syntax: – Allows to abbreviate common data types uni:T949318 uni:age 27. – Named graphs: a way to treat a set of triples as a single resource 3-67 A Semantic Web Primer, 2nd EditionChapter 3
68
Named Graphs @prefix uni:. @prefix rdf:. @prefix dc:. { dc:creator } { uni:CIT1111 uni:courseName "Discrete Maths"; uni:isTaughtBy uni:T949318. uni:T949318 uni:age "27"^^ ; uni:name "David Billington"; uni:title "Associate Professor". } 3-68 A Semantic Web Primer, 2nd EditionChapter 3
69
A Semantic Web Primer, 2nd Edition 3-69 Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data
70
Chapter 3A Semantic Web Primer, 2nd Edition 3-70 Basic Ideas of RDF Schema RDF is a universal language that lets users describe resources in their own vocabularies – RDF does not assume, nor does it define semantics of any particular application domain The user can do so in RDF Schema using: – Classes and Properties – Class Hierarchies and Inheritance – Property Hierarchies
71
Chapter 3A Semantic Web Primer, 2nd Edition 3-71 Classes and their Instances We must distinguish between – Concrete “things” (individual objects) in the domain: Discrete Maths, David Billington etc. – Sets of individuals sharing properties called classes: lecturers, students, courses etc. Individual objects that belong to a class are referred to as instances of that class The relationship between instances and classes in RDF is through rdf:type
72
Chapter 3A Semantic Web Primer, 2nd Edition 3-72 Why Classes are Useful Impose restrictions on what can be stated in an RDF document using the schema – As in programming languages – E.g. A+1, where A is an array – Disallow nonsense from being stated
73
Chapter 3A Semantic Web Primer, 2nd Edition 3-73 Nonsensical Statements disallowed through the Use of Classes Discrete Maths is taught by Concrete Maths – We want courses to be taught by lecturers only – Restriction on values of the property “is taught by” (range restriction) Room MZH5760 is taught by David Billington – Only courses can be taught – This imposes a restriction on the objects to which the property can be applied (domain restriction)
74
Chapter 3A Semantic Web Primer, 2nd Edition 3-74 Class Hierarchies Classes can be organised in hierarchies – A is a subclass of B if every instance of A is also an instance of B – Then B is a superclass of A A subclass graph need not be a tree – A class may have multiple superclasses
75
Chapter 3A Semantic Web Primer, 2nd Edition 3-75 Class Hierarchy Example
76
Chapter 3A Semantic Web Primer, 2nd Edition 3-76 Inheritance in Class Hierarchies Range restriction: Courses must be taught by academic staff members only Michael Maher is a professor – He inherits the ability to teach from the class of academic staff members This is done in RDF Schema by fixing the semantics of “is a subclass of” – It is not up to an application (RDF processing software) to interpret “is a subclass of”
77
Chapter 3A Semantic Web Primer, 2nd Edition 3-77 Differences with Object-Oriented Programming In OO programming, an object class defines the properties that apply to it. – To add new properties we modify the class. In RDFS, properties are defined globally – Not encapsulated as attributes in class definitions – Define new properties for an existing class without changing the class Use classes defined by others and adapt them to our requirements through new properties. – Another idiosyncratic feature of RDF/RDFS.
78
Chapter 3A Semantic Web Primer, 2nd Edition 3-78 Property Hierarchies Hierarchical relationships for properties – E.g., “is taught by” is a subproperty of “involves” – If a course C is taught by an academic staff member A, then C also involves Α The converse is not necessarily true – E.g., A may be the teacher of the course C, or – a tutor who marks student homework but does not teach C P is a subproperty of Q, if Q(x,y) is true whenever P(x,y) is true – E.g. father is a subproperty of parent
79
Chapter 3A Semantic Web Primer, 2nd Edition 3-79 RDF Layer vs RDF Schema Layer Discrete Mathematics is taught by David Billington The schema is itself written in a formal language, RDF Schema, that can express its ingredients: – subClassOf, Class, Property, subPropertyOf, Resource, etc.
80
RDF Layer vs RDF Schema Layer (2) Chapter 3 3-80 A Semantic Web Primer, 2nd Edition
81
Chapter 3A Semantic Web Primer, 2nd Edition 3-81 Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data
82
Chapter 3A Semantic Web Primer, 2nd Edition 3-82 RDF Schema in RDF The modeling primitives of RDF Schema are defined using resources and properties (RDF itself is used!) To declare that “lecturer” is a subclass of “academic staff member” – Define resources lecturer, academicStaffMember – define property subClassOf – Write triple (lecturer, subClassOf, academicStaffMember) We use the XML-based syntax of RDF
83
Chapter 3A Semantic Web Primer, 2nd Edition 3-83 Core Classes rdfs:Resource, the class of all resources rdfs:Class, the class of all classes rdfs:Literal, the class of all literals (strings) rdf:Property, the class of all properties.
84
Chapter 3A Semantic Web Primer, 2nd Edition 3-84 Core Properties rdf:type, relates a resource to its class – The resource is declared to be an instance of that class rdfs:subClassOf, relates a class to one of its superclasses – All instances of a class are instances of its superclass rdfs:subPropertyOf, relates a property to one of its superproperties
85
Chapter 3A Semantic Web Primer, 2nd Edition 3-85 Core Properties (2) rdfs:domain, specifies the domain of a property P – The class of those resources that may appear as subjects in a triple with predicate P – If the domain is not specified, then any resource can be the subject rdfs:range, specifies the range of a property P – The class of those resources that may appear as values in a triple with predicate P
86
Chapter 3A Semantic Web Primer, 2nd Edition 3-86 Examples (abbreviated syntax) <rdfs:range rdf:resource="http://www.w3.org/ 2000/01/rdf-schema#Literal"/>
87
Chapter 3A Semantic Web Primer, 2nd Edition 3-87 Examples (long syntax)
88
Chapter 3A Semantic Web Primer, 2nd Edition 3-88 Relationships Between Core Classes and Properties rdfs:subClassOf and rdfs:subPropertyOf are transitive, by definition rdfs:Class is a subclass of rdfs:Resource – Because every class is a resource rdfs:Resource is an instance of rdfs:Class – rdfs:Resource is the class of all resources, so it is a class Every class is an instance of rdfs:Class – For the same reason
89
Chapter 3A Semantic Web Primer, 2nd Edition 3-89 Subclass Hierarchy of some Modeling Primitives of RDF Schema
90
Chapter 3A Semantic Web Primer, 2nd Edition 3-90 Instance Relationships of some Modeling Primitives of RDFS
91
Chapter 3A Semantic Web Primer, 2nd Edition 3-91 Instance Relationships of Some Core Properties of RDF and RDF Schema
92
Chapter 3A Semantic Web Primer, 2nd Edition 3-92 Containers rdf:Bag, the class of bags rdf:Seq, the class of sequences rdf:Alt, the class of alternatives rdfs:Container, the superclass of all container classes, including the 3 above
93
Chapter 3A Semantic Web Primer, 2nd Edition 3-93 Utility Properties rdfs:seeAlso relates a resource to another resource that explains it rdfs:isDefinedBy is a subproperty of rdfs:seeAlso and relates a resource to the place where its definition, typically an RDF schema, is found rfds:comment. Comments, typically longer text, can be associated with a resource rdfs:label. A human-friendly label (name) is associated with a resource
94
Chapter 3A Semantic Web Primer, 2nd Edition 3-94 Example: A University The class of lecturers. All lecturers are academic staff members. <rdfs:subClassOf rdf:resource="#academicStaffMember"/>
95
Chapter 3A Semantic Web Primer, 2nd Edition 3-95 Example: A University (2) The class of academic staff members The class of staff members
96
Chapter 3A Semantic Web Primer, 2nd Edition 3-96 Example: A University (3) The class of courses It relates only courses to lecturers
97
Chapter 3A Semantic Web Primer, 2nd Edition 3-97 Example: A University (4) Inherits its domain ("course") and range ("lecturer") from its superproperty "involves"
98
Chapter 3A Semantic Web Primer, 2nd Edition 3-98 Example: A University (5) It is a property of staff members and takes literals as values.
99
Chapter 3A Semantic Web Primer, 2nd Edition 3-99 Class Hierarchy for the Motor Vehicles Example
100
Chapter 3A Semantic Web Primer, 2nd Edition 3- 100 Example: Motor Vehicles (1) <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
101
Chapter 3A Semantic Web Primer, 2nd Edition 3- 101 Example: Motor Vehicles (2)
102
Chapter 3A Semantic Web Primer, 2nd Edition 3- 102 Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data
103
Chapter 3A Semantic Web Primer, 2nd Edition 3- 103 The Namespace of RDF <rdfs:Class rdf:ID="Property" rdfs:comment=" The class of properties "/> The class of unordered containers
104
Chapter 3A Semantic Web Primer, 2nd Edition 3- 104 The Namespace of RDF (2) The class of RDF Lists The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it
105
The Namespace of RDF (3) The subject is an instance of a class The first item in the subject RDF list The rest of the subject RDF list after the first item 3- 105 A Semantic Web Primer, 2nd EditionChapter 3
106
A Semantic Web Primer, 2nd Edition 3- 106 The Namespace of RDF Schema <rdfs:Class rdf:ID="Resource" rdfs:comment="The most general class"/> <rdfs:Class rdf:ID="Class" rdfs:comment="The concept of classes. All classes are resources"/> <rdf:Property rdf:ID="comment" rdfs:comment="Use this for descriptions"/>
107
Chapter 3A Semantic Web Primer, 2nd Edition 3- 107 The Namespace of RDF Schema (2) <rdfs:domain rdf:resource="http://www.w3.org/ 1999/02/22-rdf-syntax-ns#Property"/> <rdfs:range rdf:resource="http://www.w3.org/ 1999/02/22-rdf-syntax-ns#Property"/>
108
Chapter 3A Semantic Web Primer, 2nd Edition 3- 108 Namespace versus Semantics Consider rdfs:subClassOf – The namespace specifies only that it applies to classes and has a class as a value – The meaning of being a subclass not expressed The meaning cannot be expressed in RDF – If it could, RDF Schema would be unnecessary External definition of semantics required – Respected by RDF/RDFS processing software
109
Chapter 3A Semantic Web Primer, 2nd Edition 3- 109 Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data
110
Chapter 3A Semantic Web Primer, 2nd Edition 3- 110 Problem of Axiomatic Semantics The described axiomatic semantics can be used for automated reasoning with RDF and RDF Schema. It requires a first-order logic proof system. – This is a very heavy requirement It is unlikely to scale when millions of statements are involved – E.g. millions of statements of the form Type(?r, ?c)
111
Chapter 3A Semantic Web Primer, 2nd Edition 3- 111 Semantics based on Inference Rules Semantics in terms of RDF triples instead of restating RDF in terms of first-order logic – Plus sound and complete inference systems This inference system consists of inference rules of the form: IF E contains certain triples THEN add to E certain additional triples where E is an arbitrary set of RDF triples – Usually the set of explicit triples of an RDF document
112
Inference rules (or entailments) Inference rules add new triples to an existing set of triples so that a query can retrieve the correct set of triples according to RDF/S semantics Entailments are “materialized” conclusions of inference rules 3- 112 A Semantic Web Primer, 2nd EditionChapter 3
113
Inference / Query Process 3- 113 A Semantic Web Primer, 2nd Edition Original (explicit) set of triples RDF document translation RDF/S Inference rules input Inferred (implicit) set of triples output Set of all triples Query Chapter 3
114
A simple rule language The condition of a rule contains patterns of triples that are “searched” (or “matched”) against the current set of triples – Both explicit and implicit If the condition of the rule is true (i.e. there are triples that match the pattern), then the pattern of triples of the conclusion are added to the current set of triples (or triple DB) 3- 114 A Semantic Web Primer, 2nd EditionChapter 3
115
Constants and Variable Constants are RDF/S “reserved” names (classes/properties) – They could also be literals or resource names Variables begin with ? – They denote any value that could match the pattern in this place – Variables are logical ones: once they match with a value, they keep it throughout rule evaluation 3- 115 A Semantic Web Primer, 2nd EditionChapter 3
116
A Semantic Web Primer, 2nd Edition 3- 116 Examples of Inference Rules (1) Any resource ?p that is used in the property position of a triple can be inferred to be a member of the class rdf:Property. IF ?x ?p ?y. THEN?p rdf:type rdf:Property. Example (explicit triple): uni:CIT1111 uni:courseName "Discrete Maths". Conclusion (implicit triple): uni:courseName rdf:type rdf:Property.
117
Chapter 3A Semantic Web Primer, 2nd Edition 3- 117 Examples of Inference Rules (2a) Definition of the meaning of rdfs:subClassOf IF ?x rdf:type ?u. and ?u rdfs:subClassOf ?v. THEN ?x rdf:type ?v. Example (explicit triple): uni:CIT1111 rdf:type uni:PostGraduateCourse. uni:PostGraduateCourse rdfs:subClassOf uni:Course. Conclusion (implicit triple): uni:CIT1111 rdf:type uni:Course.
118
Examples of Inference Rules (2b) Transitivity of the subclass relation IF ?u rdfs:subClassOf ?v. and ?v rdfs:subclassOf ?w. THEN ?u rdfs:subClassOf ?w. Example (explicit triple): uni:Lecturer rdfs:subClassOf uni:Faculty. uni:Faculty rdfs:subClassOf uni:Staff. Conclusion (implicit triple): uni:Lecturer rdfs:subClassOf uni:Staff. 3- 118 A Semantic Web Primer, 2nd EditionChapter 3
119
A Semantic Web Primer, 2nd Edition 3- 119 Examples of Inference Rules (3a) Any resource ?y which appears as the value of a property ?p can be inferred to be a member of the range of ?p – This shows that range definitions in RDF Schema are not used to restrict the range of a property, but rather to infer the membership of the range IF ?x ?p ?y. and ?p rdfs:range ?u. THEN ?y rdf:type ?u.
120
Examples of Inference Rules (3b) IF ?x ?p ?y. and ?p rdfs:range ?u. THEN ?y rdf:type ?u. Example (explicit triple): uni:T949348 uni:teaches uni:CIT1111. uni:teaches rdfs:range uni:Course. Conclusion (implicit triple): uni:CIT1111 rdf:type uni:Course. 3- 120 A Semantic Web Primer, 2nd EditionChapter 3
121
Other entailment rules (a) Domain IF ?x ?p ?y. and ?p rdfs:domain ?u. THEN ?x rdf:type ?u. Example (explicit triple): uni:T949348 uni:teaches uni:CIT1111. uni:teaches rdfs:domain uni:Faculty. Conclusion (implicit triple): uni:T949348 rdf:type uni:Faculty. 3- 121 A Semantic Web Primer, 2nd EditionChapter 3
122
Other entailment rules (b) Every node of the semantic net is a Resource IF ?x ?p ?y. THEN ?x rdf:type rdfs:Resource. IF ?x ?p ?y. THEN ?y rdf:type rdfs:Resource. Example (explicit triple): uni:T949348 uni:teaches uni:CIT1111. Conclusion (implicit triple): uni:T949348 rdf:type rdfs:Resource. uni:CIT1111 rdf:type rdfs:Resource. 3- 122 A Semantic Web Primer, 2nd EditionChapter 3
123
Sub-property entailment rules (a) What it means to be a subproperty IF ?a rdfs:subPropertyOf ?b. and ?x ?a ?y. THEN ?x ?b ?y. Example (explicit triple): uni:CIT1111 uni:isTaughtBy uni:T949348. uni:isTaughtBy rdfs:subPropertyOf uni:involves. Conclusion (implicit triple): uni:CIT1111 uni:involves uni:T949348. 3- 123 A Semantic Web Primer, 2nd EditionChapter 3
124
Sub-property entailment rules (b) Transitivity of subproperty relation IF ?u rdfs:subPropertyOf ?v. and ?v rdfs:subPropertyOf ?w. THEN ?u rdfs:subPropertyOf ?w. Example (explicit triple): ex:father rdfs:subPropertyOf ex:parent. ex:parent rdfs:subPropertyOf ex:ancestor. Conclusion (implicit triple): ex:father rdfs:subPropertyOf ex:ancestor. 3- 124 Lectures 4 & 5: Knowledge Representation on the Web: Semantic Networks & RDF
125
Sub-property inheritance of domain/range (a) IF ?a rdfs:subPropertyOf ?b. and ?b rdfs:domain ?u. THEN ?a rdfs:domain ?u. IF ?a rdfs:subPropertyOf ?b. and ?b rdfs:range ?u. THEN ?a rdfs:range ?u. 3- 125 A Semantic Web Primer, 2nd EditionChapter 3
126
Sub-property inheritance of domain/range (b) Example (explicit triple): uni:isTaughtBy rdfs:subPropertyOf uni:involves. uni:involves rdfs:domain uni:Course. uni:involves rdfs:range uni:Staff. Conclusion (implicit triple): uni:isTaughtBy rdfs:domain uni:Course. uni:isTaughtBy rdfs:range uni:Staff. 3- 126 A Semantic Web Primer, 2nd EditionChapter 3
127
RDF/RDFS inference uni:lecturer rdf:type rdfs:Class. uni:course rdf:type rdfs:Class. uni:teaches rdf:type rdf:Property. uni:teaches rdfs:domain uni:lecturer. uni:teaches rdfs:range uni:course. uni:smith rdf:type uni:lecturer. uni:smith uni:teaches uni:math. Conclusion: uni:math rdf:type uni:course. 3- 127 A Semantic Web Primer, 2nd Edition IF ?x ?p ?y. and ?p rdfs:range ?u. THEN ?y rdf:type ?u. Chapter 3
128
RDF/RDFS inference (2) uni:lecturer rdf:type rdfs:Class. uni:course rdf:type rdfs:Class. uni:teaches rdf:type rdfs:Property. uni:teaches rdfs:domain uni:lecturer. uni:teaches rdfs:range uni:course. uni:smith rdf:type uni:lecturer. uni:smith uni:teaches uni:jones. Conclusion: uni:jones rdf:type uni:course. !! 3- 128 A Semantic Web Primer, 2nd EditionChapter 3
129
RDF/RDFS inference (2’) uni:lecturer rdf:type rdfs:Class. uni:course rdf:type rdfs:Class. uni:teaches rdf:type rdfs:Property. uni:teaches rdfs:domain uni:lecturer. uni:teaches rdfs:range uni:course. uni:smith rdf:type uni:lecturer. uni:jones rdf:type uni:lecturer. uni:smith uni:teaches uni:jones. Conclusion: uni:jones rdf:type uni:course. !!!!!!!!! 3- 129 A Semantic Web Primer, 2nd EditionChapter 3
130
A Semantic Web Primer, 2nd Edition 3- 130 RDF/RDFS inference (2’) - explanation An instance can have multiple types simultaneously! – It can be an instance of multiple classes! – It can belong to different classes, because each resource can have multiple roles in general! – It belongs to the intersection of the classes. Big difference with OO programming!
131
… BUT (being instance of multiple classes) When a resource is an instance of two classes … but the two classes have a hierarchical (subClassOf) relationship then the most special class is the class of the resource 3- 131 A Semantic Web Primer, 2nd EditionChapter 3
132
Example of being an instance of multiple classes when one is subclass of the other Example (explicit triple): uni:Faculty rdfs:subClassOf uni:Staff. uni:isTaughtBy rdfs:subPropertyOf uni:involves. uni:isTaughtBy rdfs:domain uni:Course. uni:isTaughtBy rdfs:range uni:Faculty. uni:involves rdfs:domain uni:Course. uni:involves rdfs:range uni:Staff. uni:CIT1111 rdf:type uni:Course. uni:T949348 rdf:type uni:Faculty. uni:CIT1111 uni:isTaughtBy uni:T949348. Conclusion (implicit triple): uni:CIT1111 uni:involves uni:T949348. uni:isTaughtBy rdfs:domain uni:Course. We already know that! uni:CIT1111 rdf:type uni:Course. We already know that! uni:isTaughtBy rdfs:range uni:Staff. Faculty Staff Faculty Staff Faculty uni:T949348 rdf:type uni:Staff. We already know that! (from subclass entailment) Faculty Staff x Faculty x Staff 3- 132 A Semantic Web Primer, 2nd Edition When an inferred triple is already present in the set of triples (either explicit or implicit), it is NOT inserted again! Chapter 3
133
A Semantic Web Primer, 2nd Edition 3- 133 Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data
134
Chapter 3A Semantic Web Primer, 2nd Edition 3- 134 Why an RDF Query Language? Different XML Representations XML at a lower level of abstraction than RDF There are various ways of syntactically representing an RDF statement in XML Thus we would require several XQuery queries, e.g. – //uni:lecturer/uni:title if uni:title element – //uni:lecturer/@uni:title if uni:title attribute – Both XML representations equivalent!
135
Chapter 3A Semantic Web Primer, 2nd Edition 3- 135 Why an RDF Query Language? Understanding the Semantics Grigoris Antoniou David Billington A query for the names of all lecturers should return both Grigoris Antoniou and David Billington
136
SPARQL Query Language A W3C Recommendation for querying RDF – Specification 1.0: http://www.w3.org/TR/rdf-sparql-query/ http://www.w3.org/TR/rdf-sparql-query/ – Specification 1.1: http://www.w3.org/TR/2013/REC-sparql11-query- 20130321/ http://www.w3.org/TR/2013/REC-sparql11-query- 20130321/ All major RDF query tools had implemented support for SPARQL Chapter 3A Semantic Web Primer, 2nd Edition 3- 136
137
Triple stores To perform a SPARQL query, one needs software to execute the query. – Called Triple Store or Graph Store (e.g. a database for RDF) – Sesame (70 million), OpenLink Virtuoso (>15.4 billion), OWLIM (>12 b), Apache Jena (200 m), AllegroGraph (1 trillion), IBM DB2, Oracle, 4store (15 b), Bigdata (12.7 b), YARS2 (7 b), Mulgara (500 m), … 3- 137 A Semantic Web Primer, 2nd EditionChapter 3
138
Loading triples Before one can query a triple store, it needs to be populated with RDF. Most triple stores provide bulk upload options. SPARQL Update: provides a series of mechanisms for inserting, loading, and deleting RDF into a triple store. 3- 138 A Semantic Web Primer, 2nd EditionChapter 3
139
SPARQL protocol A triple store can be queried by sending SPARQL queries using the SPARQL protocol. Each triple store provides an endpoint, where SPARQL queries can be submitted. Clients can send queries to an endpoint using the HTTP protocol. – You can issue a SPARQL query to an endpoint by entering it into the browser’s URL bar – It’s preferable to have a client designed specifically for SPARQL. 3- 139 A Semantic Web Primer, 2nd EditionChapter 3
140
Dbpedia SPARQL endpoint http://dbpedia.org/sparql http://dbpedia.org/sparql 3- 140 A Semantic Web Primer, 2nd Edition More endpoints can be found at: http://ckan.org/ Chapter 3
141
Basic Idea SPARQL is based on matching graph patterns Simplest graph pattern = triple pattern – like an RDF triple – a variable can be in the position of the subject, predicate, or object Combining triple patterns gives a basic graph pattern – An exact match to a graph is needed Chapter 3A Semantic Web Primer, 2nd Edition 3- 141
142
Basic Query Example PREFIX rdf: PREFIX rdfs: SELECT ?c WHERE { ?c rdf:type rdfs:Class. } Chapter 3A Semantic Web Primer, 2nd Edition 3- 142
143
Query Explanation Retrieve all triple patterns – where the property is rdf:type, and – the object is rdfs:Class – I.e. Retrieve all classes SPARQL allows to define prefixes for namespaces – Use prefixes in the query pattern, to make queries shorter and easier to read Chapter 3A Semantic Web Primer, 2nd Edition 3- 143
144
Get all instances of a class PREFIX uni: SELECT ?i WHERE { ?i rdf:type uni:course. } Chapter 3A Semantic Web Primer, 2nd Edition 3- 144
145
SPARQL and RDF Semantics SPARQL makes no explicit commitment to support RDFS semantics. The result depends on whether the system answering the query supports RDFS semantics. – If yes, then result will include all instances of the subclasses of course. – If not, it will only retrieve those instances that are explicitly of type course. Chapter 3A Semantic Web Primer, 2nd Edition 3- 145
146
Using select-from-where SELECT specifies the projection: – the number and order of retrieved data FROM specifies the source being queried – Optional – When not specified, assume querying the knowledge base of a particular system. WHERE imposes constraints on solutions – Graph pattern templates and boolean constraints Chapter 3A Semantic Web Primer, 2nd Edition 3- 146
147
Example Retrieve all phone numbers of staff members SELECT ?x ?y WHERE { ?x uni:phone ?y. } ?x, ?y – variables ?x uni:phone ?y – A resource-property-value triple pattern Chapter 3A Semantic Web Primer, 2nd Edition 3- 147
148
Implicit Join Retrieve all lecturers and their phone numbers SELECT ?x ?y WHERE { ?x rdf:type uni:Lecturer ; uni:phone ?y. } Chapter 3A Semantic Web Primer, 2nd Edition 3- 148 Collects all instances of class Lecturer and binds result to variable ?x Syntax shortcut: a semicolon ; indicates that the following triple pattern shares its subject with the previous one. Collects all triples with predicate phone Implicit join: restrict the 2nd pattern only to those triples whose subject is ?x
149
Equivalent Query SELECT ?x ?y WHERE { ?x rdf:type uni:Lecturer. ?x uni:phone ?y. } Chapter 3A Semantic Web Primer, 2nd Edition 3- 149
150
Retrieve all information about (1) SELECT ?x ?p ?o WHERE { ?x rdf:type uni:Lecturer ; ?p ?o. } 3- 150 A Semantic Web Primer, 2nd EditionChapter 3
151
Retrieve all information about (2) SELECT ?p ?o WHERE { uni:T949352 rdf:type uni:Lecturer ; ?p ?o. } Or SELECT ?p ?o WHERE { uni:T949352 ?p ?o. } 3- 151 A Semantic Web Primer, 2nd EditionChapter 3
152
Limiting results On large data sets we may write queries that can return millions of triples. – E.g. ?i rdf:type dbpedia-owl:Place It is good practice to limit the number of answers a query returns – Public endpoints (e.g. DBPedia) 3- 152 A Semantic Web Primer, 2nd EditionChapter 3
153
LIMIT PREFIX dbpedia-owl:. SELECT ?i WHERE { ?i rdf:type dbpedia-owl:Place. } LIMIT 100 3- 153 A Semantic Web Primer, 2nd EditionChapter 3
154
Explicit Join Retrieve names of courses taught by lecturer with ID T949352 SELECT ?n WHERE { ?x rdf:type uni:Course ; uni:isTaughtBy :T949352. ?c uni:name ?n. FILTER (?c = ?x). } Chapter 3A Semantic Web Primer, 2nd Edition 3- 154 FILTER condition: a boolean constraint Explicit join of variables ?c, ?x using equality ( = ) operator.
155
Another Example with FILTER SELECT ?x ?y WHERE { ?x rdf:type uni:Lecturer ; uni:age ?y. FILTER (?y > 30). } Chapter 3A Semantic Web Primer, 2nd Edition 3- 155
156
SPARQL built-in filter functions Logical: !, &&, || Math: +, -, *, / Comparison: =, !=, >, <,... SPARQL tests: isURI, isBlank, isLiteral, bound SPARQL accessors: str, lang, datatype Strings (SPARQL 1.1): STRLEN, SUBSTR, UCASE, LCASE, STRSTARTS, STRENDS, CONTAINS, CONCAT, … More math (SPARQL 1.1): abs, round, ceil, floor, RAND Date/time (SPARQL 1.1): now, year, month, day, hours, minutes, seconds, timezone Chapter 3A Semantic Web Primer, 2nd Edition 3- 156
157
Optional Patterns The graph patterns so far are mandatory – Either the knowledge base matches the complete pattern, in which case an answer is returned, – or – it doesn’t, in which case the query does not produce a result. However, in many cases we may wish to be more flexible. Chapter 3A Semantic Web Primer, 2nd Edition 3- 157
158
Example RDF fragment Grigoris Antoniou David Billington david@work.example.org Chapter 3A Semantic Web Primer, 2nd Edition 3- 158
159
Optional patterns - Example This fragment contains information on two lecturers. – For one lecturer it only lists the name – For the other it also lists the e-mail address. We want to query for all lecturers and their e- mail addresses Chapter 3A Semantic Web Primer, 2nd Edition 3- 159
160
Querying with mandatory patterns SELECT ?name ?email WHERE { ?x rdf:type uni:Lecturer ; uni:name ?name ; uni:email ?email. } Chapter 3A Semantic Web Primer, 2nd Edition 3- 160
161
Querying with mandatory patterns Result ?name?email David Billingtondavid@work.example.org Chapter 3A Semantic Web Primer, 2nd Edition 3- 161 Despite the fact that Grigoris Antoniou is listed as a lecturer, the query does not return his name. The query pattern does not match because he has no e-mail address.
162
Querying with optional patterns SELECT ?name ?email WHERE { ?x rdf:type uni:Lecturer ; uni:name ?name. OPTIONAL { ?x uni:email ?email } } Chapter 3A Semantic Web Primer, 2nd Edition 3- 162 Meaning: "give all the names of lecturers, and if known also their e-mail addresses"
163
Querying with optional patterns Result Chapter 3A Semantic Web Primer, 2nd Edition 3- 163 ?name?email Grigoris Antoniou David Billingtondavid@work.example.org
164
Querying alternatives We want a contact detail for all lecturers – This can be either a phone or an e-mail SELECT ?name ?contact WHERE { ?x rdf:type uni:Lecturer ; uni:name ?name. {?x uni:phone ?contact.} UNION {?x uni:email ?contact.} } Chapter 3A Semantic Web Primer, 2nd Edition 3- 164
165
Results of UNION ?name?contact JohnSmithjohn.smith@example.org Harald9922 nbassili97913 nbassilinbassili@csd.auth.gr Chapter 3A Semantic Web Primer, 2nd Edition 3- 165 People with both contact details will be included twice in the result
166
Querying alternatives If we don’t want the same person twice we must choose the most preferred contact detail (e.g. phone) and write a different query SELECT ?x ?contact WHERE { ?x rdf:type :Faculty. {?x :phone ?contact.} UNION {?x :email ?contact. OPTIONAL { ?x :phone ?p. } FILTER(!bound(?p)) } Chapter 3A Semantic Web Primer, 2nd Edition 3- 166 In case the lecturer has also a phone, filter him out! (Variable ?p should not be bound)
167
Results of UNION + OPTIONAL + FILTER ?name?contact JohnSmithjohn.smith@example.org Harald9922 nbassili97913 Chapter 3A Semantic Web Primer, 2nd Edition 3- 167
168
SPARQL 1.1 Property Paths Property Paths give a more succinct way to write parts of basic graph patterns and also extend matching of triple pattern to arbitrary length paths. Property paths do change any existing SPARQL query. Chapter 3A Semantic Web Primer, 2nd Edition 3- 168
169
Simple Paths: Sequence Find the name of any people that Alice knows. { ?x foaf:mbox. ?x foaf:knows/foaf:name ?name. } This is equivalent to: { ?x foaf:mbox. ?x foaf:knows ?y. ?y foaf:name ?name. } Chapter 3A Semantic Web Primer, 2nd Edition 3- 169
170
Complex Paths Find the names of all the people that can be reached from Alice by foaf:knows { ?x foaf:mbox. ?x foaf:knows+/foaf:name ?name. } Chapter 3A Semantic Web Primer, 2nd Edition 3- 170 1 or more
171
Limited Inference Capabilities All classes and super-classes ?c of a resource: { uni:nick rdf:type/rdfs:subClassOf* ?c } All direct and indirect instances ?x of a class: { ?x rdf:type/rdfs:subClassOf* uni:Person } Chapter 3A Semantic Web Primer, 2nd Edition 3- 171 0 or more
172
DISTINCT - rationale Find all Greek cities with a University select ?c where { ?u rdf:type dbpedia-owl:University. ?u dbpedia-owl:country dbpedia:Greece. ?u dbpedia-owl:city ?c. } 3- 172 A Semantic Web Primer, 2nd EditionChapter 3
173
Result 3- 173 A Semantic Web Primer, 2nd Edition c http://dbpedia.org/resource/Corfu http://dbpedia.org/resource/Ioannina http://dbpedia.org/resource/Patras http://dbpedia.org/resource/Piraeus http://dbpedia.org/resource/Karditsa http://dbpedia.org/resource/Larissa http://dbpedia.org/resource/Trikala http://dbpedia.org/resource/Volos http://dbpedia.org/resource/Athens http://dbpedia.org/resource/Sparta... duplicates Chapter 3
174
DISTINCT Find all Greek cities with a University select DISTINCT ?c where { ?u rdf:type dbpedia-owl:University. ?u dbpedia-owl:country dbpedia:Greece. ?u dbpedia-owl:city ?c. } 3- 174 A Semantic Web Primer, 2nd EditionChapter 3
175
Results 3- 175 A Semantic Web Primer, 2nd Edition c http://dbpedia.org/resource/Corfu http://dbpedia.org/resource/Ioannina http://dbpedia.org/resource/Patras http://dbpedia.org/resource/Piraeus http://dbpedia.org/resource/Karditsa http://dbpedia.org/resource/Larissa http://dbpedia.org/resource/Trikala http://dbpedia.org/resource/Volos http://dbpedia.org/resource/Athens http://dbpedia.org/resource/Thessaloniki … No duplicates unordered Chapter 3
176
ORDER BY Find all Greek cities with a University select DISTINCT ?c where { ?u rdf:type dbpedia-owl:University. ?u dbpedia-owl:country dbpedia:Greece. ?u dbpedia-owl:city ?c. } ORDER BY ?c 3- 176 A Semantic Web Primer, 2nd EditionChapter 3
177
Results 3- 177 A Semantic Web Primer, 2nd Edition No duplicates Ordered c http://dbpedia.org/resource/Agrinio http://dbpedia.org/resource/Alexandroupoli http://dbpedia.org/resource/Argostoli http://dbpedia.org/resource/Athens http://dbpedia.org/resource/Attica http://dbpedia.org/resource/Chania http://dbpedia.org/resource/Corfu http://dbpedia.org/resource/Corinth http://dbpedia.org/resource/Crete http://dbpedia.org/resource/Didymoteicho http://dbpedia.org/resource/Drama,_Greece … How many? Chapter 3
178
COUNT Find how many Greek cities have a University select count(?c) as ?TotalCities where { ?u rdf:type dbpedia-owl:University. ?u dbpedia-owl:country dbpedia:Greece. ?u dbpedia-owl:city ?c. } 3- 178 A Semantic Web Primer, 2nd Edition TotalCities 68 Result Can’t be!!! Chapter 3
179
COUNT DISTINCT Find how many Greek cities have a University select count(DISTINCT ?c) as ?TotalCities where { ?u rdf:type dbpedia-owl:University. ?u dbpedia-owl:country dbpedia:Greece. ?u dbpedia-owl:city ?c. } 3- 179 A Semantic Web Primer, 2nd Edition TotalCities 3838 Result Chapter 3
180
Lecture Outline 1. Basic Ideas of RDF 2. XML-based Syntax of RDF 3. Basic Concepts of RDF Schema 4. Τhe Language of RDF Schema 5. The Namespaces of RDF and RDF Schema 6. Direct Semantics based on Inference Rules 7. Querying of RDF/RDFS Documents using SPARQL 8. Linked Open Data 3- 180 A Semantic Web Primer, 2nd EditionChapter 3
181
Linked Open Data Linked Data is about using the Web to – connect related data that wasn't previously linked, or – lower the barriers to linking data currently linked using other methods A recommended best practice for exposing, sharing, and connecting pieces of data, information, and knowledge on the Semantic Web using URIs and RDF. – Wikipedia definition Chapter 3A Semantic Web Primer, 2nd Edition 3- 181
182
Linked Data – Tim Berners Lee’s thoughts ( http://www.w3.org/DesignIssues/LinkedData.html ) http://www.w3.org/DesignIssues/LinkedData.html Semantic Web isn't just about putting data on the web It is about making links, so that a person or machine can explore the web of data. – With linked data, when you have some of it, you can find other, related, data. In the web of hypertext (or web of documents), links are relationships between documents written in HTML In the web of data, links are relationships between arbitrary things described by RDF. – The URIs identify any kind of object or concept. Chapter 3A Semantic Web Primer, 2nd Edition 3- 182
183
Linked Data Principles Use URIs as names for things – Real inanimate or animate things, abstract concepts, … Use HTTP URIs so that names can be looked up – E.g. using a browser When someone looks up a URI, provide useful information, using the standards (RDF, SPARQL) Include links to other URIs so that more things can be discovered – Links are actually RDF properties interpreted as hyperlinks Chapter 3A Semantic Web Primer, 2nd Edition 3- 183 Don't just link the documents, link the things
184
Advantages of LOD Linked Data is a way of publishing data on the Web that: – encourages reuse – reduces redundancy – maximises its (real and potential) inter- connectedness – enables network effects to add value to data Chapter 3A Semantic Web Primer, 2nd Edition 3- 184
185
Linked Data Technology Stack URIs – as a mechanism to identify things (IDs) HTTP – as a mechanism to access things RDF – as a mechanism to describe things and their relationships RDFS/OWL – as a mechanism to describe vocabularies of properties and relationships of things Chapter 3A Semantic Web Primer, 2nd Edition 3- 185
186
Linked Data Example Chapter 3A Semantic Web Primer, 2nd Edition 3- 186 Prefixes rc: rdf: foaf: dbpedia: dp: skos: Data Merging with RDF Mix schemas/vocabularies within one document Less painful data merging
187
Dbpedia:Berlin select ?p ?o where { dbpedia:Berlin ?p ?o. } 3- 187 A Semantic Web Primer, 2nd Edition See attached file Chapter 3
188
Dbpedia:Berlin Dbpedia:Berlin expands to full URI: http://dbpedia.org/resource/Berlin http://dbpedia.org/resource/Berlin – Unique ID that represents the resource in the Web of Data However, if you type the above URI at a browser, you will be re-directed at: http://dbpedia.org/page/Berlin http://dbpedia.org/page/Berlin – Manifestation (or visualization) of the resource in the Web of Documents 3- 188 A Semantic Web Primer, 2nd EditionChapter 3
189
Dbpedia:Berlin 3- 189 A Semantic Web Primer, 2nd EditionChapter 3
190
Dbpedia:Berlin If you type at the browser: http://dbpedia.org/data/Berlin http://dbpedia.org/data/Berlin The browser will retrieve an RDF/XML file that contains all information for BerlinRDF/XML – All triples with http://dbpedia.org/resource/Berlin as a subjecthttp://dbpedia.org/resource/Berlin 3- 190 A Semantic Web Primer, 2nd EditionChapter 3
191
Why Publish Linked Data? Ease of discovery Ease of consumption – standards-based data sharing Reduced redundancy Added value – build ecosystems around your data/content Chapter 3A Semantic Web Primer, 2nd Edition 3- 191
192
The Linking Open Data cloud diagram Now Chapter 3A Semantic Web Primer, 2nd Edition 3- 192
193
The Linking Open Data cloud diagram May 2007 Chapter 3A Semantic Web Primer, 2nd Edition 3- 193
194
DBpedia (http://dbpedia.org)http://dbpedia.org A project aiming to extract structured content from the information created as part of the Wikipedia. – This structured information is then made available on the Web DBpedia allows users to query relationships and properties associated with Wikipedia resources, including links to other related datasets. One of the more famous parts of the Linked Data project, according to TBL Chapter 3A Semantic Web Primer, 2nd Edition 3- 194
195
DBpedia dataset Wikipedia articles include structured information embedded in the articles (mostly free text) – E.g. "infobox" tables, categorisation information, images, geo-coordinates and links to external pages.pages – This structured information is extracted and put in a uniform dataset which can be queried. The DBpedia project uses RDF to represent the extracted information. – 2.46 billion RDF triples 470 million from the English edition 1.98 billion from other language editions (119) 45 million data links to external RDF data sets Chapter 3A Semantic Web Primer, 2nd Edition 3- 195
196
DBpedia challenges The same concepts can be expressed using different properties in templates – E.g. birthplace and placeofbirth – Queries about where people were born must search for both properties to get complete results. The DBpedia Mapping Language helps mapping properties to an ontology – Reduces the number of synonyms The development of the ontology and the mappings are open to public – Due to large diversity of infoboxes and properties Chapter 3A Semantic Web Primer, 2nd Edition 3- 196
197
GeoNames GeoNames is a geographical database available and accessible through various Web services Contains over 10,000,000 geographical names corresponding to over 7,500,000 unique features. – E.g. names of places, latitude, longitude, elevation, population, administrative subdivision, postal codes, … Web services: – Direct and reverse geocoding, finding places through postal codes, finding places next to a given place, and finding Wikipedia articles about neighbouring places. Chapter 3A Semantic Web Primer, 2nd Edition 3- 197
198
GeoNames and LOD Each GeoNames feature is represented as a Web resource identified by a stable URI.Web resourceURI – Provides access to the HTML wiki page or to RDF description, using GeoNames ontology RDFontology This ontology describes the GeoNames features properties using the OWL – The classes and codes are described in SKOS (RDFS).SKOS GeoNames data are linked to DBpedia data and other RDF Linked Data.DBpediaLinked Data – Through Wikipedia articles URL linked in the RDF descriptions Chapter 3A Semantic Web Primer, 2nd Edition 3- 198
199
Geonames – Example page Chapter 3A Semantic Web Primer, 2nd Edition 3- 199
200
Chapter 3A Semantic Web Primer, 2nd Edition 3- 200 Summary RDF provides a foundation for representing and processing metadata RDF has a graph-based data model RDF has an XML-based syntax to support syntactic interoperability. – XML and RDF complement each other because RDF supports semantic interoperability RDF has a decentralized philosophy and allows incremental building of knowledge, and its sharing and reuse
201
Chapter 3A Semantic Web Primer, 2nd Edition 3- 201 Summary (2) RDF is domain-independent RDF Schema provides a mechanism for describing specific domains RDF Schema is a primitive ontology language – It offers certain modelling primitives with fixed meaning Key concepts of RDF Schema are class, subclass relations, property, subproperty relations, and domain and range restrictions There exist query languages (SPARQL) for RDF/RDFS
202
Chapter 3A Semantic Web Primer, 2nd Edition 3- 202 Points for Discussion in Subsequent Chapters RDF Schema is quite primitive as a modelling language for the Web Many desirable modelling primitives are missing Therefore we need an ontology layer on top of RDF and RDF Schema
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.