RDF


Winter 2019
Instructor: Raghava Mutharaju
IIIT-Delhi
IIIT Delhi

Introduction

  • Resource Description Framework (RDF) is a data model that is used to describe resources
    • Physical things
    • Abstract concepts
    • Numbers and strings
  • We use the term resource and entity synonymously here
  • It is a universal, machine readable data exchange format
  • Resources are described using triples (subject, predicate, object)
  • A triple captures the relationship (predicate) between a subject and an object
  • <Delhi> <capitalOf> <India>
  • RDF triple is called a RDF Statement
  • Triple can be represented as a directed labelled graph
RDF Graph
Image source: https://www.w3.org/TR/rdf11-concepts/rdf-graph.svg
Sample RDF Graph
Image source: http://www.obitko.com/tutorials/ontologies-semantic-web/rdf-graph-and-syntax.html

Identifiers

  • URL (Uniform Resource Locator)
    • It is a mechanism to specify and locate a web resource on a computer network.
    • Eg: http://, ftp://
  • URN (Uniform Resource Name)
    • They are persistent location independent identifiers that use the urn scheme.
    • Eg: ISBN of a book is a URN used to identify a book uniquely
  • URI (Uniform Resource Identifier)
    • It is an identifier that can uniquely and unambiguously identify resources
    • ASCII encoding is used in the identifiers
    • URL and URN are type of URIs. URIs and URNs need not be resolvable to a location, which is the case with URL
    • Eg: http://www.w3.org/2002/07/owl#
  • IRI (International Resource Identifier)
    • IRI is similar to URI except that the character set for encoding the identifier is Universal Character Set (UTF-8)
    • Eg: é, ö could be used in IRI
  • Subject, Predicate, and Object in a triple are identified by IRIs
    • http://www.example.org/~joe/contact.rdf#joesmith
    • http://xmlns.com/foaf/0.1/homepage
    • http://www.example/org/~joe
  • Literals and blank nodes do not have IRIs

Namespace


  • It is a logical grouping of unique identifiers
    • Packages in Java (java.util.concurrent, org.w3c.dom)
    • Namespace in C++ (std)
    • XML namespace: xmlns="http://www.w3.org/1999/xhtml"
    • RDF namespace: rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    • RDFS namespace: rdfs="http://www.w3.org/2000/01/rdf-schema#"
    • XSD namespace: xsd="http://www.w3.org/2001/XMLSchema#"

Literals


  • Objects in a triple can be literals
  • Literals are constants. They can be values of strings, numbers, and dates
  • Literal consists of the following parts
    • a lexical form, which is a unicode string
    • a datatype IRI
    • a language tag (only for string datatype)
  • "That Seventies Show"^^xsd:string
  • "That Seventies Show"@en
  • "La Joconde"@fr
  • "1"^^xs:integer

Blank Nodes

  • A blank node does not have a name associated with it
  • It is similar to anonymous classes in Java, C++
  • It indicates the existence of something but we will not be using or saying anything about the name of that thing
RDF Graph with Blank Nodes
Image source: https://goo.gl/u7P6wU
  • It does not have an IRI
    • Blank node identifiers have only local scope
    • No global identity unlike other nodes with IRIs
  • It is not a literal
  • It can be used as a subject or object

Multiple Graphs

  • RDF statements can be grouped into multiple graphs
  • Each graph can have a name associated with it (named graphs), which is an IRI
  • An RDF dataset is a collection of graphs
    • Exactly one default (unnamed) graph that may be empty
    • Zero or more named graphs
    • Graph names are unique within a RDF dataset
    • Blank nodes can be shared by graphs in a RDF dataset
  1. Graph name (IRI): http://example.org/bob
    • <Bob> <is a> <person>.
    • <Bob> <is a friend of> <Alice>.
    • <Bob> <is born on> <the 4th of July 1990>.
    • <Bob> <is interested in> <the Mona Lisa>.
  2. Graph name (IRI): https://www.wikidata.org/wiki/Special:EntityData/Q12418
    • <Leonardo da Vinci> <is the creator of> <the Mona Lisa>.
    • <The video 'La Joconde à Washington'> <is about> <the Mona Lisa>

RDF Serialization Formats

  • There are different serialization formats for writing RDF graphs
  • They are all logically equivalent and lead to same triples
    • Turtle family of RDF serialization formats
      • N-Triples
      • Turtle
      • TriG
      • N-Quads
    • JSON-LD
    • RDFa
    • RDF/XML
RDF Serialization Formats
Image source: https://goo.gl/AsV5vR

N-Triples


  • It is a line based, plain text format to encode a RDF graph
  • It is a sequence of subject, predicate, and object separated by whitespace and terminated by dot
  • IRIs are written as absolute IRIs (not shortcuts) and are enclosed in angular brackets
  • Literals are written in double quotes followed by datatype or language tag
  • Datatype IRI is preceded by "^^"
  • Language tag is preceded by "@"
  • Blank nodes are expressed as _: followed by blank node label
    • _:alice <http://xmlns.com/foaf/0.1/knows> _:bob .
Sample RDF Graph
Image source: https://www.w3.org/TR/rdf11-primer/example-graph-iris.jpg

N-Triples

  1. <http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
  2. <http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> .
  3. <http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> .
  4. <http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> .
  5. <http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" .
  6. <http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> .
  7. <http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> .

Turtle


  • Turtle is the Terse RDF Triple Language
  • It is an extension of N-Triples with syntactic shortcuts
    • Namespace prefix
    • Predicate lists
    • Object lists

Turtle


BASE   <http://example.org/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX schema: <http://schema.org/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX wd: <http://www.wikidata.org/entity/>
						

Turtle


  • Predicate lists are triples with the same subject but different predicates and objects
  • Semi colon is used as a separator

<bob#me>
	a foaf:Person ;
	foaf:knows <alice#me> ;
	schema:birthDate "1990-07-04"^^xsd:date ;
	foaf:topic_interest wd:Q12418 .
						

Turtle


  • Object lists are triples with the same subject and predicate, but different object
  • Comma is used as a separator

<ex:spiderman> foaf:name "Spiderman", "Человек-паук"@ru  .
						

Turtle


  • Two types of IRIs - relative and absolute
  • Absolute IRI
    • <http://one.example/subject1>
  • Relative IRI

BASE <http://one.example/>
<subject1> <predicate1> <object1> .
						
PREFIX p: <http://one.example/>
p:subject1 p:predicate1 p:object1> .
						

TriG


  • Extension of Turtle that supports multiple graphs

GRAPH <http://example.org/bob>
{
    <bob#me>
	a foaf:Person ;
        foaf:knows <alice#me> ;
        schema:birthDate "1990-07-04"^^xsd:date ;
        foaf:topic_interest wd:Q12418 .
}
						

TriG


  • Default graphs

<http://example.org/bob>
        dcterms:publisher <http://example.org/crc> ;
        dcterms:rights <http://creativecommons.org/licenses/by/3.0/> .
						

TriG

TriG Named Graphs
Image source: https://www.w3.org/TR/rdf11-primer/example-multiple-graphs-iris.jpg

N-Quads


  • Extends N-Triples with a fourth element to the line which is the graph IRI of the triple

<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/bob> .
<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> <http://example.org/bob> .
						
<http://example.org/bob> <http://purl.org/dc/terms/publisher> <http://example.org> .
<http://example.org/bob> <http://purl.org/dc/terms/rights> <http://creativecommons.org/licenses/by/3.0/> .
						

JSON-LD


  • Provides JSON sytanx for RDF graphs
  • JSON-LD can be used to transform JSON to RDF
  • JSON objects are given universal identifiers in JSON-LD
    • This helps in referring to objects in other JSON documents anywhere on the Web

JSON-LD


{
"@context": "example-context.json",
"@id": "http://example.org/bob#me",
"@type": "Person",
"birthdate": "1990-07-04",
"knows": "http://example.org/alice#me",
"interest": {
	"@id": "http://www.wikidata.org/entity/Q12418",
	"title": "Mona Lisa",
	"subject_of": "http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619",
	"creator": "http://dbpedia.org/resource/Leonardo_da_Vinci"
    }
}
						

RDFa


  • It is used to embed RDF within HTML and XML documents
  • Search engines can make use of the structured data (schema.org, Rich Snippets) to enrich search results

RDFa

<body prefix="foaf: http://xmlns.com/foaf/0.1/
	schema: http://schema.org/
	dcterms: http://purl.org/dc/terms/">
<div resource="http://example.org/bob#me" typeof="foaf:Person">
	<p>
		Bob knows <a property="foaf:knows" href="http://example.org/alice#me">Alice</a>
        and was born on the <time property="schema:birthDate" datatype="xsd:date">1990-07-04</time>.
    </p>
	<p>
		Bob is interested in <span property="foaf:topic_interest"
        resource="http://www.wikidata.org/entity/Q12418">the Mona Lisa</span>.
      </p>
  <</div>
</body>
						

RDF/XML


  • Provides XML syntax for RDF graphs
  • There is good tool support for XML
  • This used to be the only syntax that was available to serialize RDF

RDF/XML

<?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.org/">
	<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-07-04</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:RDF>
						

RDFS

  • RDFS is a semantic extension of RDF
  • It provides the vocabulary for the RDF data
  • It provides a mechanism to describe groups of related resources (classes) and the relationships between these resources (properties)
  • Classes
    • Related resources can be categorized as a class
    • A class is defined using rdfs:Class
    • Members of the class are known as instances
    • Classes can be subclass of another class. This is defined using rdfs:subClassOf
  • A Resource is the class of everything, i.e., class of all classes
  • Properties
    • It is a relation between subject resources and object resources
    • A property/predicate is defined using rdf:Property
    • Subproperties can be stated using rdfs:subPropertyOf
      • hasSon rdfs:subPropertyOf hasChild
    • A property can have domain and range, which can be defined using rdfs:domain and rdfs:range respectively
      • If multiple domains/ranges are defined then the domain/range of the property is the intersection of all the defined domains/ranges
  • Other frequently used RDFS schema elements
    • rdf:type
    • rdfs:Literal
    • rdfs:label
    • rdfs:comment

Examples


  1. Person rdf:type rdfs:Class .
  2. Father rdfs:subClassOf Person .
  3. hasAge rdf:type rdf:Property .
  4. hasSon rdfs:subPropertyOf hasChild .
  5. hasAge rdfs:domain Person
  6. hasAge rdfs:range rdfs:Literal .
  7. wd:Q12418 rdfs:Label "Mona Lisa" .
  8. wd:Q12418 rdfs:comment "Wikidata ID for Mona Lisa" .

Reification


  • Used to capture provenance information
  • Describe other RDF statements using statements

exproducts:triple12345   rdf:type        rdf:Statement .
exproducts:triple12345   rdf:subject     exproducts:item10245 . 
exproducts:triple12345   rdf:predicate   exterms:weight . 
exproducts:triple12345   rdf:object      "2.4"^^xsd:decimal .
exproducts:triple12345   dc:creator      exstaff:85740 . 
						

Entailment Rules

Representing Knowleding using RDF

  • Pick a domain of your choice and build an RDF graph

References