cc7220-1 la web de datos - aidanhogan.com

117
CC7220-1 LA WEB DE DATOS PRIMAVERA 2021 Lecture 2: RDF Model and Syntax Aidan Hogan [email protected]

Upload: others

Post on 29-Apr-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CC7220-1 La Web de Datos - aidanhogan.com

CC7220-1 LA WEB DE DATOS PRIMAVERA 2021 Lecture 2: RDF Model and Syntax

Aidan Hogan

[email protected]

Page 2: CC7220-1 La Web de Datos - aidanhogan.com

The “Semantic Web”

Page 3: CC7220-1 La Web de Datos - aidanhogan.com

Semantic Web: Data, Logic, Query

* More or less

Page 4: CC7220-1 La Web de Datos - aidanhogan.com

RDF: Resource Description Framework

Page 5: CC7220-1 La Web de Datos - aidanhogan.com

RDF (1.1): A Web Standard

Page 6: CC7220-1 La Web de Datos - aidanhogan.com

Semantic Web: Data

* More or less

Page 7: CC7220-1 La Web de Datos - aidanhogan.com

Semantic Web: Data

Page 8: CC7220-1 La Web de Datos - aidanhogan.com

Modelling the world with triples

Page 9: CC7220-1 La Web de Datos - aidanhogan.com

Concatenate to “integrate” new data

Page 10: CC7220-1 La Web de Datos - aidanhogan.com

RDF often drawn as a (directed, labelled) graph

Page 11: CC7220-1 La Web de Datos - aidanhogan.com

Set of triples thus called an “RDF Graph”

Page 12: CC7220-1 La Web de Datos - aidanhogan.com

But why graphs?

Why not (e.g.) tables?

Page 13: CC7220-1 La Web de Datos - aidanhogan.com

Graphs are flexible

Page 14: CC7220-1 La Web de Datos - aidanhogan.com

Relational Databases …

Page 15: CC7220-1 La Web de Datos - aidanhogan.com

Relational Databases …

Page 16: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 17: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 18: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 19: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 20: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 21: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 22: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 23: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 24: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 25: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 26: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 27: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 28: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 29: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 30: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 31: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 32: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 33: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

Page 34: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Relational Data

(╯°□°)╯︵ ┻━┻

Page 35: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 36: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 37: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 38: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 39: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 40: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 41: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 42: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 43: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 44: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 45: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 46: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 47: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 48: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 49: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 50: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 51: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 52: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 53: CC7220-1 La Web de Datos - aidanhogan.com

Planets / Graph Data

Page 54: CC7220-1 La Web de Datos - aidanhogan.com

Relational data: Pros and Cons

We have to impose a

structure (schema) from the start

We have a

structure (schema) imposed from the start

Page 55: CC7220-1 La Web de Datos - aidanhogan.com
Page 56: CC7220-1 La Web de Datos - aidanhogan.com

Graph Data: Pros and Cons

We don't have to impose a

structure (schema) from the start

We don't have a

structure (schema) imposed from the start

Page 57: CC7220-1 La Web de Datos - aidanhogan.com
Page 58: CC7220-1 La Web de Datos - aidanhogan.com

Naming things

Page 59: CC7220-1 La Web de Datos - aidanhogan.com

Naming things: Strings not enough

Page 60: CC7220-1 La Web de Datos - aidanhogan.com

Naming things: Strings not enough

Page 61: CC7220-1 La Web de Datos - aidanhogan.com

Naming things: Strings not enough

Page 62: CC7220-1 La Web de Datos - aidanhogan.com

Naming things: Strings not enough

Page 63: CC7220-1 La Web de Datos - aidanhogan.com

Naming things: Strings not enough

Page 64: CC7220-1 La Web de Datos - aidanhogan.com

Naming things in RDF: IRIs

Page 65: CC7220-1 La Web de Datos - aidanhogan.com

Need unambiguous symbols/identifiers

• Since we’re on the Web … use Web identifiers

• URL: Uniform Resource Location – The location of a resource on the Web – http://ex.org/Dubl%C3%ADn.html

• URI: Uniform Resource Identifier (RDF 1.0) – Need not be a location, can also be a name – http://ex.org/Dubl%C3%ADn

• IRI: Internationalised Resource Identifier (RDF 1.1) – A URI that allows Unicode characters – http://ex.org/Dublín

Page 66: CC7220-1 La Web de Datos - aidanhogan.com

We will use IRIs with prefixes

• http://ex.org/Dublín ↔ ex:Dublín

• “ex:” denotes a prefix for http://ex.org/

• “Dublín” is the local name

• Frequently used prefixes:

Page 67: CC7220-1 La Web de Datos - aidanhogan.com

From strings …

Page 68: CC7220-1 La Web de Datos - aidanhogan.com

… to IRIs …

Page 69: CC7220-1 La Web de Datos - aidanhogan.com

Naming things in RDF: Literals

Page 70: CC7220-1 La Web de Datos - aidanhogan.com

What about numbers?

Should we assign IRIs to

numbers, booleans, etc.?

Page 71: CC7220-1 La Web de Datos - aidanhogan.com

RDF allows “literals” in object position

• Literals are for datatype values, like strings,

numbers, booleans, dates, times

• Only allowed in object position

Page 72: CC7220-1 La Web de Datos - aidanhogan.com

Datatype literals

• "[lexical-string]"^^[datatype-IRI]

– "200"^^xsd:int

– "2014-12-13"^^xsd:date

– "true"^^xsd:boolean

– "this is a string"^^xsd:string

• If the datatype is omitted, it’s a string

– "this is a string"

– "200" is a string, not a number!

Page 73: CC7220-1 La Web de Datos - aidanhogan.com

Many datatypes borrowed from XML Schema

Page 74: CC7220-1 La Web de Datos - aidanhogan.com

Boolean datatype

Page 75: CC7220-1 La Web de Datos - aidanhogan.com

Numeric datatypes

Page 76: CC7220-1 La Web de Datos - aidanhogan.com

Temporal datatypes

Page 77: CC7220-1 La Web de Datos - aidanhogan.com

Text/string datatypes

Page 78: CC7220-1 La Web de Datos - aidanhogan.com

Language-Tagged Strings

• Specify that a string is in a given language

– "string"@lang-tag

• No datatype!

Page 79: CC7220-1 La Web de Datos - aidanhogan.com

(Not) Naming Things in RDF: Blank Nodes

Page 80: CC7220-1 La Web de Datos - aidanhogan.com

Having to name everything is hard work

Page 81: CC7220-1 La Web de Datos - aidanhogan.com

For this reason, RDF gives blank nodes

• Syntax: _:blankNode

• Represents existence of something – Often used to avoid giving an IRI (e.g., shortcuts)

• Can only appear in subject or object position

• (More later)

Page 82: CC7220-1 La Web de Datos - aidanhogan.com

RDF Terms: summary

Page 83: CC7220-1 La Web de Datos - aidanhogan.com

A Summary of RDF Terms

1. IRIs (Internationalised Resource Identifiers)

– Used to name generic things

2. Literals

– Used to refer to datatype values

– Strings may have a language tag

3. Blank Nodes

– Used to avoid naming things

– A little mysterious right now

Page 84: CC7220-1 La Web de Datos - aidanhogan.com

Modelling data in RDF

Page 85: CC7220-1 La Web de Datos - aidanhogan.com

Let’s model something in RDF …

Model the following in RDF:

“Sharknado is the first movie of the Sharknado series. It first aired on

July 11, 2013. The movie stars Tara Reid and Ian Ziering. The movie

was followed by another called ‘Sharknado 2: The Second One’.”

Page 86: CC7220-1 La Web de Datos - aidanhogan.com

RDF Properties

• RDF Terms used as predicate

– rdf:type, ex:firstMovie, ex:stars, …

Page 87: CC7220-1 La Web de Datos - aidanhogan.com

RDF Classes

• Used to conceptually group resources

– ex:Movie, ex:Actor, ex:Series, etc.

– Uses property rdf:type to type a resource

Page 88: CC7220-1 La Web de Datos - aidanhogan.com

Modelling in RDF not always so simple

Model the following in RDF:

“'Batman Returns' stars Michael Keaton in the role of 'Batman'."

Page 89: CC7220-1 La Web de Datos - aidanhogan.com

Modelling in RDF not always so simple

Model the following in RDF:

"'Batman Returns' stars Michael Keaton in the role of 'Batman'."

"'Batman Begins' stars Christian Bale in the role of 'Batman'."

Problem?

Page 90: CC7220-1 La Web de Datos - aidanhogan.com

Modelling in RDF not always so simple

Model the following in RDF:

"'Batman Returns' stars Michael Keaton in the role of 'Batman'."

"'Batman Begins' stars Christian Bale in the role of 'Batman'."

Problem?

Page 91: CC7220-1 La Web de Datos - aidanhogan.com

Modelling in RDF not always so simple

Model the following in RDF:

"'Batman Returns' stars Michael Keaton in the role of 'Batman'."

"'Batman Begins' stars Christian Bale in the role of 'Batman'."

Problem?

Page 92: CC7220-1 La Web de Datos - aidanhogan.com

Modelling in RDF not always so simple

Model the following in RDF:

"'Batman Returns' stars Michael Keaton in the role of 'Batman'."

"'Batman Begins' stars Christian Bale in the role of 'Batman'."

"'Batman Returns' stars Christian Bale in the role of 'Robin'."*

"'Batman Begins' stars Michael Keaton in the role of 'Robin'."*

* hypothetical

Who played which character in which movie?

Page 93: CC7220-1 La Web de Datos - aidanhogan.com

Modelling n-Ary Relations

Model the following in RDF:

"'Batman Returns' stars Michael Keaton in the role of 'Batman'."

"'Batman Begins' stars Christian Bale in the role of 'Batman'."

Page 94: CC7220-1 La Web de Datos - aidanhogan.com

Modelling in RDF not always so simple

Model the following in RDF:

"The first movie in the Sharknado series is ‘Sharknado’.

The second movie is ‘Sharknado 2: The Second One’.

The third movie is ‘Sharknado 3: Oh Hell No!’."

More general way to represent

lists as a graph?

Page 95: CC7220-1 La Web de Datos - aidanhogan.com

RDF Collections: Model Ordered Lists

• Standard way to model (linked) lists in RDF

– Use rdf:rest to link to rest of list

– Use rdf:first to link to current member

– Use rdf:nil to end the list

Page 96: CC7220-1 La Web de Datos - aidanhogan.com

RDF Collections: Generic Modelling

• Not just for Sharknado series

Page 97: CC7220-1 La Web de Datos - aidanhogan.com

RDF Collections: Generic Modelling

Which modelling is better?

If the order of ingredients matters, the collection above is needed.*

Otherwise, the graph below is much simpler (and better). * Sometimes collections are used for unordered elements to indicate a closed set, but this is not something recommended in general.

Page 98: CC7220-1 La Web de Datos - aidanhogan.com

Blank nodes add complexity

Page 99: CC7220-1 La Web de Datos - aidanhogan.com

Blank nodes are local identifiers

How should we combine these two RDF graphs?

Page 100: CC7220-1 La Web de Datos - aidanhogan.com

Blank nodes are local identifiers

How should we combine these two RDF graphs?

Page 101: CC7220-1 La Web de Datos - aidanhogan.com

Blank nodes names aren’t important …

(Isomorphic)

Page 102: CC7220-1 La Web de Datos - aidanhogan.com

Blank nodes names aren’t important …

(Not Isomorphic!)

Page 103: CC7220-1 La Web de Datos - aidanhogan.com

Are two RDF graphs the “same”?

Page 104: CC7220-1 La Web de Datos - aidanhogan.com

Are two RDF graphs the “same”?

Page 105: CC7220-1 La Web de Datos - aidanhogan.com

Are two RDF graphs the “same”?

Page 106: CC7220-1 La Web de Datos - aidanhogan.com

Are two RDF graphs the “same”?

Page 107: CC7220-1 La Web de Datos - aidanhogan.com

RDF Syntaxes: Writing RDF down

Page 108: CC7220-1 La Web de Datos - aidanhogan.com

N-Triples

• Line delimited format

• No shortcuts

Page 109: CC7220-1 La Web de Datos - aidanhogan.com

RDF/XML

• Legacy format

• Difficult to read

Page 110: CC7220-1 La Web de Datos - aidanhogan.com

RDFa

• Embed RDF into HTML

• Not so intuitive

Page 111: CC7220-1 La Web de Datos - aidanhogan.com

JSON-LD

• Embed RDF into HTML

• Not completely RDF

Page 112: CC7220-1 La Web de Datos - aidanhogan.com

• Readable format

Turtle

Page 113: CC7220-1 La Web de Datos - aidanhogan.com

Turtle: Collections Shortcut

Page 114: CC7220-1 La Web de Datos - aidanhogan.com

RDF …

Page 115: CC7220-1 La Web de Datos - aidanhogan.com

Semantic Web: Data

Page 116: CC7220-1 La Web de Datos - aidanhogan.com

Broadly adopted

https://w3techs.com/technologies/overview/structured_data

Page 117: CC7220-1 La Web de Datos - aidanhogan.com

Questions?