smart data now.
Contesto e introChristian Morbidoni
giovedì 29 marzo 12
smart data now.Open Information vs Open Data
Data
Data
Data
2
giovedì 29 marzo 12
smart data now.Open Information vs Open Data
Data
Data
Data
2
giovedì 29 marzo 12
smart data now.Open Information vs Open Data
Data
Data
Data
2
giovedì 29 marzo 12
smart data now.Open Information vs Open Data
Data
Data
Data
2
giovedì 29 marzo 12
smart data now.Open Information vs Open Data
Data
Data
Data
2
giovedì 29 marzo 12
smart data now.Open Information vs Open Data
Data
Data
Data
2
giovedì 29 marzo 12
smart data now.Open Information vs Open Data
Data
Data
Data
2
giovedì 29 marzo 12
smart data now.
I dati hanno meno valorequando sono isolati
giovedì 29 marzo 12
smart data now.Web of Documents
For humans
For machines
Hyperlinks
X
4
giovedì 29 marzo 12
smart data now.Web of Data
For humans
For machines
Hyperlinks
RDF Data RDF Data RDF Data RDF Data
Semantic Linkscitesagrees
cites
same as explainslocated-insame-asauthor-ofrelated-to
works-for
5
giovedì 29 marzo 12
smart data now.Buzzword: Global Data Space
6
giovedì 29 marzo 12
smart data now.
Institutions
Buzzword: Global Data Space
6
giovedì 29 marzo 12
smart data now.
InstitutionsCompanies
Buzzword: Global Data Space
6
giovedì 29 marzo 12
smart data now.
InstitutionsCompanies
Geo-spatialservices
Buzzword: Global Data Space
6
giovedì 29 marzo 12
smart data now.
InstitutionsCompanies
Geo-spatialservices
Libraries
Buzzword: Global Data Space
6
giovedì 29 marzo 12
smart data now.
InstitutionsCompanies
Geo-spatialservices
Libraries
Citizens
Buzzword: Global Data Space
6
giovedì 29 marzo 12
smart data now.
InstitutionsCompanies
Geo-spatialservices
Libraries
Citizens
Buzzword: Global Data Space
6
giovedì 29 marzo 12
smart data now.
Pubblicare Linked Data sul WebChristian Morbidoni
giovedì 29 marzo 12
smart data now.Che cos’è Linked Data• Una serie di “best practices” per pubblicare dati
strutturati e interconnessi sul Web
• 4 Principi base:• Use URIs as names for things.
• Use HTTP URIs, so that people can look up those names.
• When someone looks up a URI, provide useful information, using the standards (RDF, SPARQL).
• Include links to other URIs, so that they can discover more things.
• L’idea è usare la stessa infrastruttura del Web (of documents) per costruire il Web of Data
8
giovedì 29 marzo 12
smart data now.Dereferenciable URLs• Best practice: evitare l’uso di URN e “non HTTP” URLs
• LD si basa su un unico protocollo (HTTP) per la risoluzione delle risorse
• I dati “parlano” di entità del mondo reale, non solo di risorse web• Information resource: un documento che “descrive” o “rappresenta” una
risorsa
• Non-information resource: una entità del mondo reale, non-digitale
• Esempio:• Mario Monti è una real-world resource (non-information resource)
• http://it.wikipedia.org/wiki/Mario_Monti è uno dei possibili documenti che descrivono la risorsa (information resource)
9
giovedì 29 marzo 12
smart data now.Dereferenciable URLs• Documenti e real-world resources devono avere URL diverse
• Non devono essere confuse tra loro
• Più rappresentazioni digitali della stessa real-world resources devono essere possibili• HTML per gli umani
• RDF per i software “semantici”
• Plain XML, JSON, TXT, etc. per i software “non semantici” ?
• Content negotiation• RFC 2616, http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html
• Meccanismo standard HTTP per fornire diverse rappresentazioni della stessa risorsa in risposta a diverse richieste
• Due strategie possibili (http://www.w3.org/TR/cooluris/)• 303 redirect
• Hash URLs
10
giovedì 29 marzo 12
smart data now.303 redirect + content negotiation
11
giovedì 29 marzo 12
smart data now.303 redirect + content negotiation
12
Client Server
GET /id/alice HTTP/1.1
Host: example.com
Accept: text/html;q=0.5, application/rdf+xml
HTTP/1.1 303 See Other
Location: http://example.com/data/alice
1 2
3
GET /data/alice HTTP/1.1
Host: example.com
Accept: text/html;q=0.5, application/rdf+xml
4
HTTP/1.1 200 OK
Content-Type: application/rdf+xml
<http://www.example.com/id/alice> a foaf:Person; foaf:name "Alice"; foaf:mbox <mailto:[email protected]>; ...
giovedì 29 marzo 12
smart data now.303 redirect to generic doc
13
giovedì 29 marzo 12
smart data now.303 redirect to generic doc
13
Variane da usare solo nel caso i due documenti siano equivalenti dal punto di vista del contenuto. (http://www.w3.org/TR/cooluris)Scarsa utilità pratica (?)
giovedì 29 marzo 12
smart data now.Alternative (?): “plain” content negotiation
• Blog post e discussione (2010): http://blog.iandavis.com/2010/11/07/a-guide-to-publishing-linked-data-without-redirects/
• Non possibile se le URI provengono da diversi host• 303 redirect è lo standard “de facto”, ma questo approccio è condiviso da molti• C’è una lunga discussione in corso su questo argomento...it’s up to you :-)
14
Client Server
GET /id/alice HTTP/1.1
Host: example.com
Accept: text/html;q=0.5, application/rdf+xml
1
2
HTTP/1.1 200 OK
Content-Location: http://example.com/data/alice
Content-Type: application/rdf+xml
<http://www.example.com/id/alice> a foaf:Person; foaf:name "Alice"; foaf:mbox <mailto:[email protected]>; ...
giovedì 29 marzo 12
smart data now.Hash URLs
• L’URL fragment (#...) è ignorato dal browser, che richiede l’intero documento
• La URL http://example.com/about#alice non è direttamente dereferenziabile e può essere utilizzata per indicare la non-information resource
15
giovedì 29 marzo 12
smart data now.Hash URLs
16
Client Server
GET /about HTTP/1.1
Host: example.com
Accept: text/html;q=0.5, application/rdf+xml
1
2
HTTP/1.1 200 OK
Content-Type: application/rdf+xml
<http://www.example.com/about#alice> a foaf:Person; foaf:name "Alice"; foaf:mbox <mailto:[email protected]>; ...<http://www.example.com/about#bob> a foaf:Person; foaf:name "Bob"; foaf:mbox <mailto:[email protected]>; ...
Client requests URL: http://example.com/about#alice
Client skips unwanted info...
giovedì 29 marzo 12
smart data now.Pros e Cons• Hash URL
• Contro: Richiede il dowload dell’intero documento (che potenzialmente descrive N risorse)
• Pro: Non richiede redirects
• 303 redirect• Contro: richiede più passaggi e una opportuna configurazione del web server
• Pro: E’ più flessibile. Permette di scaricare una descrizione alla volta, o più descrizioni assieme. Permette di cambiare la policy in seguito.
• Best practice:• 303 redirect per risorse in un (potenzialmente) largo dataset
• Hash URLs per i vocabolari/ontologie
• Se possibile mettere a disposizione anche uno SPARQL endpoint
• Soluzione ibrida ()• http://example.com/id/alice#this > Non-Information Resource
• http://example.com/id/alice > Information Resource
17
giovedì 29 marzo 12
smart data now.Links
…..<http://dati.piemonte.it/id/Torino> skos:exactMatch <http://dbpedia.org/resource/Turin> .…..<http://dati.piemonte.it/id/Torino> owl:sameAs <http://sws.geonames.org/3165524> .….<http://dati.piemonte.it/id/Mostra-123> dc:subject <http://rdf.freebase.com/ns/en.impressionism> .….<http://dati.piemonte.it/id/Torino> rdf:type <http://sw-portal.deri.org/ontologies/swportal#City> .….
http://dati.piemonte.it
http://freebase.com
http://geonames.org
http://dbpedia.org
http://sw-portal.deri.org
giovedì 29 marzo 12
smart data now.Links
…..<http://dati.piemonte.it/id/Torino> skos:exactMatch <http://dbpedia.org/resource/Turin> .…..<http://dati.piemonte.it/id/Torino> owl:sameAs <http://sws.geonames.org/3165524> .….<http://dati.piemonte.it/id/Mostra-123> dc:subject <http://rdf.freebase.com/ns/en.impressionism> .….<http://dati.piemonte.it/id/Torino> rdf:type <http://sw-portal.deri.org/ontologies/swportal#City> .….
http://dati.piemonte.it
http://freebase.com
http://geonames.org
http://dbpedia.org
http://sw-portal.deri.org
Identity Links
giovedì 29 marzo 12
smart data now.Links
…..<http://dati.piemonte.it/id/Torino> skos:exactMatch <http://dbpedia.org/resource/Turin> .…..<http://dati.piemonte.it/id/Torino> owl:sameAs <http://sws.geonames.org/3165524> .….<http://dati.piemonte.it/id/Mostra-123> dc:subject <http://rdf.freebase.com/ns/en.impressionism> .….<http://dati.piemonte.it/id/Torino> rdf:type <http://sw-portal.deri.org/ontologies/swportal#City> .….
http://dati.piemonte.it
http://freebase.com
http://geonames.org
http://dbpedia.org
http://sw-portal.deri.org
Identity Links
Relationship Links
giovedì 29 marzo 12
smart data now.Links
…..<http://dati.piemonte.it/id/Torino> skos:exactMatch <http://dbpedia.org/resource/Turin> .…..<http://dati.piemonte.it/id/Torino> owl:sameAs <http://sws.geonames.org/3165524> .….<http://dati.piemonte.it/id/Mostra-123> dc:subject <http://rdf.freebase.com/ns/en.impressionism> .….<http://dati.piemonte.it/id/Torino> rdf:type <http://sw-portal.deri.org/ontologies/swportal#City> .….
http://dati.piemonte.it
http://freebase.com
http://geonames.org
http://dbpedia.org
http://sw-portal.deri.org
Identity Links
Relationship Links
Vocabulary Links
giovedì 29 marzo 12
smart data now.Descrivere un dataset• Così come in RDF si descrivono le risorse (es. le città, le
persone), è importante anche descrivere i dataset stessi• Fornisce informazioni importanti agli utenti dei dati
• Consente ai motori di ricerca di indicizzare e scoprire più facilmente i dati
• Standard de facto• VoID (Vocabulary of Interlinked Datasets)
19
giovedì 29 marzo 12
smart data now.VoID: example
20
@prefix : <http://rdfs.org/ns/void#> . @prefix dcterms: <http://purl.org/dc/terms/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . <#DS1> a :Dataset; dcterms:description "Geonames dataset"; dcterms:title "Geonames"; :exampleResource <http://sws.geonames.org/3172483/about.rdf>; foaf:homepage <http://geonames.org> . <#myDS-DS1> a :Linkset; :linkPredicate <http://www.w3.org/2000/01/rdf-schema#seeAlso>; :target <#DS1>, <http://linkedopendata.it/datasets/grrp> . <http://linkedopendata.it/grrp> a :Dataset; dcterms:description "Accommodations in Piemonte. GoodRelations compliant."; dcterms:license <http://creativecommons.org/licenses/by/2.0/>; dcterms:publisher <http://linkedopendata.it>; dcterms:source <dati.piemonte.it>; dcterms:subject <http://dbpedia.org/resource/Piedmont>; dcterms:title "Strutture ricettive Piemonte - GoodRelations"; :dataDump <http://dump.linkedopendata.it/grrp>; :exampleResource <http://data.linkedopendata.it/grrp/resource/AFFITTACAMERE_ARCOBALENO_2>; :sparqlEndpoint <http://sparql.linkedopendata.it/grrp>; :subset <#myDS-DS1>; :vocabulary <http://purl.org/goodrelations/v1#>, <http://purl.org/net7/vocab/gracc/v1#>, <http://www.w3.org/2006/vcard/ns#>; foaf:homepage <http://linkedopendata.it/grrp> .
giovedì 29 marzo 12
smart data now.Discovery of VoID descriptions• Come rendere “trovabile” la descrizione VoID di un dataset?
• Back links• Consentono di risalire alla descrizione del dataset a partire dai dati stessi (descrizione RDF delle
risorse)
• es. <http://dbpedia.org/data/Berlin> dcterms:isPartOf :DBpedia .
• La tripla deve essere inclusa nella descrizione RDF di ogni risorsa del dataset
• Sitemap• Sitemap è il modo standard per esporre le risorse ai web crawler
• Semantic Sitemap è una estensione per descrivere dataset linked
• Esiste un overlap tra VoID e Semantic Sitemaps, ma possono essere usati efficacemente assieme
• Workflow:• Il client raggiunge il file robots.txt posizionato nella root (/) del dominio
• Il client cerca la riga che iniza per 'Sitemap :', che è seguita dalla URL del file sitemap.xml
• Se il file sitemap.xml sua l’estensione Semantic Sitemap, contiene l’elemento <sc:dataset> che a sua volta contiene l’elemento <sc:datasetURI> come figlio. il suo valore è l’URL del dataset
• L’URL del dataset viene dereferenziata ottendendo la descrizione VoID del datset
21
giovedì 29 marzo 12
smart data now.Semantic Sitemap: example
22
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:sc="http://sw.deri.org/2007/07/sitemapextension/scschema.xsd">
<sc:dataset> <sc:datasetLabel>Big Lynx People Data Set</sc:datasetLabel> <sc:datasetURI>http://biglynx.co.uk/datasets/people</sc:datasetURI> <sc:linkedDataPrefix>http://biglynx.co.uk/people/</sc:linkedDataPrefix> <sc:sampleURI>http://biglynx.co.uk/people/dave-smith</sc:sampleURI> <sc:sampleURI>http://biglynx.co.uk/people/matt-briggs</sc:sampleURI> <sc:sparqlEndpointLocation>http://biglynx.co.uk/sparql</sc:sparqlEndpointLocation> <sc:dataDumpLocation>http://biglynx.co.uk/dumps/people.rdf.gz</sc:dataDumpLocation> <changefreq>monthly</changefreq> </sc:dataset> </urlset>
giovedì 29 marzo 12
smart data now.License• Creative Commons definisce un vocabolario RDF per descrivere
le licenze
• E’ possibile specificare la licenza per ogni descrizione RDF aggiungendo una singola tripla• es. <http://example.org/id/alice> cc:license <http://creativecommons.org/
licenses/by-sa/3.0/> .23
ESEMPIO:<http://creativecommons.org/licenses/by-sa/3.0/> rdf:type cc:License ; dc:title "Attribution-Share Alike 3.0 Unported" ; dc:creator <http://creativecommons.org/> ; cc:permits cc:Distribution , cc:DerivativeWorks , cc:Reproduction ; cc:requires cc:ShareAlike , cc:Attribution , cc:Notice ;
giovedì 29 marzo 12
smart data now.Pattern architetturali
24
from: http://linkeddatabook.com/editions/1.0
Criteri: 1) Tipologia di dati di partenza 2)Mole di dati 3)Frequanza di update dei dati
giovedì 29 marzo 12
smart data now.File RDF statici• Best practice: usare Hash URLs
• File: http://example.org/porjects/myproject.rdf
• Entità progetto: http://example.org/porjects/myproject.rdf#project
• Configurare il web server per servire il giusto MIME type, application/rdf+xml
• Rendere l’RDF facilmente trovabile includendo un link nella pagina HTML corrispondente• <link rel="alternate" type="application/rdf+xml" href="project.rdf">
• Alternativa: includere RDFa nelle pagine HTML25
giovedì 29 marzo 12
smart data now.Servire LD da un DB relazionale
• Esistono tool ad-hoc per questo compito• D2RQ è uno dei più usati
26
giovedì 29 marzo 12
smart data now.Servire LD da un triplestore• Non tutti i triple store hanno supporto buil-in per Linked Data
• In questi casi occorre usare un layer aggiuntivo
• Tool più utilizzati:• Pubby, http://www4.wiwiss.fu-berlin.de/pubby/
• Linked Data API (http://code.google.com/p/linked-data-api/wiki/Specification) implementation• ELDA, http://elda.googlecode.com/hg/deliver-elda/src/main/docs/index.html
• PUELIA, http://code.google.com/p/puelia-php/
27
giovedì 29 marzo 12
smart data now.
Resource Description Framework
(e database relazionali)Christian Morbidoni
giovedì 29 marzo 12
smart data now.Dati distribuiti• Il primo requirement di RDF è quello di supportare la descrizione di dati distribuiti sul
Web
• Supponendo di voler rappresentare i seguenti dati in forma tabulare...Come distribuirli sul Web?
29
ID Title Author Medium Year
1 As you like it Shakespeare Play 1599
2 Hamlet Shakespeare Play 1604
3 Othello Shakespeare Play 1603
4 Sonnet 18 Shakespeare Poem 1609
5 Astrophil and Stella Sir Phillip Sidney Poem 1590
6 Edward II Christopher Marlowe Play 1592
7 Hero and Leander Christopher Marlowe Poem 1593
8 Greensleeves Henry VII Rex Song 1525
giovedì 29 marzo 12
smart data now.Dati distribuiti• Un primo approccio potrebbe essere distribuire i dati riga per riga
• Ogni serve mantiene un certo numero di risorse• Flessibilità: facile inserire una nuova risorsa
• Rigidità: aggiungere un campo alla tabella richiede coordinazione tra tutti i server
• I server devono essere coordinati in modo che i campi corrispondano
• Requirement: serve un identificatore globale per ogni campo30
ID Title Author Medium Year1 As you like it Shakespeare Play 1599
server 1ID Title Author Medium Year2 Hamlet Shakespeare Play 16043 Othello Shakespeare Play 1603
server 2
ID Title Author Medium Year6 Edward II Christopher Marlowe Play 15927 Hero and Leander Christopher Marlowe Poem 1593
server 3
giovedì 29 marzo 12
smart data now.Dati distribuiti• Un secondo approccio: colonna per colonna
• Ogni server è responsabile per un “tipo” di dati• Flessibilità: è facile estendere il modello del DB (aggiungere campi)
• Rigidità: inserire una nuova risorsa richiede la collaborazione di tutti i server
• Requirement: serve un identificatore globale per ogni risorsa
31
TitleAs you like itHamletOthelloSonnet 18Astrophil and StellaEdward IIHero and LeanderGreensleeves
AuthorShakespeareShakespeareShakespeareShakespeareSir Phillip SidneyChristopher MarloweChristopher MarloweHenry VII Rex
Medium YearPlay 1599Play 1604Play 1603Poem 1609Poem 1590Play 1592Poem 1593Song 1525
server 1
server 2
server 3
giovedì 29 marzo 12
smart data now.Dati distribuiti• Una combinazione dei due: cella per cella
• Pro: Combina la flessibilità dei due approcci • ogni server può liberamente aggiungere risorse, campi e relativi valori
• Requirement: • Servono identificatori globali sia per le risorse che per i “campi”
• RDF si basa su questo approccio
32
Title
1 As you like it
Medium
4 Poem
Author
2 Shakespeare
Year
2 1604
Title
3 Othello
server 2
server 3server 1
giovedì 29 marzo 12
smart data now.Triple• In questo modello l’unità atomica di dati è formata da tre valori:
• identificatore della riga
• nome del campo
• valore corrispondente.
• In RDF si chiama Tripla o Statement, ed è composto a:• Soggetto - una risorsa
• Predicato - un tipo di relazione o proprietà
• Oggetto - un valore o una risorsa
33
giovedì 29 marzo 12
smart data now.Triple e tabelle• Dati tabellari:
• Una tripla può essere vista come una tabella con tre campi.
• oppure:
ID Title Author Medium Year1 As you like it Shakespeare Play 15992 Hamlet Shakespeare Play 1604
Subject Predicate Object1 has title “As you like it”1 has author Shakespere2 has medium Play2 has author Shakespere
Subject Predicate ObjectShakespere wrote As you like itAs you like it has medium PlayShakespere wrote HamletAmlet year 1604
34
giovedì 29 marzo 12
smart data now.Triple e grafi• Un tripla può essere rappresentata anche così:
• Quando più triple si riferiscono alla stessa risorsa possono essere visualizzate come un grafo etichettato e direzionato (directed labeled graph):
HamletShakespere wrote
Hamlet
Shakesperewrote
1604year
As you like itwrote
Playhas medium
35
giovedì 29 marzo 12
smart data now.Graph merging• Ogni pezzo di informazione sul Semantic Web è un grafo
• Unire e aggregare informazioni è semplice ....
36
Hamlet
Shakesperewrote
1604year
wroteMacbeth set in Scotland
UK
part of
Shakespere Stratford itlived inEnglandis in
UK
part of
Playhas mediumMacbeth
wrote
giovedì 29 marzo 12
smart data now.Graph merging• Unico requisito: un modo inequivocabile per stabilire quando due
nodi in grafi diversi sono equivalenti
37
Hamlet
Shakesperewrote
1604year
wrote
Stratford it
lived in
England
is in part of
Macbeth set in Scotland
UK
part of
Play
has medium
giovedì 29 marzo 12
smart data now.URI come identificatori globali
• Un generalizzazione dell’approccio già usato sul Web• Le URL sono tipi particolari di URI
• Due risorse sono uguali se hanno la stessa URI
• Un Uniform Resource Identifier identifica una risorsa che può far parte di un grafo RDF• Non-unique Name Assumption: non è Unique è Uniform!
• Una risorsa può avere più URI
38
giovedì 29 marzo 12
smart data now.URI: sintassi• Sintassi dipendente dallo schema
<scheme>:<scheme-specific-part>
• Sintassi generica (usata da diversi schemi ma non obbligatoria)
<scheme>://<authority><path>?<query>
• Schema (obbligatorio)• Determina la “semantica” dell’URI
• Può indicare un meccanismo di risoluzione (http, ftp, etc.)
• Authority• Indica una autorità per il naming (es. web domain)
• Path• Identifica la risorsa all’interno dell’authority (es. a/b/c)
• Query• Stringa interpretabile dalla risorsa stessa (es. ?user=christian)
39
giovedì 29 marzo 12
smart data now.URL e URN• Tipi di URI:
• Uniform Resource Locators (URLs)
• Specificano un protocollo per risolvere la risorsa
• Uniform Resource Names (URNs)
• Sono dei nomi ma non hanno una rappresentazione digitale vera e propria
• URL e risorse:• Una pagina Web: http://myHomePage.it/me.htm (URL)
• Un libro: urn:isbn:1234-123443-1234343 (URN)
• Un oggetto digitale: urn:doi:10.1000/182 (URN)
• Una persona: mailto:[email protected] (URL)
• Generalizzazione: Internationalized Resource Identifier (IRI) Wikipedia: “is a generalization of the Uniform Resource Identifier (URI), which is in turn a generalization of the Uniform Resource Locator (URL). While URIs are limited to a subset of the ASCII character set, IRIs may contain characters from the Universal Character Set (Unicode/ISO 10646), including Chinese or Japanese kanji, Korean, Cyrillic characters, and so forth.”
40
giovedì 29 marzo 12
smart data now.Esempio di N-Triples<http://www.artchive.com/crucifixion.jpg>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.icom.com/schema.rdf#Sculpture> .
<http://www.ibiblio.org/wm/paint/auth/pippo/>
<http://www.icom.com/schema.rdf#first_name> "Pippo"@en .
<http://www.ibiblio.org/wm/paint/auth/pippo/>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.icom.com/schema.rdf#Sculptor> .
<http://www.ibiblio.org/wm/paint/auth/rodin/>
<http://www.icom.com/schema.rdf#creates>
<http://www.artchive.com/crucifixion.jpg> .
41
giovedì 29 marzo 12
smart data now.Turtle (superset di N-Triples)# See slides for RDF talk
#
# http://www.w3.org/2000/Talks/0906-xmlweb-tbl/slide6-0.html
#
@prefix p: <http://www.example.org/personal_details#> .
@prefix m: <http://www.example.org/meeting_organization#> .
<http://www.example.org/people#fred>
! p:GivenName ! "Fred";
! p:hasEmail ! ! <mailto:[email protected]>;
! m:attending !! <http://meetings.example.com/cal#m1> .
<http://meetings.example.com/cal#m1>
! m:homePage ! ! <http://meetings.example.com/m1/hp> .
42
giovedì 29 marzo 12
smart data now.Stesso esempio in RDF/XML
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:m="http://www.example.org/meeting_organization#"
xmlns="http://www.example.org/people#"
xmlns:p="http://www.example.org/personal_details#">
<rdf:Description about="http://meetings.example.com/cal#m1">
<m:homePage resource="http://meetings.example.com/m1/hp"/>
</rdf:Description>
<rdf:Description about="http://www.example.org/people#fred">
<m:attending resource="http://meetings.example.com/cal#m1"/>
<p:GivenName>Fred</p:GivenName>
<p:hasEmail resource="mailto:[email protected]"/>
</rdf:Description>
</rdf:RDF>43
giovedì 29 marzo 12
smart data now.RDF/JSON{ "http://example.org/about" : { "http://purl.org/dc/elements/1.1/creator" :
[ { "value" : "Anna Wilder", "type" : "literal" } ], "http://purl.org/dc/elements/1.1/title" :
[ { "value" : "Anna's Homepage", "type" : "literal", "lang" : "en" } ] , "http://xmlns.com/foaf/0.1/maker" :
[ { "value" : "_:person", "type" : "bnode" } ] } , "_:person" : { "http://xmlns.com/foaf/0.1/homepage" :
[ { "value" : "http://example.org/about", "type" : "uri" } ] , "http://xmlns.com/foaf/0.1/made" :
[ { "value" : "http://example.org/about", "type" : "uri" } ] , "http://xmlns.com/foaf/0.1/name" :
[ { "value" : "Anna Wilder", "type" : "literal" } ] , "http://xmlns.com/foaf/0.1/firstName" :
[ { "value" : "Anna", "type" : "literal" } ] , "http://xmlns.com/foaf/0.1/surname" :
[ { "value" : "Wilder", "type" : "literal" } ] , "http://xmlns.com/foaf/0.1/depiction" :
[ { "value" : "http://example.org/pic.jpg", "type" : "uri" } ] , "http://xmlns.com/foaf/0.1/nick" : [ { "type" : "literal", "value" : "wildling"} , { "type" : "literal", "value" : "wilda" } ] , "http://xmlns.com/foaf/0.1/mbox_sha1sum" :
[ { "value" : "69e31bbcf58d432950127593e292a55975bc66fd", "type" : "literal" } ] }}
44
giovedì 29 marzo 12
smart data now.RDFa: embedding RDF into web pages
45
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="XHTML+RDFa 1.0" xml:lang="en"> <head> <title>John's Home Page</title> <base href="http://example.org/john-d/" /> <meta property="dc:creator" content="Jonathan Doe" /> <link rel="foaf:primaryTopic" href="http://example.org/john-d/#me" /> </head> <body about="http://example.org/john-d/#me"> <h1>John's Home Page</h1> <p>My name is <span property="foaf:nick">John D</span> and I like <a href="http://www.neubauten.org/" rel="foaf:interest" xml:lang="de">Einstürzende Neubauten</a>. </p> <p> My <span rel="foaf:interest" resource="urn:ISBN:0752820907">favorite book is the inspiring <span about="urn:ISBN:0752820907"><cite property="dc:title">Weaving the Web</cite> by <span property="dc:creator">Tim Berners-Lee</span></span> </span> </p> </body></html>
giovedì 29 marzo 12
smart data now.Named Graphs• L’idea alla base delle specifiche (http://www.w3.org/1999/02/22-
rdf-syntax-ns#) è semplice:• Un set di triple RDF è un grafo
• Ogni grafo è identificato esso stesso da una URI
• Ampio supporto in SPARQL e nei triple-store
• Da triple a quadruple (quad-store)• Soggetto - Predicato - Oggetto - Provenienza
46
giovedì 29 marzo 12
smart data now.TriG• Specifiche: http://www4.wiwiss.fu-berlin.de/bizer/TriG/#example
• Esempio:
47
# TriG Example Document 1# This document encodes three graphs.@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .@prefix swp: <http://www.w3.org/2004/03/trix/swp-1/> .@prefix dc: <http://purl.org/dc/elements/1.1/> .@prefix ex: <http://www.example.org/vocabulary#> .@prefix : <http://www.example.org/exampleDocument#> .:G1 { :Monica ex:name "Monica Murphy" . :Monica ex:homepage <http://www.monicamurphy.org> . :Monica ex:email <mailto:[email protected]> . :Monica ex:hasSkill ex:Management }
:G2 { :Monica rdf:type ex:Person . :Monica ex:hasSkill ex:Programming }
:G3 { :G1 swp:assertedBy _:w1 . _:w1 swp:authority :Chris . _:w1 dc:date "2003-10-02"^^xsd:date . :G2 swp:quotedBy _:w2 . :G3 swp:assertedBy _:w2 . _:w2 dc:date "2003-09-03"^^xsd:date . _:w2 swp:authority :Chris . :Chris rdf:type ex:Person . :Chris ex:email <mailto:[email protected]> }
giovedì 29 marzo 12
smart data now.RDF and tabular data: assignment
• Assignment: esprimere i dati in forma di RDF• Osservazioni:
• Ogni riga identifica una risorsa diversa: servono identificatori per le risorse
• Ogni colonna esprime una proprietà di una risorsa: servono identificatori per le proprietà
• Il nome della tabella esprime una categoria di oggetti: i prodotti
• Namespace: possiamo scegliere un namespace unico per il DB: http://manufactoringX.com/products/ (prefisso mfx:)
• Consiglio: usare la sintassi N3
ID Model Division Product Line Manufacture Location Available
1 zx-3 Manufactoring support Paper machine Sacramento 23
2 zx-3P Manufactoring support Paper machine Sacramento 4
3 B-1430 Control Engineering Active sensor Hong Kong 100
4 DBB-12 Safety Safety Valve Cleveland 34
Products
48
giovedì 29 marzo 12
smart data now.RDB to RDF mapping • Specifiche W3C:
• Direct Mapping: http://www.w3.org/TR/rdb-direct-mapping/• Definisce un metodo “standard” per mappare tabelle relazionali in triple RDF
• La struttura dell’RDF riflette esattamente quella del DB
• Il vocabolario RDF riflette esattamente le tabelle del DB
• Mapping language: R2RML: http://www.w3.org/TR/r2rml/
• Un linguaggio per specificare un mapping “custom” da un particolare DB• Consente di scegliere un vocabolario RDF qualsiasi
• Produce un RDF più “usabile”
• Tools:• D2RQ, http://d2rq.org/ - open-source
• Triplify, http://triplify.org - open-source
• Virtuoso, http://virtuoso.openlinksw.com/ - open-source + commercial
• .....
49
giovedì 29 marzo 12
smart data now.Direct Mapping: example
50
giovedì 29 marzo 12
smart data now.R2RML: example
51
giovedì 29 marzo 12
smart data now.R2RML: example
?
51
giovedì 29 marzo 12
smart data now.R2RML: example
52
giovedì 29 marzo 12
smart data now.D2RQ everviewArchitecture
53
giovedì 29 marzo 12
smart data now.D2RQ: example mapping
54
giovedì 29 marzo 12
smart data now.RDFS Vocabulary
56
giovedì 29 marzo 12
smart data now.RDF, RDFS, Vocabulary
57
giovedì 29 marzo 12
smart data now.RDFS Entailments
58
giovedì 29 marzo 12
smart data now.Inference and data integration• L’inferenza gioca un ruolo importante nell’integrazione tra grafi
• In alcuni casi le URI non bastano...
• Esempio: come unire in modo consistente i seguenti grafi?
59
ex2:Motorcicleex1:Car
ex1:FiatPunto
rdf:type
ex1:FiatBravo
rdf:type
ex1:Fiat500
rdf:type
ex2:RXex2:Shadow
ex2:Monster
rdf:type
rdf:type
rdf:type
Graph 1 Graph 2
giovedì 29 marzo 12
smart data now.Inference and data integration• Utilizzando semplicemente rdfs:subClassOf possiamo creare un
modello di integrazione
60
ex2:Motorcicleex1:Car
ex1:FiatPunto
rdf:type
ex1:FiatBravo
rdf:type
ex1:Fiat500
rdf:type
ex2:RXex2:Shadow
ex2:Monster
rdf:type
rdf:type
rdf:type
Graph 1 Graph 2
myns:Veicle
rdfs:SubClassOf rdfs:SubClassOf
Integration model
giovedì 29 marzo 12
smart data now.Inference and data integration• Il modello integrato presenta gli individui in modo omogeneo:
• L’inferenza può sembrare molto banale ...
• .. ma spesso semplici connessioni logiche sono in grado di rendere le applicazioni sensibilmente più smart• “A little semantics goes a long way” :-)
61
ex1:FiatPunto
ex1:FiatBravo
ex1:Fiat500 ex2:RX
ex2:Shadow
ex2:Monster
myns:Veicle
rdf:type
Integrated model
rdf:type
rdf:type
rdf:type rdf:type
rdf:type
giovedì 29 marzo 12
smart data now.Type propagation (rdfs:subClassOf)
• Se RDF modella triple e grafi ...
• RDF Schema modella insiemi (sets)• Un insieme è definito come una risorsa di tipo rdfs:Class
• Il costrutto per indicare un sotto-set è rdfs:subClassOf• E’ anche il più abusato (come extends in Java :-) )
• Pattern: type propagation
62
:AllStartPlayer rdf:type rdfs:Class:MajorLeaguePlayer rdf:type rdfs:Class
:AllStartPlayer rdfs:subClassOf :MajorLeaguePlayer
:Keneda rdf:type :AllStartPlayer .
INFERRED TRIPLES:
:Keneda rdf:type :MajorLeaguePlayer
giovedì 29 marzo 12
smart data now.Relationship propagation (rdfs:subPropertyOf)• In alcuni casi è utili parlare non solo delle classi (insiemi di istanze) ma anche
delle proprietà (relazioni) che intercorrono tra le risorse
• rdfs:subPropertyOf• funzionamento analogo
a rdfs:subClassOf
• IF ?p rdfs:subPropertyOf ?qAND ?x ?p ?yTHEN ?x ?q ?y
• Nota: Non ha un analogo nei lingugaggi di programmazione
63
:freeLancesTo rdfs:subPropertyOf :contractsTo .:indirectlyContractsTo rdfs:subPropertyOf :contractsTo .:isEmployedBy rdfs:subPropertyOf :worksFor .:contractsTo rdfs:subPropertyOf :worksFor .
:Goldman :isEmployedBy :TheFirm .:Spence :freeLancesTo :TheFirm .:Long :indirectlyContractsTo :TheFirm .
INFERRED TRIPLES:
:Goldman :worksFor :theFirm:Spencer :contractsTo :theFirm:Long :contractsTo :theFirm
SECOND STEP:
:Spence :worksFor :theFirm:Long :worksFor :theFirm
giovedì 29 marzo 12
smart data now.rdfs:domain e rdfs:range• Un altro modo di parlare di una proprietà è quello di indicare come essa dovrebbe
essere usata nel contesto• Ovvero: quali tipi di risorse unisce
• I concetti di dominio (domain) e codominio (range) vengono presi dalla matematica
• Regole di inferenza:• IF ?p rdfs:range ?a
AND ?x ?p ?yTHEN ?y rdf:type ?a
• IF ?p rdfs:domain ?aAND ?x ?p ?yTHEN ?x rdf:type ?a
• Nota: doamin e range non possono generare dati invalidi o inconsistenze
• L’approccio è quello di rendere sempre consistente il grafo applicando le regole di inferenza
64
:contractsTo a owl:ObjectProperty ; rdfs:domain :Person ;:Spencer :contractsTo :theFirm
INFERRED TRIPLE::Spencer rdf:type Person
giovedì 29 marzo 12
smart data now.Patternrdfs:domain, rdfs:range + rdfs:subClassOf
• I pratica possiamo definire un’altra regola di inferenza:• IF ?p rdfs:domain ?a
AND ?a rdfs:subClassOf ?bTHEN ?p rdfs:domain ?b
• L’inferenza agisce in modo “inaspettato”: dal semplice uso di una proprietà posso dedurre la sua appartenenza a una gerarchia di classi ...
65
:developed :Developer
:ITEmployee
rdfs:subClassOf
rdfs:domain
:Daniel :developed :Talia
Inferred triples:
:Daniel rdf:type :Developer:Daniel rdf:type :ITEmployee
giovedì 29 marzo 12
smart data now.domain e range: errori comuni• L’utilizzo e il significato di rdfs:domain e rdfs:range in RDFS crea
spesso confusione• Soprattutto a chi è abituato a pensare “Object Oriented”
(e chi non lo è ?!)
• Una comune associazione tra OOP e RDFS:• rdfs:Class >> OOP Class
• rdfs:domain A >> dichiarazione di una variabile nella classe A
• Visione rafforzata da alcuni tool per la visualizzazione di RDF (es. Protege)
• Ma non è proprio così ....
66
giovedì 29 marzo 12
smart data now.OOP vs. Semantic Web
• In OOP l’inheritance consente alle sottoclassi di ereditarele variabili
• ! In RDFS le super-classi ricevono associazioni con le risorse dalle sottoclassi !
67
:foo :ClassB
:ClassA
rdfs:subClassOf
rdfs:domain
Class A
public static Object Foo;
Class B extends A
Foo;
rdfs:domain:foo
OOP Semantic Web
giovedì 29 marzo 12
smart data now.Consistency check?• ! In RDFS non esiste il concetto di consistency/validity check !
• AAA• Anybody can say Anything about Anything
• Open World Assumption• Non posso dedurre nuova conoscenza dalla mancanza di informazioni
• Es. se in un dataset RDF non esiste la tripla “:Pluto rdf:type :Dog”• Non posso dedurre NOT(:Pluto rdf:type :Dog)
68
giovedì 29 marzo 12
smart data now.Consistency check?
69
:Christian rdf:type :Person .:hasPrice rdfs:domain :Product .:Christian :hasPrice “49.99 €” .
giovedì 29 marzo 12
smart data now.Consistency check?
69
:Christian rdf:type :Person .:hasPrice rdfs:domain :Product .:Christian :hasPrice “49.99 €” .
! I dati sono validi per un reasoner RDFS !
giovedì 29 marzo 12
smart data now.Consistency check?
69
:Christian rdf:type :Person .:hasPrice rdfs:domain :Product .:Christian :hasPrice “49.99 €” .
! I dati sono validi per un reasoner RDFS !
:Christian rdf:type :Product .
! Un reasoner deduce ...
giovedì 29 marzo 12
smart data now.
Interrogare dati RDF: SPARQLChristian Morbidoni
giovedì 29 marzo 12
smart data now.Querying RDF• SPARQL
• Specifiche: http://www.w3.org/TR/rdf-sparql-query/
• RDF Query language standard W3C
• Basato sul predecessore RDQL
• Tutorial: http://www.cambridgesemantics.com/2008/09/sparql-by-example
• SQL-like syntaxEsempio:! PREFIX dc: <http://purl.org/dc/elements/1.1/>
! ! SELECT ?title
! ! WHERE
! ! ! { <http://example.org/book/book1> dc:title ?title }
• SeRQL• Precedente RDF Query Language sviluppato da Aduna (Sesame)
• Funzionalità equiparabili a SPARQL71
giovedì 29 marzo 12
smart data now.SPARQL tutorial
• Alcuni esempi di query nelle seguenti slides....
• Tuttavia esiste un ottimo tutorial online a cui fare riferimento:• http://www.cambridgesemantics.com/2008/09/sparql-by-example/
72
giovedì 29 marzo 12
smart data now.SPARQL• PREFIX
• Dichiarazione dei namespace
• SELECT• Identifica le variabile di ritorno della query
• FROM• Il nome del grafo su cui eseguire la query
• SPARQL supporta i Named Graphs
• WHERE • “Query Pattern”
73
giovedì 29 marzo 12
smart data now.RDF example
74
giovedì 29 marzo 12
smart data now.SPARQL query example (1)
75
giovedì 29 marzo 12
smart data now.SPARQL query example (2)
76
giovedì 29 marzo 12
smart data now.SPARQL query example (3)
77
giovedì 29 marzo 12
smart data now.SPARQL query example (4)
78
giovedì 29 marzo 12
smart data now.SPARQL query example (5)
79
giovedì 29 marzo 12
smart data now.SPARQL query example (6)
80
giovedì 29 marzo 12
smart data now.Biblio e Links• RDF Primer, http://www.w3.org/TR/rdf-primer/
• RDFa Primer, http://www.w3.org/TR/xhtml-rdfa-primer/
• RDF/JSON specification, http://docs.api.talis.com/platform-api/output-types/rdf-json
• Tom Heath, Christian Bizer, Linked Data: Evolving the Web into a Global Data Space, http://linkeddatabook.com
• Tim Berners Lee, Linked Data design issues, http://www.w3.org/DesignIssues/LinkedData.html
• Dereferencing HTTP URIs, http://www.w3.org/2001/tag/doc/httpRange-14/2007-05-31/HttpRange-14
• Leo Sauermann and Richard Cyganiak. Cool uris for the semantic web, http://www.w3.org/TR/cooluris/
• Dean Allemang, Jim Handler, Semantic Web for the Working Ontologiest, http://workingontologist.org/
• A Direct Mapping of Relational Data to RDF, http://www.w3.org/TR/rdb-direct-mapping/
• R2RML: RDB to RDF Mapping Language, http://www.w3.org/TR/r2rml/
• D2RQ, http://d2rq.org/
• A Comparison of RDB-to-RDF Mapping Languages, http://www.ifi.uzh.ch/pax/uploads/pdf/publication/1830/paper.pdf
• SPARQL 1.0, http://www.w3.org/TR/rdf-sparql-query/
• SPARQL 1.1, http://www.w3.org/TR/sparql11-query/
• SPARQL by examples (Tutorial), http://www.cambridgesemantics.com/2008/09/sparql-by-example
• RFC 2616, http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html
• Harry Halpin, Patrick J. Haye, When owl:sameAs isn’t the Same: An Analysis of Identity Links on the Semantic Web, http://events.linkeddata.org/ldow2010/papers/ldow2010_paper09.pdf
• HTML/ChangeProposal25, http://www.w3.org/wiki/HTML/ChangeProposal25
• Semantic Sitemap specs, http://sw.deri.org/2007/07/sitemapextension/
• Guide to VoID (Vocabulary of Interlinked Datasets), http://vocab.deri.ie/void/guide
81
giovedì 29 marzo 12
Top Related