RDF imports
RDF imports and transforming RDF using SPARQL CONSTRUCT
A data import is a combination of 3 resources:
- File
- An uploaded file holding the data to be converted to RDF and imported, such as CSV or RDF file
- Mapping
- The
CONSTRUCT
query that produces RDF - Target container
- The container to which converted items will be POSTed, skolemized against, and become its children
The import process runs in the background, i.e. the import item is created before the process completes. Currently the only way to determine when it completes is to refresh the import item and check the import status (completed/failed). Upon successful report, metadata such as the number of imported RDF triples is attached to the import.
The converted RDF is validated against constraints before import. Constraint violations, if any, are attached to the import item.
Import RDF
Lets assume we want to import SKOS concept data:
@prefix : <http://vocabularies.unesco.org/thesaurus/> . @prefix skos: <http://www.w3.org/2004/02/skos/core#> . @prefix dcterms: <http://purl.org/dc/terms/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . :concept10 a skos:Concept ; dcterms:modified "2006-05-23T00:00:00"^^xsd:dateTime ; skos:inScheme <http://vocabularies.unesco.org/thesaurus> ; skos:narrower :concept4938 , :concept7597 ; skos:prefLabel "Right to education"@en , "Droit à l'éducation"@fr , "Derecho a la educación"@es , "Право на образование"@ru ; skos:related :concept9 , :concept556 , :concept557 , :concept1519 , :concept5052 ; skos:topConceptOf <http://vocabularies.unesco.org/thesaurus> . :concept1000 a skos:Concept ; dcterms:modified "2006-05-23T00:00:00"^^xsd:dateTime ; skos:broader :concept389 ; skos:inScheme <http://vocabularies.unesco.org/thesaurus> ; skos:prefLabel "Talent"@en , "Talent"@fr , "Talento"@es , "Талант"@ru ; skos:related :concept993 , :concept996 , :concept3086 . :concept10003 a skos:Concept ; dcterms:modified "2006-05-23T00:00:00"^^xsd:dateTime ; skos:altLabel "Entrevue"@fr ; skos:broader :concept4725 ; skos:inScheme <http://vocabularies.unesco.org/thesaurus> ; skos:prefLabel "Interviews"@en , "Entretien"@fr , "Entrevista"@es , "Интервью"@ru .
Transformation
This step is used to transform the RDF data that is being imported, if necessary (to a different vocabulary, for example). It also connects instances in the imported data to the documents in LinkedDataHub's dataset.
The mapping is a user-defined SPARQL CONSTRUCT
. In this case we give each SKOS concept from the imported dataset an additional RDF
type and pair the concept with its item (document):
PREFIX dh: <https://www.w3.org/ns/ldt/document-hierarchy#>
PREFIX sioc: <http://rdfs.org/sioc/ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dct: <http://purl.org/dc/terms/>
CONSTRUCT
{
?thing ?p ?o ;
a ?type ;
?p ?o .
?item a dh:Item ;
sioc:has_container ?container ;
dh:slug ?id ;
dct:title ?prefLabel ;
foaf:primaryTopic ?thing .
}
WHERE
{
SELECT *
{
{
?thing a skos:Concept
BIND (skos:Concept AS ?type)
BIND (<concepts/> AS ?container)
}
UNION
{
?thing a skos:ConceptScheme
BIND (skos:ConceptScheme AS ?type)
BIND (<concept-schemes/> AS ?container)
}
BIND(struuid() AS ?id)
BIND(BNODE() AS ?item)
?thing ?p ?o
OPTIONAL
{
?thing skos:prefLabel ?prefLabel
FILTER (langMatches(lang(?prefLabel), "en"))
}
}
}
These are the rules that hold for mapping queries:
- the base URI of the query is the URI of the CSV file (does not need to be explicitly
specified as
BASE
) $base
binding value is set to the application's base URI- produce items (documents) and pair them with topic resources using the
foaf:primaryTopic
property - use
OPTIONAL
for optional cell values - use
BIND()
to introduce new values and/or cast literals to the appropriate result datatype or URI
Blank node resources in the output will be skolemized depending on their RDF types.
We are planning to provide a UI-based mapping tool in the future.
The result of our mapping using:
@prefix : <http://vocabularies.unesco.org/thesaurus/> . @prefix skos: <http://www.w3.org/2004/02/skos/core#> . @prefix dcterms: <http://purl.org/dc/terms/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix sioc: <http://rdfs.org/sioc/ns#> . @prefix dh: <https://www.w3.org/ns/ldt/document-hierarchy#> . :concept10 a skos:Concept ; dcterms:modified "2006-05-23T00:00:00"^^xsd:dateTime ; skos:inScheme <http://vocabularies.unesco.org/thesaurus> ; skos:narrower :concept4938 , :concept7597 ; skos:prefLabel "Right to education"@en , "Droit à l'éducation"@fr , "Derecho a la educación"@es , "Право на образование"@ru ; skos:related :concept9 , :concept556 , :concept557 , :concept1519 , :concept5052 ; skos:topConceptOf <http://vocabularies.unesco.org/thesaurus> . <concepts/c499e66a-8036-4637-929d-0d809177883e/> a dh:Item ; sioc:has_container <concepts/> ; dh:slug "c499e66a-8036-4637-929d-0d809177883e" ; dcterms:title "Right to education"@en ; foaf:primaryTopic :concept10 . :concept1000 a skos:Concept ; dcterms:modified "2006-05-23T00:00:00"^^xsd:dateTime ; skos:broader :concept389 ; skos:inScheme <http://vocabularies.unesco.org/thesaurus> ; skos:prefLabel "Talent"@en , "Talent"@fr , "Talento"@es , "Талант"@ru ; skos:related :concept993 , :concept996 , :concept3086 . <concepts/f41910fa-9077-4656-8f73-752fd923a79b/> a dh:Item ; sioc:has_container <concepts/> ; dh:slug "f41910fa-9077-4656-8f73-752fd923a79b" ; dcterms:title "Talent"@en ; foaf:primaryTopic :concept1000 . :concept10003 a skos:Concept ; dcterms:modified "2006-05-23T00:00:00"^^xsd:dateTime ; skos:altLabel "Entrevue"@fr ; skos:broader :concept4725 ; skos:inScheme <http://vocabularies.unesco.org/thesaurus> ; skos:prefLabel "Interviews"@en , "Entretien"@fr , "Entrevista"@es , "Интервью"@ru . <concepts/2afb2e06-5081-4db1-9255-660fcd1b3ec8/> a dh:Item ; sioc:has_container <concepts/> ; dh:slug "2afb2e06-5081-4db1-9255-660fcd1b3ec8" ; dcterms:title "Interviews"@en ; foaf:primaryTopic :concept10003 .
If you are ready to import some RDF, see our step-by-step tutorial on creating an RDF import.