class: center, middle # Introduction to RDF and Linked Data ## Alexandre Bertails http://bertails.org ## Text By the Bay
permalink: http://bertails.org/2015/04/25/intro-linked-data --- ## once upon a time: the Web -- .left.huge[URL]
-- .center.huge[HTTP]
-- .right.huge[HTML] --- ## once upon a time: the Web **of Data** .left.huge[URL]
.center.huge[HTTP]
.right.huge[RDF] --- ## TimBL as RDF
--- ## TimBL as Turtle ``` @prefix schema:
. @prefix profile:
. @prefix ex:
. @prefix rdf:
.
a schema:Person ; schema:alternateName "TimBL" ; profile:first_name "Tim" ; profile:last_name "Berners-Lee" ; schema:workLocation [ schema:name "W3C/MIT" ] ; schema:performerIn _:b1, _:b2 ; ex:preferredLanguages ( "en" "fr" ). _:b1 schema:name "F2F5 - Linked Data Platform" ; schema:url
. _:b2 a schema:Event ; schema:name "TED 2009" ; schema:startDate "2009-02-04" ; schema:url
. ``` --- ## TimBL as JSON-LD ``` { "@context": "http://schema.org/", "@id": "http://example.com/timbl#", "@type": "Person", "preferredLanguages": [ "en", "fr" ], "first_name": "Tim", "last_name": "Berners-Lee", "alternateName": "TimBL", "performerIn": [ { "@id": "_:b0", "@type": "Event", "name": "TED 2009", "startDate": "2009-02-04", "url": "http://conferences.ted.com/TED2009/" }, ... ] } ``` --- ## RDF: one abstract model ``` graph ::= Set(triple) triple ::= (node, iri, node) node ::= iri | bnode | literal iri ::= URI with Unicode bnode ::= local node identifier literal ::= (lexicalForm, datatype, Option(lang)) lexicalForm ::= string datatype ::= iri lang ::= string ```
.right[as defined in [RDF 1.1 Concepts](http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph)] --- ## RDF: several syntaxes * Turtle * JSON-LD * RDF/XML * N-Triples, TriG, etc. ??? * without a context **and** a frame, JSON-LD won't be used by Web Developers * JSON-LD encourages you to work on a tree, while RDF is a graph * don't sacrifice correctness for "pragmatism": JSON itself is usually not enough for data --- ## syntax examples * `
` is a **IRI** * `xsd:integer` is a **prefixed IRI**, alias for
* `_:b2719` is a **blank node** * `"foo"` is a **string literal** (`"foo"`, `xsd:string`, no lang) * `42` is an **integer** (`"42"`, `xsd:integer`, no lang) * `"foo"@en` is an **i18ned string** ("foo", `rdf:langString`, `"en"`) --- ## datasets ``` dataset ::= (graph, Set(namedGraph)) namedGraph ::= (graphName, graph) graphName ::= iri | bnode ```
#### in plain English * a **dataset** is made of one **default graph** and a collection of **named graphs** * a **named graph** is a graph with a name (either IRI or Blank Node) ??? who knows examples of datasets? --- ## two views of the world * **databases** vs the **Web** * **web services** vs **REST** * **SPARQL** vs **LDP**
.center.big[not opposed, just **complimentary**] ??? just a shift of focus --- ## Semantic Web^W^WLinked Data timeline
--- ## SPARQL looking for the episodes of Doctor Who on http://dbpedia.org/sparql -- #### simple query ``` SELECT DISTINCT ?s ?p WHERE { ?s ?p "Doctor Who"@en . } LIMIT 100 ``` #### just a bit more complex ``` SELECT DISTINCT ?s ?date WHERE { ?s ?p
. ?s dbpprop:date ?date . FILTER (?date > "2001-01-01"^^xsd:dateTime) . } LIMIT 500 ``` --- ## Linked Data .center.huge[demo] --
``` curl -H 'Accept: text/html' http://bertails.org/alex | head curl -H 'Accept: text/turtle' http://bertails.org/alex curl -H 'Accept: text/turtle' http://www.w3.org/People/Berners-Lee/card curl -H 'Accept: text/turtle' http://graph.facebook.com/bertails curl -H 'Accept: text/turtle' http://www.bbc.co.uk/things/cbeab979-c95b-432e-a3bb-2b1d502f4db5 ``` --- ## LDP: read/write Linked Data **tldr:** containers (LDP-C) contains (`ldp:contains`) resources (LDP-R) ### HTTP-based (RESTful) * POST, PUT, PATCH, DELETE, GET * REST interactions model through `Link` header ### RDF-biased * for RDF applications (domain-specific triples) * relies on RDF (protocol-related triples) * also supports binaries --- ## sharing structured data on the Web .big[http://www.bbc.co.uk/programmes/b006q2x0] ### with Facebook, Bing, Google, Yahoo!, Yandex, etc. * [Open Graph Protocol](https://developers.facebook.com/docs/sharing/webmasters) * http://schema.org -- ### W3C RDFa distiller http://www.w3.org/2012/pyRdfa/ [direct link](http://www.w3.org/2012/pyRdfa/extract?uri=http://www.bbc.co.uk/programmes/b006q2x0) --- ## summary * RDF: model and serializations * Semantic Web vs Linked Data * SPARQL vs LDP * shared ontologies