The SPARQL RDF Transformer
We provide here a collection of SPARQL transformers for covering common export needs.
Export a Selected Scheme from a Thesaurus
Realizing the export of a scheme might not be so straightforward: an RDF thesaurus could contain a lot of specific RDF constructs defined by the community (e.g. developed by means of Custom Forms) maintaining the thesaurus and not all of them might be local to scheme, so there is no way to make a general exporter that works for all thesauri. The following SPARQL code performs general operations that will probably satisfy the need of most thesauri, plus it can represent a starting point for developing a custom exporter for your own thesaurus.
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
DELETE {
?concept ?p ?o .
?label ?pLabel ?oLabel .
?scheme ?pScheme ?oScheme .
}
WHERE{
?concept a skos:Concept .
FILTER NOT EXISTS{
?concept skos:inScheme|skos:topConceptOf|^skos:hasTopConcept <TARGET_SCHEME> .
}
?concept ?p ?o .
OPTIONAL {
?concept ?p2 ?label .
?label a skosxl:Label .
?label ?pLabel ?oLabel .
}
?scheme a skos:ConceptScheme .
FILTER (?scheme != <TARGET_SCHEME>)
?scheme ?pScheme ?oScheme .
OPTIONAL{
?scheme ?p3 ?labelScheme .
?labelScheme a skosxl:Label .
?labelScheme ?pLabelScheme ?oLabelScheme .
}
}
So, this generic UPDATE removes from the export:
- all triples with the concepts not belonging to the target scheme as their subject
- In case of a SKOSXL lexicalization, removes all triples defining the reified labels for concepts not in the target scheme (usually two, plus all triples starting or ending in the URI of the reified label in case of lexical relationships)
A further possibility is to remove all triples with the skos:Concepts and skosxl:Labels not belonging to the selected scheme as their object. With the sparql update above, in case of two schemes A and B where A is the scheme to be exported, triples such as:
:CA skos:related CB
where CB belongs to scheme B, would not be removed (CB would be a “mention” in the resulting dataset).