52
WWW 2012 Tutorial Schema Mapping with SPARQL 1.1 Andreas Schultz (Freie Universität Berlin)

Data translation with SPARQL 1.1

Embed Size (px)

Citation preview

Page 1: Data translation with SPARQL 1.1

WWW 2012 Tutorial

Schema Mapping with SPARQL 1.1

Andreas Schultz(Freie Universität Berlin)

Page 2: Data translation with SPARQL 1.1

Outline

Why Do We Want to Integrate Data? Schema Mapping Translating RDF Data with SPARQL 1.1 Mapping Patterns

Page 3: Data translation with SPARQL 1.1

Motivation

Web of Data is heterogeneous Many different and overlapping ways to

represent information

Distribution of the most widely used vocabularies

Page 4: Data translation with SPARQL 1.1

Data is represented...

Using terms from a wide range of vocabularies Using diverging structures With values of different (data type) formats Fine grained vs. coarse grained Using different measuring units

Page 5: Data translation with SPARQL 1.1

Naming Differences

SELECT ?longTrack ?runtime{ { ?longTrack mo:duration ?time

} UNION {

?longTrack dbpedia-owl:runtime ?time

} FILTER (?track > 300)}

Page 6: Data translation with SPARQL 1.1

Structural Differences

dbpedia:Three_Little_Birds dbpedia-owl:musicalArtist dbpedia:Bob_Marley_&_The_Wailers .

dbpedia:Bob_Marley_&_The_Wailers foaf:made dbpedia:Three_Little_Birds .

Page 7: Data translation with SPARQL 1.1

Value Level Differences

“2012-04-15” vs. “2012-04-15”^^xsd:date “John Doe” vs. “John Doe”@en 20 in Celcius vs. 68 in Fahrenheit “Doe, John” vs. “John Doe”

Page 8: Data translation with SPARQL 1.1

Outline

Motivation Schema Mapping Translating RDF Data with SPARQL 1.1 Mapping Patterns

Page 9: Data translation with SPARQL 1.1

Schema Mapping

For data translation:

A mapping specifies how data under a source representation is translated to a target

representation, that is, the representation that you or your application expects.

Page 10: Data translation with SPARQL 1.1

Ways to Express Executable Mappings for RDF Data

Ontology constructs OWL, RDFS (rdfs:subClassOf, rdfs:subPropertyOf)

Rules SWRL RIF

Query Languages SPARQL 1.1

Page 11: Data translation with SPARQL 1.1

Outline

Motivation Schema Mapping Translating RDF Data with SPARQL 1.1 Mapping Patterns

Page 12: Data translation with SPARQL 1.1

Data Translation with SPARQL 1.1

Nearly W3C Recommendation status Many scalable SPARQL engine

implementations out there Data translation with SPARQL CONSTRUCT Huge improvements to version 1.0 regarding

data translation

Page 13: Data translation with SPARQL 1.1

How to Use SPARQL Construct Mappings Ideally

SELECT ?longTrack ?runtimeFROM { Construct { ?subj target:relevantProperty ?obj } WHERE { ?subj sour:relProperty ?obj } } WHERE { ?subj target:relevantProperty ?obj . …}

Page 14: Data translation with SPARQL 1.1

How to Use SPARQL Construct Mappings in Practice

SELECT ?longTrack ?runtimeFROM { Construct { ?subj target:relevantProperty ?obj } WHERE { ?subj sour:relProperty ?obj } } WHERE { ?subj target:relevantProperty ?obj . …}

Page 15: Data translation with SPARQL 1.1

Possibilities

Execute all SPARQL Construct queries on the source data set(s) to generate local versions of the target data set(s)

Optionally merge multiple target data sets into one

Reference these files in FROM clause Possibility we won't cover: Write the results

directly into a RDF store and query the store.

Page 16: Data translation with SPARQL 1.1

1. Transform Data Sets with ARQ

query –query=constructQuery.qry –data=sourceDataset.nt > targetDataset.ttl

# Execute more queries

Page 17: Data translation with SPARQL 1.1

2. Use Target Data Set Files in Query

SELECT ?longTrack ?runtimeFROM <targetDataset.ttl>FROM …WHERE { ?subj target:relevantProperty ?obj . …}

Page 18: Data translation with SPARQL 1.1

Outline

Motivation Schema Mapping Translating RDF Data with SPARQL 1.1 Mapping Patterns

Page 19: Data translation with SPARQL 1.1

Pattern based approach

Presentation of common mapping patterns Ordered from common to not so common Learn how to tackle these mapping patterns

with SPARQL 1.1

Page 20: Data translation with SPARQL 1.1

Simple Renaming Mapping Patterns

Page 21: Data translation with SPARQL 1.1

Rename Class / Property

Substitute the class or property URI

src:inst a mo:MusicArtist

src:inst a dbpedia-owl:MusicalArtist

Page 22: Data translation with SPARQL 1.1

Rename Class

SPARQL Mapping:

CONSTRUCT {

?s a mo:MusicArtist

} WHERE {

?s a dbpedia-owl:MusicalArtist

}

Page 23: Data translation with SPARQL 1.1

Rename Property

SPARQL Mapping:

CONSTRUCT {

?s rdfs:label ?o

} WHERE {

?s freebase:type.object.name ?o

}

Page 24: Data translation with SPARQL 1.1

Structural Mapping Patterns

Page 25: Data translation with SPARQL 1.1

Rename Class based on Property Existence

Rename class based on the existence of a property relation.

dbpedia:William_Shakespeare a fb:people.deceased_person .

dbpedia:William_Shakespeare a dbpedia-owl:Person ; dbpedia-owl:deathDate "1616-04-23"^^xsd:date .

Page 26: Data translation with SPARQL 1.1

Rename Class based on Property

SPARQL Mapping:

CONSTRUCT {

?s a freebase:people.deceased_person

} WHERE {

?s a dbpedia-owl:Person ; dbpedia-owl:deathDate ?dd .

}

Page 27: Data translation with SPARQL 1.1

Rename Class based on Value

Instances of the source class become instances of the target class if they have a specific property value.

gw-p:Kurt_Joachim_Lauk_euParliament_1840_P ; a fb:government.politician .

gw-p:Kurt_Joachim_Lauk_euParliament_1840_P a gw:Person ; gw:profession "politician"^^xsd:string .

Page 28: Data translation with SPARQL 1.1

Rename Class based on Value

SPARQL Mapping:

CONSTRUCT {

?s a fb:government.politician

} WHERE {

?s a gw:Person ; gw:profession "politician"^^xsd:string .

}

Page 29: Data translation with SPARQL 1.1

Reverse Property

The target property represents the reverse relationship regarding the source property.

dbpedia:Joey_Castillo mo:member_of dbpedia:Queens_of_the_Stone_Age .

dbpedia:Queens_of_the_Stone_Age dbpedia-owl:currentMemberdbpedia:Joey_Castillo .

Page 30: Data translation with SPARQL 1.1

Reverse Property

SPARQL Mapping:

CONSTRUCT {

?s mo:member_of ?o

} WHERE {

?o dbpedia-owl:currentMember ?s

}

Page 31: Data translation with SPARQL 1.1

Resourcesify

Represent an attribute by a newly created resource that then carries the attribute value.

dbpedia:The_Usual_Suspects po:version _:new ._:new po:duration 6360.0 .

dbpedia:The_Usual_Suspects dbpedia-owl:runtime 6360.0 .

Page 32: Data translation with SPARQL 1.1

Resourcesify

SPARQL Mapping:

CONSTRUCT {

?s po:version _:newversion . _:newversion po:runtime ?runtime .

} WHERE {

?s dbpedia-owl:runtime ?runtime .

}

Page 33: Data translation with SPARQL 1.1

Deresourcesify

Inverse pattern to the Resourcesify pattern.

dbpedia:John_F._Kennedy_International_Airport lgdp:owner "New York City" .

dbpedia:John_F._Kennedy_International_Airport dbpedia-owl:city dbpedia:New_York_City .dbpedia:New_York_City rdfs:label "New York City" .

Page 34: Data translation with SPARQL 1.1

Deresourcesify

SPARQL Mapping:

CONSTRUCT {

?s lgdp:owner ?cityLabel .

} WHERE {

?s dbpedia-owl:city ?city . ?city rdfs:label ?cityLabel .

}

Page 35: Data translation with SPARQL 1.1

Value Transformation based Mapping Patterns

Page 36: Data translation with SPARQL 1.1

SPARQL 1.1 functions

SPARQL 1.1 offers functions covering:

RDF terms (str, lang, IRI, STRDT etc.)

Strings (SUBSTR, UCASE etc.)

Numerics (abs, round etc.)

Dates and Times (now, year, month etc.)

Hash Functions (SHA1, MD5 etc.)

XPath Constructor Functions (xsd:float etc.)

Page 37: Data translation with SPARQL 1.1

Transform Value 1:1

Transform the (lexical) value of a property.

dbpedia:The_Shining_(film) movie:runtime 142 .

dbpedia:The_Shining_(film)dbpedia-owl:runtime 8520 .

Page 38: Data translation with SPARQL 1.1

Transform Value 1:1

SPARQL Mapping:

CONSTRUCT {

?s movie:runtime ?runtimeInMinutes .

} WHERE {

?s dbpedia-owl:runtime ?runtime . BIND(?runtime / 60 As ?runtimeInMinutes)

}

BIND( Expression As ?newVariable )

Page 39: Data translation with SPARQL 1.1

Transform Literal to URI

Transform a literal value into a URI.

dbpedia:Von_Willebrand_disease diseasome:omim <http://bio2rdf.org/omim:193400> .

dbpedia:Von_Willebrand_diseasedbpedia-owl:omim 193400 .

Also 1:1 transformation pattern!

Page 40: Data translation with SPARQL 1.1

Transform Literal to URI

SPARQL Mapping:

CONSTRUCT {

?s diseasome:omim ?omimuri .

} WHERE {

?s dbpedia-owl:omim ?omim . BIND(IRI(concat(“http://bio2rdf.org/omim:”, str(?omim))) As ?omimuri)

}

Page 41: Data translation with SPARQL 1.1

Construct Literals

SPARQL 1.1 offers several functions to construct literals:

STR – returns the lexical form → plain literal STRDT – construct data type literal STRLANG – construct literal with language tag

Page 42: Data translation with SPARQL 1.1

Cast to another Datatype

fb:en.clint_eastwood dbpedia-owl:birthDate “1930-05-31”^^xsd:date .

fb:en.clint_eastwoodfb:people.person.date_of_birth

“1930-05-31T00:00:00”^^xsd:dateTime .

Page 43: Data translation with SPARQL 1.1

Cast to another Datatype

SPARQL Mapping:

CONSTRUCT {

?s dbpedia-owl:birthDate ?date

} WHERE {

?s fb:people.person.date_of_birth ?dateTime . BIND(xsd:date(?dateTime) As ?date)

}

Page 44: Data translation with SPARQL 1.1

Transform Value N:1

dbpedia:William_Shakespeare foaf:name "Shakespeare, William" .

dbpedia:William_Shakespeare foaf:givenName "William" ; foaf:surname "Shakespeare" .

Transform multiple values from different properties to a single value.

Page 45: Data translation with SPARQL 1.1

Transform Value N:1

SPARQL Mapping:

CONSTRUCT {

?s foaf:name ?name

} WHERE {

?s foaf:givenName ?givenName ; foaf:surname ?surname . BIND(CONCAT(?surname, “, ”, ?givenName) As ?name)

}

Page 46: Data translation with SPARQL 1.1

Aggregation based Mapping Pattern

Page 47: Data translation with SPARQL 1.1

Aggregation

fb:en.berlin_u-bahndbpedia-owl:numberOfLines 2 .

fb:en.berlin_u-bahn fb:metropolitan_transit.transit_system.transit_lines fb:en.u1 ; fb:metropolitan_transit.transit_system.transit_lines fb:en.u3 .

Aggregate multiple values / occurrences into one value.

Page 48: Data translation with SPARQL 1.1

Aggregation

SPARQL Mapping:

CONSTRUCT {

?s dbpedia-owl:numberOfLines ?nrOfLines

} WHERE {

{ SELECT ?s (COUNT(?l) AS ?nrOfLines) { ?s fb:metropolitan_transit.transit_system.transit_lines ?l . } GROUP BY ?s }}

Page 49: Data translation with SPARQL 1.1

Data Cleaning

Page 50: Data translation with SPARQL 1.1

Data Cleaning

fb:en.jimi_hendrix dbpedia-owl:birthDate "1942-11-27"^^xsd:date

fb:en.jimi_hendrix fb:people.person.date_of_birth "1942-11-27" .

fb:en.josh_wink fb:people.person.date_of_birth "1970" .

Integrating data cleaning into a mapping.

Page 51: Data translation with SPARQL 1.1

Data Cleaning

SPARQL Mapping:

Construct {

?s dbpedia-owl:birthDate ?birthDate

} Where {

?s fb:people.person.date_of_birth ?bd . FILTER regex(?bd, “[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]”) BIND ((xsd:date(?bd)) As ?birthDate)

}

Page 52: Data translation with SPARQL 1.1

Questions?