1 of 77

RDF and its serializations, RDFS

Jakub Klímek

2 of 77

The principles of Linked Data

  1. Use IRIs as names for things
  2. Use HTTP(S) IRIs so that people can look up those names.
  3. When someone looks up an IRI, provide useful information, using the standards (RDF, SPARQL)
  4. Include links to other IRIs so that they can discover more things.

2

3 of 77

HTTP(S) IRIs for things and linking

3

http://praha.eu/contract/7302

http://praha.eu/city

http://mfcr.cz/

prague/budget

http://mfcr.cz/

prague

http://risy.cz/

location/prague

http://risy.cz/contract/22189-01

http://risy.cz/

project/22189

http://registry.

czso.cz/prague

http://czso.cz/

prague

http://czso.cz/prague/demogstat

c: hasBeneficiary

a:fundedBy

b:hasBudget

http://praha.eu/council

d:hasDemography

4 of 77

URI, URL, IRI, URN

4

5 of 77

URI, URL, IRI, URN

URI - Uniform Resource Identifier - RFC 3986�URN - Uniform Resource Name - RFC 8141, IANA URN namespace registry�URL - Uniform Resource Locator - RFC 3986�IRI - Internationalized Resource Identifier - RFC 3987�� foo://example.com:8042/over/there?name=ferret#nose� \_/ \______________/\_________/ \_________/ \__/� | | | | |� scheme authority path query fragment� | _____________________|__� / \ / \� urn:example:animal:ferret:nose

5

6 of 77

RFC 3986 - Uniform Resource Identifier - examples

  • ftp://ftp.is.co.za/rfc/rfc1808.txt
  • http://www.ietf.org/rfc/rfc2396.txt
  • ldap://[2001:db8::7]/c=GB?objectClass?one
  • mailto:John.Doe@example.com
  • news:comp.infosystems.www.servers.unix
  • tel:+1-816-555-1212
  • telnet://192.0.2.16:80/
  • urn:oasis:names:specification:docbook:dtd:xml:4.1.2

6

7 of 77

RFC 3987 - IRI - Internationalized Resource Identifier

Examples

Percent-encoding

  • For some usages only URIs are acceptable
    • e.g. HTTP
  • IRIs are encoded in URIs
  • each byte represented as �'%' and two hexadecimal digits
  • e.g. 💩 => %F0%9F%92%A9
    • emojis are 4 bytes in UTF-8

The same examples of IRIs percent-encoded into URIs

7

8 of 77

RFC 3492 - Punycode

IRIs not to be confused with IDN - internationalized domain name:

  • e.g. https://www.háčkyčárky.cz = https://www.xn--hkyrky-ptac70bc.cz/
  • even less readable than percent-encoding
  • punycoded name is used with DNS

8

9 of 77

RDF - Resource Description Framework - idea

RDF - graph based data model - a set of triples

Triple describes a relation as:

subject predicate object

2004 & 2014 W3C Recommendations

Triples are written in one of RDF notations / syntaxes / serializations:

RDF/XML, RDFa, N-Triples, Turtle, JSON-LD, N-Quads, TriG

9

Jakub Klímek studied at Charles University .

predicate

object

subject

Jakub Klímek Charles University

studied at

10 of 77

RDF model: a triple, a statement

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8574> .

10

http://example.com/index.html

http://example.com/staff/8574

http://purl.org/dc/terms/creator

subject (S)

predicate (P)�(property)

object (O)

Resource / Thing

Resource / Thing

11 of 77

RDF model: a triple with literal value

<http://example.com/index.html> <http://purl.org/dc/terms/subject> "education" .

11

http://example.com/index.html

education

http://purl.org/dc/terms/subject

subject (S)

predicate (P)

object (O)

Resource

Literal

12 of 77

RDF serializations: IRIs and IRI prefixes

<http://purl.org/dc/terms/creator>

=

@prefix dcterms: <http://purl.org/dc/terms/> .

dcterms:creator

12

13 of 77

RDF model: multiple properties

my:index.html dcterms:creator exstaff:85740 .�my:index.html dcterms:subject "education" .�my:index.html dcterms:language "en" .

13

my:index.html

my:staff/85740

dcterms:creator

education

en

dcterms:language

dcterms:subject

a set�i.e. no ordering among triples

14 of 77

RDF model: typed literals

my:index.html dcterms:created "2020-04-23"^^xsd:date .

14

my:index.html

"2020-04-23"^^<http://www.w3.org/2001/XMLSchema#date>

dcterms:created

15 of 77

RDF model: text literals with a language tag

my:index.html dcterms:title "Homepage of Jakub Klímek"@en .

15

my:index.html

"Homepage of Jakub Klímek"@en

dcterms:title

16 of 77

RDF model: classes

16

my:Person

my:staff/85740

rdf:type

Resource

Resource

Class

 

17 of 77

RDF model: blank nodes

my:staff/85740 my:hasAddress _:a1 .

_:a1 my:street "Malostranske nam. 25" .�_:a1 my:city "Prague" .�_:a1 my:zipCode "11800" .

17

my:street

Prague

11800

my:zipCode

my:city

my:staff/85740

my:hasAddress

Malostranské nám. 25

18 of 77

RDF model: rdf:List for closed collection

18

rdf:List

my:item1

my:item2

rdf:type

rdf:first

rdf:rest

my:list

rdf:nil

rdf:first

rdf:rest

rdf:type

rdf:type

19 of 77

RDF model: containers for open collections

rdf:Bag, rdf:Seq, rdf:Alt

19

my:bag

my:item1

my:item2

my:item3

rdf:Bag

rdf:type

rdf:_1

rdf:_2

rdf:_3

20 of 77

RDF - Resource Description Framework

  • 1.0: W3C Recommendation
    • 10 February 2004
  • 1.1: W3C Recommendation
    • 25 February 2014
  • 1.2: W3C Working Draft
    • 2025
  • Graph data model
    • Directed labeled multigraph
      • Vertices for subjects and objects
      • Labeled edges for particular triples

20

21 of 77

RDF serializations

21

22 of 77

RDF 1.1 N-Triples

  • W3C Recommendation
    • 25 February 2014

22

<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here

<http://example.org/show/218> <http://example.org/show/localName> "That Seventies Show"@en . # literal with a language tag

�<http://en.wikipedia.org/wiki/Helium> <http://example.org/elements/atomicNumber> "2"^^<http://www.w3.org/2001/XMLSchema#integer> . # xsd:integer

23 of 77

RDF 1.1 N-Triples

<http://example.com/index.html> <http://purl.org/dc/terms/created> "2020-04-23"^^<http://…#date> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8574> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8575> .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "Moje stránka"@cs .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "My page"@en .

23

24 of 77

RDF 1.1 Turtle - Prefixes

<http://example.com/index.html> <http://purl.org/dc/terms/created> "2020-04-23"^^<http://…#date> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8574> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8575> .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "Moje stránka"@cs .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "My page"@en .

24

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .�@prefix dcterms: <http://purl.org/dc/terms/> .�@prefix my: <http://example.com/> .�@prefix staff: <http://example.com/staff/> .��my:index.html dcterms:created "2020-04-23"^^xsd:date .

my:index.html dcterms:creator staff:8574 .

my:index.html dcterms:creator staff:8575 .

my:index.html dcterms:title "Moje stránka"@cs .

my:index.html dcterms:title "My page"@en .

25 of 77

RDF 1.1 Turtle - Prefixes and ";"

<http://example.com/index.html> <http://purl.org/dc/terms/created> "2020-04-23"^^<http://…#date> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8574> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8575> .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "Moje stránka"@cs .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "My page"@en .

25

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .�@prefix dcterms: <http://purl.org/dc/terms/> .�@prefix my: <http://example.com/> .�@prefix staff: <http://example.com/staff/> .��my:index.html dcterms:created "2020-04-23"^^xsd:date ;

dcterms:creator staff:8574 ;

dcterms:creator staff:8575 ;

dcterms:title "Moje stránka"@cs ;

dcterms:title "My page"@en .

26 of 77

RDF 1.1 Turtle - Prefixes and ";" and ","

<http://example.com/index.html> <http://purl.org/dc/terms/created> "2020-04-23"^^<http://…#date> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8574> .

<http://example.com/index.html> <http://purl.org/dc/terms/creator> <http://example.com/staff/8575> .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "Moje stránka"@cs .

<http://example.com/index.html> <http://purl.org/dc/terms/title> "My page"@en .

26

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .�@prefix dcterms: <http://purl.org/dc/terms/> .�@prefix my: <http://example.com/> .�@prefix staff: <http://example.com/staff/> .��my:index.html dcterms:created "2020-04-23"^^xsd:date ;

dcterms:creator staff:8574 ,

staff:8575 ;

dcterms:title "Moje stránka"@cs ,

"My page"@en .

27 of 77

RDF 1.1 Turtle - More prefixes

@prefix foo: <http://example.org/ns#> .�@prefix : <http://other.example.org/ns#> .

foo:bar foo: : .�:bar : foo:bar .

<http://example.org/ns#bar> <http://example.org/ns#> <http://other.example.org/ns#> .

<http://other.example.org/ns#bar> <http://other.example.org/ns#> <http://example.org/ns#bar> .

27

28 of 77

RDF 1.1 Turtle - Relative IRIs

  • </path>
  • <#fragment>
  • <>

Need to know, relative to WHAT the IRI is.

  • Implicitly, a document URL (if known)
  • Explicitly using @base

Assuming Document URL https://test.org/doc��@prefix foo: <http://example.org/ns#> .��<#document> foo: <https://jk.com> .��@base <http://newbase.com/> .�<#document> foo: <https://jk.com> .

<https://test.org/doc#document> <http://example.org/ns#> <https://jk.com> .

<http://newbase.com/#document> <http://example.org/ns#> <https://jk.com> .

28

29 of 77

RDF 1.1 Turtle - Multiline strings, escapes

"""a string�with newlines�"""

  • \t (U+0009, tab)
  • \n (U+000A, linefeed)
  • \r (U+000D, carriage return)
  • \" (U+0022, double quote - only allowed inside strings)
  • \> (U+003E, greater than - only allowed inside URIs)
  • \\ (U+005C, backslash)
  • \uHHHH or \UHHHHHHHH for writing Unicode characters by hexadecimal codepoint where H is a single hexadecimal digit.

29

30 of 77

RDF 1.1 Turtle - Class assignment (rdf:type)

<http://example.com/index.html> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> foaf:Document .

=

<http://example.com/index.html> a foaf:Document .

30

31 of 77

RDF 1.1 Turtle - blank nodes

<http://example.com/> a v:VCard ;� v:adr [

a v:Work ;

v:country-name "Australia" ;

v:locality "WonderCity" ;

v:postal-code "5555" ;

v:street-address "33 Enterprise Drive"

] ;

.

<http://example.com/> v:adr _:1234 .

_:1234 a v:Work ;

v:locality "WonderCity" ;

...

31

=

32 of 77

RDF 1.1 Turtle - datatype shortcuts

ex:Car ex:numberOfWheels 4 ;

ex:Car ex:numberOfWheels +4 ;

ex:Car ex:numberOfWheels "4"^^xsd:integer ;

ex:Car ex:value 1300000.0 ;

ex:Car ex:value "1300000.0"^^xsd:decimal ;

ex:Car ex:value 1.3e6 ;

ex:Car ex:value "1.3e6"^^xsd:double ;

ex:Car ex:leftHandDrive true ;

ex:Car ex:leftHandDrive "true"^^xsd:boolean ;

32

33 of 77

RDF 1.1 Turtle - rdf:List shortcut

# the value of this triple is the RDF collection blank node

:subject :predicate ( :a :b :c ) .

# an empty collection value - rdf:nil

:subject :predicate2 () .

33

34 of 77

RDF 1.1 Turtle - playing with prefixes and rel. IRIs

# In-scope base IRI is the document URI at this point�<a1> <b1> <c1> .�@base <http://example.org/ns/> .��# In-scope base IRI is http://example.org/ns/ at this point�<a2> <http://example.org/ns/b2> <c2> .�@base <foo/> .��# In-scope base IRI is http://example.org/ns/foo/ at this point�<a3> <b3> <c3> .�@prefix : <bar#> .�:a4 :b4 :c4 .�@prefix : <http://example.org/ns2#> .�:a5 :b5 :c5 .

34

http://example.org/ns/c2

http://example.org/ns/foo/

http://example.org/ns/foo/c3

http://example.org/ns/foo/bar#

http://example.org/ns/foo/bar#c4

http://example.org/ns2#c5

35 of 77

Detour from RDF serializations

35

36 of 77

RDF model - statements about statements

my:index.html my:createdBy "Jakub Klímek" .

36

This statement

  • came from https://x.y.z
  • was scraped on 2020-04-23

How to represent these facts in RDF?

37 of 77

RDF model - reification

Direct approach to the problem:

Statement will become a resource.

  • Assign IRI to the statement itself, or
  • make it a blank node (e.g. _:triple1)

Original statement:

my:index.html my:createdBy "Jakub Klímek" .

Reified statement:

_:triple1 a rdf:Statement .

_:triple1 rdf:subject my:index.html .

_:triple1 rdf:predicate my:createdBy .

_:triple1 rdf:object "Jakub Klímek" .

37

Possibility of additional statements we need:

_:triple1 dcterms:created "2020-04-23"^^xsd:date .

38 of 77

RDF model - named graphs

Alternative approach to the problem:

  • Statements belong to “named graphs”
  • Named graphs are resources
  • We can state facts about resources

RDF Triples become RDF Quads

  • S P O G
  • G can be used as subject of another triple (quad)

38

my:index.html

my:staff/85740

dcterms:creator

education

en

dcterms:language

dcterms:subject

my:index.html

my:staff/85740

dcterms:creator

education

en

dcterms:language

dcterms:subject

my:index.html

my:staff/85740

dcterms:creator

education

en

dcterms:language

dcterms:subject

https://example.org/named-graphs/1

39 of 77

RDF dataset

Consists of

  • set of named graphs
    • identified by IRIs
  • one default graph

39

my:index.html

my:staff/85740

dcterms:creator

education

en

dcterms:language

dcterms:subject

my:index.html

my:staff/85740

dcterms:creator

education

en

dcterms:language

dcterms:subject

my:index.html

my:staff/85740

dcterms:creator

education

en

dcterms:language

dcterms:subject

https://example.org/named-graphs/1

https://example.org/named-graphs/2

default graph

40 of 77

Back to RDF serializations

40

41 of 77

RDF 1.1 N-Quads

  • W3C Recommendation
    • 25 February 2014
  • Based on N-Triples, adds support for named graphs

S P O G

<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> <http://example.org/graphs/spiderman> .

41

42 of 77

RDF 1.1 TriG

  • W3C Recommendation
    • 25 February 2014
  • Based on RDF Turtle, adds support for named graphs

RDF Dataset consists of

  • 1 default graph
  • N named graphs

@base <http://www.w3.org/People/> .

@prefix : <http://xmlns.com/foaf/0.1/> .

# default graph

{

ericFoaf:ericP :givenName "Eric" .

}

# also default graph, no {}

ericFoaf:ericP :givenName "Eric" .

# graph highlight

GRAPH <Eric/ericP-foaf.rdf> {

ericFoaf:ericP :givenName "Eric" .

}

42

43 of 77

RDFS: RDF Schema

43

44 of 77

RDFS - RDF Schema 1.1

W3C Recommendation

  • 25 February 2014

Vocabulary for creation of other RDF vocabularies

  • rdfs:Resource, rdfs:Class, rdfs:subClassOf
  • rdf:Property, rdfs:subPropertyOf
  • rdfs:range, rdfs:domain
  • rdfs:comment, rdfs:label, rdfs:seeAlso

44

45 of 77

RDFS - defining classes and class hierarchies

ex:MotorVehicle rdf:type rdfs:Class .

ex:PassengerVehicle rdf:type rdfs:Class .

ex:Van rdf:type rdfs:Class .

ex:Truck rdf:type rdfs:Class .

ex:MiniVan rdf:type rdfs:Class .

ex:PassengerVehicle rdfs:subClassOf ex:MotorVehicle .

ex:Van rdfs:subClassOf ex:MotorVehicle .

ex:Truck rdfs:subClassOf ex:MotorVehicle .

ex:MiniVan rdfs:subClassOf ex:Van .

ex:MiniVan rdfs:subClassOf ex:PassengerVehicle .

45

46 of 77

RDFS - defining classes and class hierarchies

46

ex:MotorVehicle

ex:Truck

ex:Van

ex:PassengerVehicle

ex:MiniVan

rdfs:subclassOf

rdfs:subclassOf

rdfs:subclassOf

rdfs:subclassOf

rdfs:subclassOf

47 of 77

RDFS - defining properties and property hierarchies

ex:Person rdf:type rdfs:Class .

ex:author rdf:type rdf:Property .

ex:author rdfs:range ex:Person .

ex:hasMother rdf:type rdf:Property .

ex:hasMother rdfs:range ex:Female .

ex:hasMother rdfs:domain ex:Person .

ex:age rdf:type rdf:Property .

ex:age rdfs:range xsd:integer .

exterms:weight rdfs:domain ex:Book .

exterms:weight rdfs:domain ex:MotorVehicle .

ex:driver rdf:type rdf:Property .

ex:primaryDriver rdf:type rdf:Property .

ex:primaryDriver rdfs:subPropertyOf ex:driver .

47

48 of 77

RDFS - property hierarchies

48

ex:Person

ex:MotorVehicle

ex:driver

ex:primaryDriver

ex:driver a rdf:Property .

ex:primaryDriver a rdf:Property .

ex:primaryDriver rdfs:subPropertyOf

ex:driver .

49 of 77

RDFS: label, comment, seeAlso

  • rdfs:label
    • Human readable name of a resource
  • rdfs:comment
    • Longer description of a resource
  • rdfs:seeAlso
    • Points to a resource that might provide more information about the subject resource
  • rdfs:isDefinedBy
    • In a sense not specified by RDF

49

50 of 77

Example of vocabulary defined by RDFS

#Vocabulary, represented using RDF and the RDFS vocabulary

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

@prefix foaf: <http://xmlns.com/foaf/0.1/> .

@prefix ex: <https://example.org/> .

ex:MotorVehicle a rdfs:Class ;

rdfs:label "Motor vehicle"@en, "Motorové vozidlo"@cs ;

rdfs:comment "Vehicle, which has a motor"@en,

"Vozdilo, které má motor"@cs .

ex:PassengerVehicle a rdfs:Class ;

rdfs:label "Passenger vehicle"@en, "Vozidlo pro cestující"@cs ;

rdfs:subClassOf ex:MotorVehicle .

ex:driver a rdf:Property ;

rdfs:label "Driver"@en, "Řidič"@cs ;

rdfs:domain ex:MotorVehicle ;

rdfs:range foaf:Person .

ex:primaryDriver a rdf:Property .

rdfs:label "Primary driver"@en, "Hlavní řidič"@cs ;

rdfs:subPropertyOf ex:driver .

#Instances, data, also represented using RDF

@prefix dcterms: <http://purl.org/dc/terms/> .

@prefix ex: <https://example.org/> .

@prefix exr: <https://example.org/resource/> .

exr:1 a ex:PassengerVehicle ;

dcterms:title "Moje první auto"@cs, "My first car"@en ;

ex:primaryDriver <https://jakub.klímek.com/#me> .

exr:2 a ex:PassengerVehicle ;

dcterms:title "Moje druhé auto"@cs, "My second car"@en ;

ex:primaryDriver <https://jakub.klímek.com/#me> .

50

# Inferred triples (a.k.a. reasoning)

exr:1 a ex:MotorVehicle .

exr:2 a ex:MotorVehicle .

<https://jakub.klímek.com/#me> a foaf:Person .

exr:1 ex:driver <https://jakub.klímek.com/#me> .

exr:2 ex:driver <https://jakub.klímek.com/#me> .

51 of 77

Back to RDF serializations

51

52 of 77

JSON-LD 1.1 - JSON for Linked Data

"@context":

{

"name": "http://schema.org/name",

"image": {

"@id": "http://schema.org/image",

"@type": "@id"

},

"homepage": {

"@id": "http://schema.org/url",

"@type": "@id"

}

},

52

"name": "Manu Sporny",

"homepage": "http://manu.sporny.org/",

"image": "http://manu.sporny.org/images/manu.png"�}

JSON-LD @context��Makes JSON interpretable as RDF model through mapping specified by @keywords

Normal JSON

{

53 of 77

JSON-LD 1.1 - JSON for Linked Data

JSON-LD 1.1 - W3C Recommendation

  • 16 July 2020

Developed at:

53

54 of 77

JSON-LD - subject identifier (IRI)

{

"@context":

{

...

"name": "http://schema.org/name"

},

"@id": "http://me.markus-lanthaler.com/",

"name": "Markus Lanthaler",

...

}

54

http://me.markus-lanthaler.com/

"Markus Lanthaler"

http://schema.org/name

55 of 77

JSON-LD - type/class identifier (IRI)

{

...

"@id": "http://example.org/places#BrewEats",

"@type": "http://schema.org/Restaurant",

...

}��{

...

"@id": "http://example.org/places#BrewEats",

"@type": [ "http://schema.org/Restaurant", "http://schema.org/Brewery" ],

...

}

{

"@context": {

...

"Restaurant": "http://schema.org/Restaurant",

"Brewery": "http://schema.org/Brewery"

},

"@id": "http://example.org/places#BrewEats",

"@type": [ "Restaurant", "Brewery" ],

...

}

55

http://example.org/places#BrewEats

s:Brewery

s:Restaurant

rdf:type

rdf:type

56 of 77

JSON-LD - base IRI

{

"@context": {

"@base": "http://example.com/document.jsonld"

},

"@id": "",

"label": "Just a simple document"

}

56

= http://example.com/document.jsonld�(relative to @base)

57 of 77

JSON-LD - default vocabulary

{

"@context": {

"@vocab": "http://schema.org/"

},

"@id": "http://example.org/places#BrewEats",

"@type": "Restaurant",

"name": "Brew Eats"

...

}

57

http://example.org/places#BrewEats

s:Restaurant

rdf:type

Brew Eats

schema:name

58 of 77

JSON-LD - exempting keys from RDF

{

"@context":

{

"@vocab": "http://schema.org/",

"databaseId": null

},

"@id": "http://example.org/places#BrewEats",

"@type": "Restaurant",

"name": "Brew Eats",

"databaseId": "23987520"

}

58

http://example.org/places#BrewEats

Brew Eats

s:Restaurant

schema:name

rdf:type

59 of 77

JSON-LD - compact IRIs

{

"@context":

{

"foaf": "http://xmlns.com/foaf/0.1/"

...

},

"@type": "foaf:Person"

"foaf:name": "Dave Longley",

...

}

59

"Dave Longley"

foaf:Person

foaf:name

rdf:type

60 of 77

JSON-LD - value type in context

{

"@context":

{

"modified":

{

"@id": "http://purl.org/dc/terms/modified",

"@type": "http://www.w3.org/2001/XMLSchema#dateTime"

}

},

...

"@id": "http://example.com/docs/1",

"modified": "2010-05-29T14:17:39+02:00",

...

}

60

http://example.com/docs/1

"2010-05-29T14:17:39+02:00"^^xsd:dateTime

http://purl.org/dc/terms/modified

61 of 77

JSON-LD - embedding

{

...

"name": "Manu Sporny",

"knows":

{

"@type": "Person",

"name": "Gregg Kellogg",

}

...

}

61

Manu Sporny

foaf:name

foaf:knows

foaf:Person

Gregg Kellogg

rdf:type

foaf:name

62 of 77

JSON-LD - scoped contexts

{

"@context":

{

"name": "http://example.com/person#name,

"details": "http://example.com/person#details"

}",

"name": "Markus Lanthaler",

...

"details":

{

"@context":

{

"name": "http://example.com/organization#name"

},

"name": "Graz University of Technology"

}

}

62

Markus Lanthaler

http://example.com/person#name

http://example.com/person#details

Graz University of Technology

http://example.com/organization#name

63 of 77

JSON-LD - languages

{

"@context": {

...

"ex": "http://example.com/vocab/",

"@language": "ja",

"name": { "@id": "ex:name", "@language": null },

"occupation": { "@id": "ex:occupation" },

"occupation_en": { "@id": "ex:occupation", "@language": "en" },

"occupation_cs": { "@id": "ex:occupation", "@language": "cs" }

},

"name": "Yagyū Muneyoshi",

"occupation": "忍者",

"occupation_en": "Ninja",

"occupation_cs": "Nindža",

...

}

63

"Ninja"@en

"忍者"@ja

ex:occupation

ex:occupation

"Yagyū Muneyoshi"

"Nindža"@cs

ex:name

ex:occupation

64 of 77

JSON-LD - language maps

{

"@context":

{

...

"occupation": { "@id": "ex:occupation", "@container": "@language" }

},

"name": "Yagyū Muneyoshi",

"occupation":

{

"ja": "忍者",

"en": "Ninja",

"cs": "Nindža"

}

...

}

64

"Ninja"@en

"忍者"@ja

ex:occupation

ex:occupation

"Yagyū Muneyoshi"

"Nindža"@cs

ex:name

ex:occupation

65 of 77

JSON-LD - multiple values

{

...

"@id": "http://example.org/people#joebob",

"nick": [ "joe", "bob", "JB" ],

...

}

{

...

"@id": "http://example.org/people#joebob",

"foaf:nick":

{

"@list": [ "joe", "bob", "jaybee" ]

},

...

}

65

66 of 77

JSON-LD - reverse properties 0/2

[

{

"@id": "#homer",

"http://example.com/vocab#name": "Homer"

},

{

"@id": "#bart",

"http://example.com/vocab#name": "Bart",

"http://example.com/vocab#parent": { "@id": "#homer" }

},

{

"@id": "#lisa",

"http://example.com/vocab#name": "Lisa",

"http://example.com/vocab#parent": { "@id": "#homer" }

}

]

66

67 of 77

JSON-LD - reverse properties 1/2

{

"@id": "#homer",

"http://example.com/vocab#name": "Homer",

"@reverse": {

"http://example.com/vocab#parent": [

{

"@id": "#bart",

"http://example.com/vocab#name": "Bart"

},

{

"@id": "#lisa",

"http://example.com/vocab#name": "Lisa"

}

]

}

}

67

68 of 77

JSON-LD - reverse properties 2/2

{

"@context": {

"name": "http://example.com/vocab#name",

"children": { "@reverse": "http://example.com/vocab#parent" }

},

"@id": "#homer",

"name": "Homer",

"children": [

{

"@id": "#bart",

"name": "Bart"

},

{

"@id": "#lisa",

"name": "Lisa"

}

]

}

68

#homer

#lisa

http://example.com/vocab#parent

#bart

69 of 77

JSON-LD - named graphs

{

"@context": {

"generatedAt": {

"@id": "http://www.w3.org/ns/prov#generatedAtTime",

"@type": "http://www.w3.org/2001/XMLSchema#date"

},

"Person": "http://xmlns.com/foaf/0.1/Person",

"name": "http://xmlns.com/foaf/0.1/name",

"knows": "http://xmlns.com/foaf/0.1/knows"

},

"@id": "http://example.org/graphs/73",

"generatedAt": "2012-04-09",

"@graph":

[

{

"@id": "http://manu.sporny.org/about#manu",

"@type": "Person",

"name": "Manu Sporny",

"knows": "http://greggkellogg.net/foaf#me"

}

]

}

69

70 of 77

JSON-LD - aliasing keywords

{

"@context":

{

"url": "@id",

"type": "@type",

"Person": "http://xmlns.com/foaf/0.1/Person",

"name": "http://xmlns.com/foaf/0.1/name"

},

"url": "http://example.com/about#gregg",

"type": "Person",

"name": "Gregg Kellogg"

}

70

71 of 77

JSON-LD - adding external context to JSON

{

"@context": "https://example.org/context.jsonld",

"url": "http://example.com/about#gregg",

"type": "Person",

"name": "Gregg Kellogg"

}

71

72 of 77

JSON-LD - adding external context to JSON

GET /ordinary-json-document.json HTTP/1.1

Host: example.com

Accept: application/ld+json,application/json,*/*;q=0.1

====================================

HTTP/1.1 200 OK

...

Content-Type: application/json

Link: <http://json-ld.org/contexts/person.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{

"name": "Markus Lanthaler",

"homepage": "http://www.markus-lanthaler.com/",

"image": "http://twitter.com/account/profile_image/markuslanthaler"

}

72

73 of 77

RDF 1.1 XML Syntax (RDF/XML)

W3C Recommendation

  • 1.1: 25 February 2014

The oldest RDF serialization

  • the only standard one for RDF 1.0 in 2004
  • meant to allow XML-based systems transfer RDF data
  • difficult for users to read and process
    • serialization of graph-based RDF model into hierarchical XML document
    • reason for many (unwarranted) antipathies towards RDF

73

74 of 77

RDF/XML - basic RDF triple

<rdf:RDF>

<rdf:Description rdf:about="SubjectResource">

<PredicateResource>ObjectLiteral</PredicateResource>

<PredicateResource rdf:resource="ObjectResource"/>

</rdf:Description>

</rdf:RDF>

74

75 of 77

RDF/XML - blank nodes

<rdf:RDF>

<rdf:Description rdf:about="SubjectResource">

<PredicateResource rdf:nodeID="BlankNode"/>

</rdf:Description>

<rdf:Description rdf:nodeID="BlankNode">

</rdf:Description>

</rdf:RDF>

75

76 of 77

RDF/XML - typed literals

Typed literals

<rdf:Description rdf:about="SubjectResource">

<PredicateResource rdf:datatype="LiteralType">

ObjectLiteral

</PredicateResource>

</rdf:Description>

<!-- Alternatively using XML entities -->

<!DOCTYPE rdf:RDF [<!ENTITY my "TypePrefix">]>

<… rdf:datatype="&my;TypeName">…</…>

76

77 of 77

RDF/XML - XML literals

In graph, this literal has datatype rdf:XMLLiteral

<?xml version="1.0"?>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

xmlns:dc="http://purl.org/dc/elements/1.1/"

xml:base="http://www.example.com/books">

<rdf:Description rdf:ID="book12345">

<dc:title rdf:parseType="Literal">

<span xml:lang="en">

The <em>&lt;br /&gt;</em> Element Considered Harmful.

</span>

</dc:title>

</rdf:Description>

</rdf:RDF>

77