Linked data crash course

...just sparql that graph for triples with {uri} as object

LINKEd data

Available on the web (whatever format) but with an open licence, to be Open Data
★★ Available as machine-readable structured data (e.g. excel instead of image scan of a table)
★★★ as (2) plus non-proprietary format (e.g. CSV instead of excel)
★★★★ All the above plus, Use open standards from W3C (RDF and SPARQL) to identify things, so that people can point at your stuff
★★★★★ All the above, plus: Link your data to other people’s data to provide context

LINKEd data II

  1. Use URIs to name (identify) things.
  2. Use HTTP URIs so that these things can be looked up (interpreted, "dereferenced").
  3. Provide useful information about what a name identifies when it's looked up, using open standards such as RDF, SPARQL, etc.
  4. Refer to other things using their HTTP URI-based names when publishing data on the Web.

 

Tim Berners-Lee 2009

(W3C) Semantic web

provides a common framework that allows data to be shared and reused across application, enterprise, and community boundaries

 

https://www.w3.org/2001/sw/

Some terms

* *RDF* = Resource Description Framework
* *Tripler* = subject -> predicate -> object
* *Triplestore* = database for tripler
  - Virtuoso (NRK)
  - Fuseki (UB)
  - Stardog
  - GraphDB
  - ...
* *Datamodell / ontologi / schema* = klasser og relasjoner
  - foaf:     -> friend of a friend
  - dct:      -> Dublin Core Terms
  - schema:   -> Schema.org
  - crm:      -> CIDOC-CRM
* *Vokabular* = kontrollert begrepsapparat

Reading list

rdf 1.1

Resource Description Framework

#basis er tripler
<subject>   <predicate>   <object>
   uri          uri      uri|literal
   ?s           ?p          ?o

#N-TRIPLES
<http://data.uib.no/tarje> <http://schema.uib.no/name> "Tarje Lavik" .
<http://data.uib.no/tarje> <http://schema.uib.no/knows> <http://data.uib.no/per> .

Serialisation

#N-TRIPLES
<http://data.uib.no/tarje> <http://schema.uib.no/name> "Tarje Lavik" .
#TURTLE/N3
@prefix uib: <http://schema.uib.no/> .

<http://data.uib.no/tarje> uib:name "Tarje Lavik" .
#RDF/XML
<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:uib="http://schema.uib.no/">
  <rdf:Description rdf:about="http://data.uib.no/tarje">
    <uib:name>Tarje Lavik</uib:name>
  </rdf:Description>
</rdf:RDF>
#JSON-LD
[{
  "@id":"http://data.uib.no/tarje",
  "http://schema.uib.no/name":
    [{ "@value":"Tarje Lavik" }]
}]

SERIALISation II

# Turtle is human-readable

# N-TRIPLES is easy to split into chunks as
# every line is a selfcontained statement

<http://data.uib.no/tarje> <http://schema.uib.no/name> "Tarje Lavik" .
<http://data.uib.no/tarje> <http://schema.uib.no/father>  <http://data.uib.no/kjartan> .
# JSON-LD is great. Turn ordinary JSON into RDF
# by adding a @context and @id
{
  "@context": {
    "name": "http://schema.uib.no/name"
  },
  "@id": "http://data.uib.no/tarje",
  "name": "Tarje Lavik"
}

URI|LITERALS?

# RDF datatypes = XSD types 
# xsd:date, xsd:dateTime, xsd:Year, blabla

<http://data.uib.no/tarje> uib:selfDelusion "13.1"^^xsd:decimal .
  
Custom datatypes possible

Datatypes are used with RDF literals to represent values such as strings, numbers and dates.

UBB RDF examples

UBB RDF examples

#Turtle
@prefix :     <http://data.ub.uib.no/id/> .
@prefix uib:  <http://schema.ub.uib.no/> .
@prefix owl:  <https://www.w3.org/2002/07/owl#> .

:ubb-bs-ok-16634 a uib:Photograph ;
    uib:title "[Pause på fjellet]" ;
    uib:maker uib:df4c7076-1e25-4020-abfd-e718412c0731 ;
    uib:hasRepresentation uib:ubb-bs-ok-16634_files .

:df4c7076-1e25-4020-abfd-e718412c0731 a uib:Person ;
    uib:name "Bailli Knudtzon" ;
    uib:identifier "df4c7076-1e25-4020-abfd-e718412c0731" ;
    owl:sameAs <https://www.histreg.no/index.php/person/daid/pf01052994001138> .


uib:ca-1 a uib:ConditionAssessment ;
    uib:assessmentOf :ubb-bs-ok-16634 ;
    uib:conditionState uib:superDuper .

SCHEMa / datamodell

#Turtle
@prefix :     <http://data.uib.no/> .
@prefix uib:  <http://schema.uib.no/> .
@prefix rdfs: <http://www.w3.org/TR/1999/PR-rdf-schema-19990303#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

:ubb-bs-ok-16634 a uib:Photograph ;
    uib:title "[Pause på fjellet]" ;
    uib:maker uib:st10938 ;
    uib:hasRepresentation uib:ubb-bs-ok-16634_files .
# UiB Schema definitions

uib:Photograph a rdfs:Class ;
    rdfs:label "Photograph"@eng ;
    rdfs:label "Photografi"@nor .

uib:title a rdf:Property ;
    rdfs:label "Tittel"@nor .

uib:maker a rdf:Property ;
    rdfs:label "Skaper"@nor ;
    rdfs:range uib:Person ;
    rdfs:domain uib:Photograph .
# 

uib:Person a rdfs:Class ;
    rdfs:label "Person"@eng .

uib:Photographer a rdfs:Class ;
    rdfs:label "Photographer"@eng ;
    rdfs:subClassOf uib:Person .

SPARQL

SPARQL Protocol and RDF Query Language

http://sparql.ub.uib.no/​

ASK (true|false), SELECT (table), 
DESCRIBE (graph), CONSTRUCT (new graph)
#SPARQL
PREFIX : <http://data.uib.no/> 
PREFIX uib: <http://schema.uib.no/> 

CONSTRUCT {
    :best a uib:Collection . 
    :best uib:title "SuperDuper quality photographs"
    :best uib:hasPart :?o .   
}
WHERE {
    ?s uib:assessmentOf ?o ;
       uib:conditionState uib:suberDuper .
    ?o a uib:Photograph .
}
#Turtle
@PREFIX : <http://data.uib.no/> .
@PREFIX uib: <http://schema.uib.no/> .

:best a uib:Collection ;
	uib:title "SuperDuper quality photographs"
    uib:hasPart :ubb-bs-ok-16634 .

SPARQL UPDATE

#SPARQL UPDATE - Insert/delete triples
PREFIX : <http://data.uib.no/> 
PREFIX uib: <http://schema.uib.no/> 

INSERT {
    :best a uib:Collection . 
    :best uib:title "SuperDuper quality photographs"
    :best uib:hasPart :?o .   
}
WHERE {
    ?s uib:assessmentOf ?o ;
       uib:conditionState uib:suberDuper .
    ?o a uib:Photograph .
}

GRAPH

# Triplestores har én DEFAULT GRAPH, og >=1 NAMED GRAPHS .
# SPARQL-spørring mot sparql.ub.uib.no må ha med GRAPH

CONSTRUCT {
  <http://data.ub.uib.no/instance/photograph/ubb-bs-ok-19362> ?p ?o .
  ?o ?p2 ?o2 .
  ?o a ?type .
}
WHERE {
  GRAPH ?g {
   <http://data.ub.uib.no/instance/photograph/ubb-bs-ok-19362> ?p ?o .
   OPTIONAL { ?o ?p2 ?o2 .
      ?o a ?type .
      FILTER isLiteral(?o2) }
  }
}

# NAMED GRAPHS i datasettet på sparql.ub.uib.no
# Marcus data  - <http://data.ub.uib.no/dataset/marcus-bs>
# Datamodellen - <http://data.ub.uib.no/ontology/ubbont>
# Extra data   - <http://data.ub.uib.no/dataset/extra>

DESCRIBE AND JSON-LD

@prefix geo:   <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix geonames: <http://www.geonames.org/ontology#> .
@prefix dct:   <http://purl.org/dc/terms/> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix skos:  <http://www.w3.org/2004/02/skos/core#> .
@prefix bibo:  <http://purl.org/ontology/bibo/> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ubbont: <http://data.ub.uib.no/ontology/> .
@prefix event: <http://purl.org/NET/c4dm/event.owl#> .
@prefix foaf:  <http://xmlns.com/foaf/0.1/> .

<http://data.ub.uib.no/instance/aggregation/ubb-bs-ok-19362>
        a                    <http://www.openarchives.org/ore/terms/Aggregation> ;
        rdfs:label           "ubb-bs-ok-19362" ;
        ubbont:hasThumbnail  "https://data.ub.uib.no/files/bs/ubb/ubb-bs/ubb-bs-ok/ubb-bs-ok-19362/jpg/ubb-bs-ok-19362_th.jpg"^^<http://www.w3.org/2001/XMLSchema#anyuri> .

<http://data.ub.uib.no/topic/dd509891-f2a4-4008-817b-2644bad3a8b4>
        a                          skos:Concept ;
        ubbont:previousIdentifier  "EM_Teller:248" ;
        dct:available              "2019-06-04"^^<http://www.w3.org/2001/XMLSchema#date> ;
        dct:identifier             "dd509891-f2a4-4008-817b-2644bad3a8b4" ;
        skos:prefLabel             "Sykehus" .

<http://data.ub.uib.no/topic/944a70d3-138d-4a22-ada1-5a3926f96525>
        a                          skos:Concept ;
        ubbont:previousIdentifier  "EM_Teller:952" ;
        dct:available              "2016-11-15"^^<http://www.w3.org/2001/XMLSchema#date> ;
        dct:identifier             "944a70d3-138d-4a22-ada1-5a3926f96525" ;
        skos:prefLabel             "Byggeplass" .

<http://data.ub.uib.no/instance/collection/ubb-bs->
        a                  bibo:Collection ;
        ubbont:sequenceNr  1 ;
        ubbont:showWeb     true ;
        dct:description    "BS-samlingen inneholder mange av fotografiene som var opprinnelsen til \n    Billedsamlingen. Flere av dem kom opprinnelig fra Bergens Museums \n    samlinger, andre ble samlet inn av samlingens tidligste ansatte og andre \n    med interesse for s&#230;rlig bergensk historie. BS-samlingen vokser stadig, og \n    det er her vi tar opp enkeltfotografier eller mindre samlinger av positive \n    og negative fotografier, postkort, lysbilder, trykk og album. Rundt 10.000 \n    av bildene er tilgjengelige digitalt. Samlingen er delt inn etter \n    st&#248;rrelsen p&#229; bildene: UBB-BS-OK- (oktav), UBB-BS-Q-(quart) og UBB-BS-FOL- \n    (foliant)." ;
        dct:identifier     "ubb-bs-" ;
        dct:title          "BS-samlingen" ;
        foaf:logo          "http://data.ub.uib.no/files/bs/ubb/ubb-bs/ubb-bs-q/ubb-bs-q-00348/jpg/ubb-bs-q-00348_th.jpg" .

<http://data.ub.uib.no/instance/agent/c38af810-17b1-4c08-bfe3-cb7951d039e0>
        a               foaf:Agent ;
        dct:identifier  "c38af810-17b1-4c08-bfe3-cb7951d039e0" ;
        foaf:name       "Ukjent" .

<http://data.ub.uib.no/instance/cataloguer/2da532a2-32a7-4aa0-97d8-03ec5b3788b3>
        a                ubbont:Cataloguer ;
        dct:available    "2017-01-17"^^<http://www.w3.org/2001/XMLSchema#date> ;
        dct:identifier   "2da532a2-32a7-4aa0-97d8-03ec5b3788b3" ;
        foaf:familyName  "Endresen" ;
        foaf:firstName   "Torill" ;
        foaf:name        "Torill Endresen" .

<http://data.ub.uib.no/instance/organization/billedsamlingen>
        a                foaf:Organization ;
        ubbont:showWeb   true ;
        dct:available    "2016-05-04"^^<http://www.w3.org/2001/XMLSchema#date> ;
        dct:description  "Billedsamlingen inneholder historiske fotografier fra hele Norge med særlig vekt på Bergen og Vestlandet. Billedsamlingen holder til i Nygårdsgaten 5." ;
        dct:identifier   "billedsamlingen" ;
        geo:lat          "60.38886"^^<http://www.w3.org/2001/XMLSchema#double> ;
        geo:long         "5.32504"^^<http://www.w3.org/2001/XMLSchema#double> ;
        foaf:homepage    "https://spesial.b.uib.no/?page_id=14" ;
        foaf:name        "Billedsamlingen" .

<http://data.ub.uib.no/topic/1c7236ed-3479-40d4-82e2-bc5dbd9f5e26>
        a                          skos:Concept ;
        ubbont:previousIdentifier  "EM_Teller:953" ;
        dct:available              "2016-11-15"^^<http://www.w3.org/2001/XMLSchema#date> ;
        dct:identifier             "1c7236ed-3479-40d4-82e2-bc5dbd9f5e26" ;
        skos:prefLabel             "Stillas" .

<http://data.ub.uib.no/instance/spatialthing/de2f4ec3-3a77-4db7-8a8f-e53980f431d4>
        a                          geo:SpatialThing ;
        ubbont:catalogueStatus     "Må kontrolleres" ;
        ubbont:previousIdentifier  "GL_Teller:1545" ;
        dct:identifier             "de2f4ec3-3a77-4db7-8a8f-e53980f431d4" ;
        geonames:parentADM1        "HORDALAND" ;
        geonames:parentCountry     "Norge" ;
        skos:prefLabel             "Jonas Lies vei 65" .

<http://data.ub.uib.no/instance/photograph/ubb-bs-ok-19362>
        a                         ubbont:Photograph ;
        ubbont:cataloguer         <http://data.ub.uib.no/instance/cataloguer/2da532a2-32a7-4aa0-97d8-03ec5b3788b3> ;
        ubbont:hasRepresentation  <http://data.ub.uib.no/instance/aggregation/ubb-bs-ok-19362> ;
        ubbont:hasThumbnail       "https://data.ub.uib.no/files/bs/ubb/ubb-bs/ubb-bs-ok/ubb-bs-ok-19362/jpg/ubb-bs-ok-19362_th.jpg"^^<http://www.w3.org/2001/XMLSchema#anyuri> ;
        ubbont:madeAfter          "1908-01-01"^^<http://www.w3.org/2001/XMLSchema#date> ;
        ubbont:madeBefore         "1911-12-31"^^<http://www.w3.org/2001/XMLSchema#date> ;
        ubbont:showWeb            true ;
        dct:available             "2016-11-30"^^<http://www.w3.org/2001/XMLSchema#date> ;
        dct:identifier            "ubb-bs-ok-19362" ;
        dct:isPartOf              <http://data.ub.uib.no/instance/collection/ubb-bs-> ;
        dct:spatial               <http://data.ub.uib.no/instance/spatialthing/de2f4ec3-3a77-4db7-8a8f-e53980f431d4> ;
        dct:subject               <http://data.ub.uib.no/topic/944a70d3-138d-4a22-ada1-5a3926f96525> , <http://data.ub.uib.no/topic/dd509891-f2a4-4008-817b-2644bad3a8b4> , <http://data.ub.uib.no/topic/1c7236ed-3479-40d4-82e2-bc5dbd9f5e26> ;
        dct:title                 "[Byggingen av Haukeland Sykehus]" ;
        bibo:owner                <http://data.ub.uib.no/instance/organization/billedsamlingen> ;
        foaf:maker                <http://data.ub.uib.no/instance/agent/c38af810-17b1-4c08-bfe3-cb7951d039e0> .

JSON-LD FRAME

{
  "@context": {
    "label": {
        "@id": "http://purl.org/dc/terms/title"
      },
    "dct": "http://purl.org/dc/terms/",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "ubbont": "http://data.ub.uib.no/ontology/",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "dc": "http://purl.org/dc/elements/1.1/",
    "bibo": "http://purl.org/ontology/bibo/",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "skos": "http://www.w3.org/2004/02/skos/core#",
    "geo": "http://www.w3.org/2003/01/geo/wgs84_pos#"
  },
  "@type": "http://data.ub.uib.no/ontology/Photograph"
}

JSON-LD FRAMED

{
  "@context": {
    "label": {
      "@id": "http://purl.org/dc/terms/title"
    },
    "dct": "http://purl.org/dc/terms/",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "ubbont": "http://data.ub.uib.no/ontology/",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "dc": "http://purl.org/dc/elements/1.1/",
    "bibo": "http://purl.org/ontology/bibo/",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "skos": "http://www.w3.org/2004/02/skos/core#",
    "geo": "http://www.w3.org/2003/01/geo/wgs84_pos#"
  },
  "@id": "http://data.ub.uib.no/instance/photograph/ubb-bs-ok-19362",
  "@type": "ubbont:Photograph",
  "ubbont:cataloguer": {
    "@id": "http://data.ub.uib.no/instance/cataloguer/2da532a2-32a7-4aa0-97d8-03ec5b3788b3",
    "@type": "ubbont:Cataloguer",
    "dct:available": {
      "@type": "http://www.w3.org/2001/XMLSchema#date",
      "@value": "2017-01-17"
    },
    "dct:identifier": "2da532a2-32a7-4aa0-97d8-03ec5b3788b3",
    "foaf:familyName": "Endresen",
    "foaf:firstName": "Torill",
    "foaf:name": "Torill Endresen"
  },
  "ubbont:hasRepresentation": {
    "@id": "http://data.ub.uib.no/instance/aggregation/ubb-bs-ok-19362",
    "@type": "http://www.openarchives.org/ore/terms/Aggregation",
    "ubbont:hasThumbnail": {
      "@type": "http://www.w3.org/2001/XMLSchema#anyuri",
      "@value": "https://data.ub.uib.no/files/bs/ubb/ubb-bs/ubb-bs-ok/ubb-bs-ok-19362/jpg/ubb-bs-ok-19362_th.jpg"
    },
    "rdfs:label": "ubb-bs-ok-19362"
  },
  "ubbont:hasThumbnail": {
    "@type": "http://www.w3.org/2001/XMLSchema#anyuri",
    "@value": "https://data.ub.uib.no/files/bs/ubb/ubb-bs/ubb-bs-ok/ubb-bs-ok-19362/jpg/ubb-bs-ok-19362_th.jpg"
  },
  "ubbont:madeAfter": {
    "@type": "http://www.w3.org/2001/XMLSchema#date",
    "@value": "1908-01-01"
  },
  "ubbont:madeBefore": {
    "@type": "http://www.w3.org/2001/XMLSchema#date",
    "@value": "1911-12-31"
  },
  "ubbont:showWeb": true,
  "dct:available": {
    "@type": "http://www.w3.org/2001/XMLSchema#date",
    "@value": "2016-11-30"
  },
  "dct:identifier": "ubb-bs-ok-19362",
  "dct:isPartOf": {
    "@id": "http://data.ub.uib.no/instance/collection/ubb-bs-",
    "@type": "bibo:Collection",
    "ubbont:sequenceNr": 1,
    "ubbont:showWeb": true,
    "dct:description": "BS-samlingen inneholder mange av fotografiene som var opprinnelsen til \n    Billedsamlingen. Flere av dem kom opprinnelig fra Bergens Museums \n    samlinger, andre ble samlet inn av samlingens tidligste ansatte og andre \n    med interesse for s&#230;rlig bergensk historie. BS-samlingen vokser stadig, og \n    det er her vi tar opp enkeltfotografier eller mindre samlinger av positive \n    og negative fotografier, postkort, lysbilder, trykk og album. Rundt 10.000 \n    av bildene er tilgjengelige digitalt. Samlingen er delt inn etter \n    st&#248;rrelsen p&#229; bildene: UBB-BS-OK- (oktav), UBB-BS-Q-(quart) og UBB-BS-FOL- \n    (foliant).",
    "dct:identifier": "ubb-bs-",
    "label": "BS-samlingen",
    "foaf:logo": "http://data.ub.uib.no/files/bs/ubb/ubb-bs/ubb-bs-q/ubb-bs-q-00348/jpg/ubb-bs-q-00348_th.jpg"
  },
  "dct:spatial": {
    "@id": "http://data.ub.uib.no/instance/spatialthing/de2f4ec3-3a77-4db7-8a8f-e53980f431d4",
    "@type": "geo:SpatialThing",
    "ubbont:catalogueStatus": "Må kontrolleres",
    "ubbont:previousIdentifier": "GL_Teller:1545",
    "dct:identifier": "de2f4ec3-3a77-4db7-8a8f-e53980f431d4",
    "http://www.geonames.org/ontology#parentADM1": "HORDALAND",
    "http://www.geonames.org/ontology#parentCountry": "Norge",
    "skos:prefLabel": "Jonas Lies vei 65"
  },
  "dct:subject": [
    {
      "@id": "http://data.ub.uib.no/topic/944a70d3-138d-4a22-ada1-5a3926f96525",
      "@type": "skos:Concept",
      "ubbont:previousIdentifier": "EM_Teller:952",
      "dct:available": {
        "@type": "http://www.w3.org/2001/XMLSchema#date",
        "@value": "2016-11-15"
      },
      "dct:identifier": "944a70d3-138d-4a22-ada1-5a3926f96525",
      "skos:prefLabel": "Byggeplass"
    },
    {
      "@id": "http://data.ub.uib.no/topic/dd509891-f2a4-4008-817b-2644bad3a8b4",
      "@type": "skos:Concept",
      "ubbont:previousIdentifier": "EM_Teller:248",
      "dct:available": {
        "@type": "http://www.w3.org/2001/XMLSchema#date",
        "@value": "2019-06-04"
      },
      "dct:identifier": "dd509891-f2a4-4008-817b-2644bad3a8b4",
      "skos:prefLabel": "Sykehus"
    },
    {
      "@id": "http://data.ub.uib.no/topic/1c7236ed-3479-40d4-82e2-bc5dbd9f5e26",
      "@type": "skos:Concept",
      "ubbont:previousIdentifier": "EM_Teller:953",
      "dct:available": {
        "@type": "http://www.w3.org/2001/XMLSchema#date",
        "@value": "2016-11-15"
      },
      "dct:identifier": "1c7236ed-3479-40d4-82e2-bc5dbd9f5e26",
      "skos:prefLabel": "Stillas"
    }
  ],
  "label": "[Byggingen av Haukeland Sykehus]",
  "bibo:owner": {
    "@id": "http://data.ub.uib.no/instance/organization/billedsamlingen",
    "@type": "foaf:Organization",
    "ubbont:showWeb": true,
    "dct:available": {
      "@type": "http://www.w3.org/2001/XMLSchema#date",
      "@value": "2016-05-04"
    },
    "dct:description": "Billedsamlingen inneholder historiske fotografier fra hele Norge med særlig vekt på Bergen og Vestlandet. Billedsamlingen holder til i Nygårdsgaten 5.",
    "dct:identifier": "billedsamlingen",
    "geo:lat": 60.38886,
    "geo:long": 5.32504,
    "foaf:homepage": "https://spesial.b.uib.no/?page_id=14",
    "foaf:name": "Billedsamlingen"
  },
  "foaf:maker": {
    "@id": "http://data.ub.uib.no/instance/agent/c38af810-17b1-4c08-bfe3-cb7951d039e0",
    "@type": "foaf:Agent",
    "dct:identifier": "c38af810-17b1-4c08-bfe3-cb7951d039e0",
    "foaf:name": "Ukjent"
  }
}

JSON-LD CONTEXT and frontend

const document = {
  "dct:title": "Title",
  title: "Title"
}

const label = document['dct:title']

// vs

const label = document.title

JSON-LD CONTEXT &

Json Schema

JSON

JSON-LD

json + @context

HTML Form

JSON Schema

validation

RDF/XML

jsonld.toRDF

Linked data crash course

By Tarje Lavik

Linked data crash course

  • 192