RDF Dr. Alexandra I. Cristea http://www.dcs.warwick.ac.uk/~acristea/ RDF Definition • The Resource Description Framework (RDF) is a W3C standard for describing resources on the Web. • RDF is a framework for describing Web resources, – e.g., title, author, modification date, content, and copyright information of a Web page. 2 RDF original purpose & the metadata • originally created in 1999 • as a standard on top of XML, for encoding metadata – literally, data about data. – e.g., who authored a web page, what date a blog entry was published, etc., – secondary info 3 RDF general information on standard evolution • http://www.w3.org/standards/techs/rdf 4 What (else) is RDF? • RDF provides a model for data, and a syntax so that independent parties can exchange and use it • RDF is designed to be read and understood by computers • RDF is not designed for being displayed to people • RDF (can be) written in XML • RDF is a part of the W3C's Semantic Web Activity • RDF is a W3C Recommendation (so a standard!) • http://www.w3.org/RDF/ 5 RDF Usage Examples • Describing properties for shopping items, such as price and availability • Describing time schedules for web events • Describing information about web pages, such as content, author, created and modified date • Describing content and rating for web pictures • Describing content for search engines • Describing electronic libraries 6 RDF is Designed to be Read by Computers • RDF was designed to provide a common way to describe information so it can be read and understood by computer applications. • RDF descriptions are not designed to be displayed on the web. 7 RDF and "The Semantic Web" • The RDF language is a part of the W3C's Semantic Web Activity. W3C's "Semantic Web Vision" is a future where: – Web information has exact meaning – Web information can be understood and processed by computers – Computers can integrate information from the web 8 RDF Statements • RDF is built of Statement s • known as the – subject, – predicate and – object (of a Statement). 9 RDF Statements Subject Predicate Object 10 Informal graph of sample triples 11 Subjects and Objects • • • • Resources and values IRI Literals Blank nodes • Let’s understand them: 12 IRI, URI, URL • International Resource Identifier • Uniform Resource Identifier • Uniform Resource Locator • The IRI for an INA video about the Mona Lisa entitled 'La Joconde à Washington' in Europeana is: http://data.europeana.eu/item/04802/243FA8618938 F4117025F17A8B813C5F9AA4D619 13 IRI • are global identifiers, so other people can re-use this IRI to identify the same thing. • IRI used as an RDF property to state acquaintance relationship : – http://xmlns.com/foaf/0.1/knows • DBpedia uses IRIs for articles: – http://dbpedia.org/resource/Name 14 Literals • Basic values that are not IRI • Examples – "La Joconde", – "the 4th of July, 1990" – "3.14159“ • associated with a datatype • Strings optionally assoc. with language tag. – "Léonard de Vinci" - "fr" language tag – "李奥纳多·达·文西" - "zh" language tag. 15 Blank nodes • When mentioning resources without global identifier • ~ variables in algebra 16 Multiple graphs 17 Example using URIs • Let's look at some example statements to get a better understanding: – Statement: "The author of http://www.w3schools.com/RDF is Jan Egil Refsnes". – Statement: "The homepage of http://www.w3schools.com/RDF is http://www.w3schools.com". 18 Example – cont. • Statement: "The author of http://www.w3schools.com/RDF is Jan Egil Refsnes". – The subject of the statement above is: http://www.w3schools.com/RDF – The predicate is: author – The object is: Jan Egil Refsnes • Statement: "The homepage of http://www.w3schools.com/RDF is http://www.w3schools.com". – The subject of the statement above is: http://www.w3schools.com/RDF – The predicate is: homepage – The object is: http://www.w3schools.com 19 RDF Statements Subject Predicate http://www.w3schools.com/RDF Object author Jan Egil Refsnes 20 RDF Resource, Property, and Property Value • RDF identifies things using Web identifiers (URIs), and • describes resources with properties and property values. • A Resource is anything that can have a URI, – such as "http://www.w3schools.com/RDF" • A Property is a Resource that has a name, – such as "author" or "homepage" • A Property value is the value of a Property, – such as "Jan Egil Refsnes" or "http://www.w3schools.com" (note that a property value can be another resource) 21 RDF Statements Subject Predicate http://www.w3schools.com/RDF Resource Object author Property Jan Egil Refsnes Property Value Can be another resource !! 22 Example 23 RDF vocabulary examples • "Friend of a Friend" (FOAF) • Dublin Core – web resources • schema.org – mark up by search providers • SKOS – classification schemes for libraries 24 So, RDF .. • Different world view • Triples (instead of pairs) • More natural? • This is the concept … how to implement it? 25 Writing RDF graphs • Turtle family of RDF languages (NTriples, Turtle, TriG and N-Quads); • JSON-LD (JSON-based RDF syntax); • RDFa (for HTML and XML embedding); • RDF/XML (XML syntax for RDF). 26 RDF can be Written in XML • RDF documents can be written in XML language : RDF/XML. • information exchange between – different types of computers – types of operating systems and – application languages. 27 RDF/XML http://www.w3.org/TR/2014/REC-rdfsyntax-grammar-20140225/ 28 RDF 1.1 XML Syntax • Original version 1999; most recent recommendation 25th of February 2014 • Encodes RDF graphs • Nodes and predicates need represented in XML terms • element names, • attribute names, • element contents, • attribute values 29 RDF/XML is XML 30 XML Rules 1. 2. 3. 4. Every start-tag must have a matching end-tag. Tags cannot overlap. Proper nesting is required. XML documents can only have one root element. Element names must obey the following XML naming conventions: a) Names must start with letters or the "_" character. Names cannot start with numbers or punctuation characters. b) After the first character, numbers and punctuation characters are allowed. 31 XML Rules (cont.) c) Names cannot contain spaces. d) Names should not contain the ":" character as it is a "reserved" character. e) Names cannot start with the letters "xml" in any combination of case. f) The element name must come directly after the "<" without any spaces between them. 5. XML is case sensitive. 6. XML preserves white space within text. 7. Elements may contain attributes. If an attribute is present, it must have a value, even if it is an empty string "". 32 Example RDF/XML <?xml version="1.0"?> Resource Property <RDF> <Description about="http://www.w3schools.com/RDF"> <author>Jan Egil Refsnes</author> <homepage>http://www.w3schools.com</homepage> </Description> Property value </RDF> 33 RDF/XML • Is not the only solution, • but the recommended one • No one-to-one mapping – – – – RDF doesn’t have ordering XML does! Serialization of a graph! So is this the price to pay? • Others: Notation 3 http://www.w3.org/DesignIssues/Notation3.html , precursor to Turtle http://www.dajobe.org/2004/01/turtle/ 34 XML has namespaces: Why namespaces? 35 Naming ambiguity 36 The Idea to Solve it • Assign a URI (~ URL) to every sublanguage: – E.g., for XHTML 1.0: http://www.w3.org/1999/xhtml • Qnames: Qualify element names with URIs: – {http://www.w3.org/1999/xhtml}head Web Naming and Addressing Overview (URIs, URLs, ...) 37 The actual solution • Namespace declarations bind URIs to prefixes: • Default namespace (no prefix) declared with: xmlns=“…” • Lexical Scope • Attribute names can also be prefixed 38 Applying namespaces 39 RDF/XML namespace <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdfsyntax-ns#" xmlns:cd="http://www.recshop.fake/cd#"> 40 Other namespaces <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdfsyntax-ns#" xmlns:cd="http://www.recshop.fake/cd#"> 41 Example: Mona Lisa <?xml version="1.0" encoding="utf-8"?> <rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:schema="http://schema.o <rdf:Description rdf:about="http://example.org/bob#me"> <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/> <schema:birthDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">1990-0704</schema:birthDate> <foaf:knows rdf:resource="http://example.org/alice#me"/> <foaf:topic_interest rdf:resource="http://www.wikidata.org/entity/Q12418"/> </rdf:Description> <rdf:Description rdf:about="http://www.wikidata.org/entity/Q12418"> <dcterms:title>Mona Lisa</dcterms:title> <dcterms:creator rdf:resource="http://dbpedia.org/resource/Leonardo_da_Vinci"/> </rdf:Description> <rdf:Description rdf:about="http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA 19"> <dcterms:subject rdf:resource="http://www.wikidata.org/entity/Q12418"/> </rdf:Description> 42 </rdf:RDF> RDF Online Validator • W3C's RDF Validation Service is useful when learning RDF. Here you can experiment with RDF files. • The online RDF Validator parses your RDF document, checks your syntax, and generates tabular and graphical views of your RDF document. 43 The <rdf:RDF> Element • <rdf:RDF> is the root element of an RDF document. It defines the XML document to be an RDF document. • It also contains a reference to the RDF namespace. <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdfsyntax-ns#"> . . Description goes here </rdf:RDF> 44 The <rdf:Description> Element • The <rdf:Description> element identifies a resource with the about attribute. • The <rdf:Description> element contains elements that describe the resource. <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"> <cd:artist>Bob Dylan</cd:artist> <cd:country>USA</cd:country> <cd:company>Columbia</cd:company> <cd:price>10.90</cd:price> <cd:year>1985</cd:year> </rdf:Description> 45 A Resource and its Description <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22rdf-syntax-ns#" xmlns:cd="http://www.recshop.fake/cd#"> <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"> … </rdf:Description> . . . </rdf:RDF> 46 Another example Title Artist Country Company Price Year Empire Burlesque Bob Dylan USA Columbia 10.90 1985 Hide your heart Bonnie Tyler UK CBS Records 9.90 1988 ... 47 RDF Declaration <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cd="http://www.recshop.fake/cd#"> <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"> <cd:artist>Bob Dylan</cd:artist> <cd:country>USA</cd:country> <cd:company>Columbia</cd:company> <cd:price>10.90</cd:price> <cd:year>1985</cd:year> </rdf:Description> <rdf:Description rdf:about="http://www.recshop.fake/cd/Hide your heart"> <cd:artist>Bonnie Tyler</cd:artist> <cd:country>UK</cd:country> <cd:company>CBS Records</cd:company> <cd:price>9.90</cd:price> <cd:year>1988</cd:year> </rdf:Description> . . . 48 </rdf:RDF> Properties as Attributes • The property elements can also be defined as attributes (instead of elements): <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque" cd:artist="Bob Dylan" cd:country="USA" cd:company="Columbia" cd:price="10.90" cd:year="1985" /> Can you identify the triples here? (resource, property, value) 49 Properties as Resources • The property elements can also be defined as resources: <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"> <cd:artist rdf:resource="http://www.recshop.fake/cd/dylan" /> ... </rdf:Description> 50 Compare: properties as • elements <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"> <cd:artist>Bob Dylan</cd:artist> </rdf:Description> • attributes <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque" cd:artist="Bob Dylan" /> • resources <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"> <cd:artist rdf:resource="http://www.recshop.fake/cd/dylan" /> </rdf:Description> 51 RDF Containers • RDF containers are used to describe groups of things. • e.g, to list the authors of a book or to list the members in a band. • The following RDF elements are used to describe such groups: <Bag>, <Seq>, and <Alt>. 52 RDF Bag • The <rdf:Bag> element is used to describe a list of values that is intended to be unordered. • The <rdf:Bag> element may contain duplicate values. <rdf:Description rdf:about="http://www.recshop.fake/cd/Beatles"> <cd:artist> <rdf:Bag> <rdf:li>John</rdf:li> <rdf:li>Paul</rdf:li> <rdf:li>George</rdf:li> <rdf:li>Ringo</rdf:li> </rdf:Bag> </cd:artist> </rdf:Description> 53 Student example <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:s="http://example.org/students/vocab#"> <rdf:Description rdf:about="http://example.org/courses/6.001"> <s:students> <rdf:Bag> <rdf:li rdf:resource="http://example.org/students/Amy"/> <rdf:li rdf:resource="http://example.org/students/Mohamed"/> <rdf:li rdf:resource="http://example.org/students/Johann"/> <rdf:li rdf:resource="http://example.org/students/Maria"/> <rdf:li rdf:resource="http://example.org/students/Phuong"/> </rdf:Bag> </s:students> </rdf:Description> </rdf:RDF> 54 RDF Bag 55 The <rdf:Seq> Element • The <rdf:Seq> element is used to describe a list of values that is intended to be ordered (For example, in alphabetical order). • The <rdf:Seq> element may contain duplicate values. <rdf:Description rdf:about="http://www.recshop.fake/cd/Beatles"> <cd:artist> <rdf:Seq> <rdf:li>George</rdf:li> <rdf:li>John</rdf:li> <rdf:li>Paul</rdf:li> <rdf:li>Ringo</rdf:li> </rdf:Seq> </cd:artist> </rdf:Description> 56 The <rdf:Alt> Element • The <rdf:Alt> element is used to describe a list of alternative values (the user can select only one of the values). <rdf:Description rdf:about="http://www.recshop.fake/cd/Beatles"> <cd:format> <rdf:Alt> <rdf:li>CD</rdf:li> <rdf:li>Record</rdf:li> <rdf:li>Tape</rdf:li> </rdf:Alt> </cd:format> </rdf:Description> 57 RDF Alt 58 The rdf:parseType="Collection" Attribute • collection can be closed (container cannot ) • RDF collections are used to describe a group that contains ONLY the specified members. • A collection is described by the attribute rdf:parseType="Collection". 59 Collection attribute example <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntaxns#" xmlns:cd="http://recshop.fake/cd#"> <rdf:Description rdf:about="http://recshop.fake/cd/Beatles"> <cd:artist rdf:parseType="Collection"> <rdf:Description rdf:about="http://recshop.fake/cd/Beatles/George"/> <rdf:Description rdf:about="http://recshop.fake/cd/Beatles/John"/> <rdf:Description rdf:about="http://recshop.fake/cd/Beatles/Paul"/> <rdf:Description rdf:about="http://recshop.fake/cd/Beatles/Ringo"/> </cd:artist> </rdf:Description> </rdf:RDF> 60 Collection: a graphical representation 61 Collection is a short notation <rdf:Description rdf:about="http://e.org/family/349"> <s:familyMembers rdf:nodeID="sch1"/> </rdf:Description> <rdf:Description rdf:nodeID="sch1"> <rdf:first rdf:resource="http://e.org/person/Paolo"/> <rdf:rest rdf:nodeID="sch2"/> </rdf:Description> <rdf:Description rdf:about="http://e.org/family/349"> <rdf:Description rdf:nodeID="sch2"> <s:familyMembers rdf:parseType="Collection"> <rdf:first rdf:resource="http://e.org/person/Emanuele"/> <rdf:Description rdf:about="http://e.org/person/Paolo"/> <rdf:rest rdf:nodeID="sch3"/> <rdf:Description rdf:about="http://e.org/person/Emanuele"/> </rdf:Description> <rdf:Description rdf:about="http://e.org/person/Maria"/> <rdf:Description rdf:about="http://e.org/person/Franco"/> <rdf:Description rdf:nodeID="sch3"> </s:familyMembers> <rdf:first rdf:resource="http://e.org/person/Maria"/> </rdf:Description> <rdf:rest rdf:nodeID="sch4"/> </rdf:Description> <rdf:Description rdf:nodeID="sch4"> <rdf:first rdf:resource="http://e.org/person/Franco"/> <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdfsyntax-ns#nil"/> </rdf:Desciption> 62 RDF Reification • Statements about statements – E.g., record info about when statements were made, who made them, etc. ("provenance" information). 63 Example • example.com could record the fact that: John Smith made the original statement about the tent's weight • By: – original statement URIref (exproducts:triple12345), describing it w. reification, then – adding an additional statement that exproducts:triple12345 was written by John Smith (w. URIref for John Smith) 64 Example figure: reification original statement John 65 Reification Rules • For the given IRI event r and the statement with terms s, p and o corresponding to the N-Triples: • spo. • add the following statements to the graph: r.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> s . r.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> p . r.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> o . r.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement> . 66 RDF Schema and Application Classes • RDF describes resources with classes, properties, and values • RDF needs to define applicationspecific classes and properties – with extensions to RDF • One such extension is RDF Schema 67 RDF Schema http://www.w3.org/TR/2014/REC-rdfschema-20140225/ 68 RDF Schema • W3C recommendation since 2004; newest 25th February 2014 • RDF Schema 1.1 • provides a data-modelling vocabulary for RDF data. • is an extension of the basic RDF vocabulary. 69 RDF Schema (RDFS) • does not provide actual applicationspecific classes and properties. • … but framework to describe them • Classes ~ OO programming languages. • Resources: – instances of classes, or – subclasses of classes. 70 RDFS Example The following example demonstrates some of the RDFS facilities: <?xml version="1.0"?> <rdf:RDF xmlns:rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xml:base= "http://www.animals.fake/animals#"> <rdf:Description rdf:ID="animal"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> </rdf:Description> <rdf:Description rdf:ID="horse"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#animal"/> </rdf:Description> </rdf:RDF> In the example above, the resource "horse" is a subclass of the class "animal". 71 Example of class structure 72 <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xml:base="http://example.org/schemas/vehicles"> <rdf:Description rdf:ID="MotorVehicle"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> </rdf:Description> <rdf:Description rdf:ID="PassengerVehicle"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdf:Description> <rdf:Description rdf:ID="Van"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdf:Description> <rdf:Description rdf:ID="MiniVan"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#Van"/> <rdfs:subClassOf rdf:resource="#PassengerVehicle"/> Multiple inheritance! </rdf:Description> </rdf:RDF> 73 Example Abbreviated • Since an RDFS class is an RDF resource we can abbreviate it using rdfs:Class instead of rdf:Description, and drop the rdf:type information 74 Original Class declaration <?xml version="1.0"?> <rdf:RDF xmlns:rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xml:base= "http://www.animals.fake/animals#"> <rdf:Description rdf:ID="animal"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> </rdf:Description> <rdf:Description rdf:ID="horse"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#animal"/> </rdf:Description> </rdf:RDF> 75 Example Class Abbreviated <?xml version="1.0"?> <rdf:RDF xmlns:rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xml:base= "http://www.animals.fake/animals#"> <rdfs:Class rdf:ID="animal" /> <rdfs:Class rdf:ID="horse"> <rdfs:subClassOf rdf:resource="#animal"/> </rdfs:Class> </rdf:RDF> 76 Original and abbreviated class So we replace: <rdf:Description rdf:ID="animal"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> </rdf:Description> with <rdfs:Class rdf:ID="animal" /> 77 Classes • rdfs:Resource rdfs:Class rdfs:Literal rdfs:Datatype rdf:XMLLiteral rdf:Property 78 Properties • rdfs:range rdfs:domain rdf:type rdfs:subClassOf rdfs:subPropertyOf rdfs:label rdfs:comment 79 RDF Conclusion • We have learned: – RDF – Usage scenarios, basics – RDFS and examples – Comparison w. XML and graph languages 80 Homework • Lists 10 URI that identify things in your environment. • Give several examples of how to extend the definition of literals in RDF. Why would this be useful? • The RDFS specification allows more than one domain to be defined for a property and uses the intersection of these domains. Discuss the pros and cons of taking the union versus taking the intersection of domains. • In an older version of the RDFS specfication, rdfs:subClassOf was not allowed to have cycles. Try to imagine situations where a cyclic clas relationship would be beneficial. (Hint: Think of equivalences between classes) • Discuss the differences between the following statements, and draw graphs to illustrate the difference: • X supports the proposal; Y supports the proposal; Z supports the proposal. • The group of X, Y and Z supports the proposal. 81