Caliper - Statistical Classifications in a Linked Open World

Here a few sample queries for you to reuse!

A query is a question written in a computer language for databases. The query language to query the Caliper repository is SPARQL, specific for RDF repositories (triple stores).

We have prepared some queries for you to reuse.

Note that some queries contain placeholders (such as "<[scheme_uri]>"), to make it easier for you to reuse it. Before using the query, the placeholder needs to be replaced as appropriate. For example, to retrieve a classification's URI (i.e., the value of placeholder "<[scheme_uri]>") use the query provided below, titled: "Get all classification's URIs in Caliper". 

General queries on the entire Caliper

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT  ?scheme ?notation ?label_en WHERE {
   ?scheme rdf:type skos:ConceptScheme .
   ?scheme skos:notation ?notation .
  ?scheme skos:prefLabel ?label_en . FILTER(lang(?label_en)='en') .
  }
ORDER BY ASC(?notation)

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>

SELECT DISTINCT ?acronym ?label_en ?label_fr ?label_es ?label_ru ?descr
WHERE {
  ?scheme rdf:type skos:ConceptScheme . FILTER(""" + exclusion + """) .
  ?scheme skos:notation ?acronym .
  ?scheme skos:prefLabel ?label_en . FILTER (lang(?label_en)= "en" || lang(?label_en)= "") .
  OPTIONAL{?scheme dc:description|dct:description|rdfs:comment ?descr . FILTER (lang(?descr)= "en" || lang(?descr)= "") } .
  OPTIONAL{?scheme skos:prefLabel ?label_fr . FILTER (lang(?label_fr)= "fr")} .
  OPTIONAL{?scheme skos:prefLabel ?label_es . FILTER (lang(?label_es)= "es")} .
  OPTIONAL{?scheme skos:prefLabel ?label_ru . FILTER (lang(?label_ru)= "ru")} .
}
ORDER BY ?acronym

Queries on classifications

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT  DISTINCT ?code (MAX(?broaderCodes) as ?broader)  ?label_en ?label_fr ?label_es ?label_ru ?alternative_label ?definition ?note WHERE {
  ?concept rdf:type skos:Concept . 
  ?concept skos:inScheme ?concept_scheme . FILTER regex(str(?concept_scheme ), '/ICC/v1.0/') .
  ?concept skos:notation ?code .
  OPTIONAL {?concept skos:broader ?broader_concept . ?broader_concept skos:notation ?broaderCode1 . BIND(?broaderCode1 as ?broaderCodes)} 
  ?concept skos:prefLabel ?label_en . FILTER(lang(?label_en)='en') .
  OPTIONAL {?concept skos:prefLabel ?label_fr . FILTER(lang(?label_fr)='fr') }.
  OPTIONAL {?concept skos:prefLabel ?label_es . FILTER(lang(?label_es)='es') }.
  OPTIONAL {?concept skos:prefLabel ?label_ru . FILTER(lang(?label_ru)='ru') }.
  OPTIONAL {?concept skos:altLabel ?alternative_label }.
  OPTIONAL {?concept skos:definition ?definition }.
  OPTIONAL {?concept skos:note ?note }.  
  }
GROUP BY ?code ?broader ?label_en ?label_es ?label_fr ?label_ru ?alternative_label ?definition ?note
ORDER BY ?code

Retrieves the namespaces of the predicates used in Caliper.

SELECT DISTINCT ?valueFinal
WHERE{
?subj ?pre ?obj .
BIND(STRBEFORE(str(?subj), "#") AS ?value)
FILTER(STRLEN(?value) != 0)
BIND(CONCAT(?value, "#" ) AS ?valueFinal)
}
Queries on classifications' metadata

Extracts all triples having a given concept scheme as subject. To run the query, replace the placeholder text "<scheme_uri>" with an existing scheme URI. 

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT * WHERE {
<[scheme_uri]> ?predicate ?object
}

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

select ?pred ?y
where {
<[scheme_uri]> rdf:type skos:ConceptScheme .
<[scheme_uri]> ?pred ?y .
filter regex (str(?pred), "dc")
}


 
Queries on classifications' items

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?code ?label_en ?concept WHERE {
?concept rdf:type skos:Concept .
?concept skos:inScheme <[scheme_uri]> .
?concept skos:prefLabel ?label_en . FILTER(lang(?label_en)='en') .
?concept skos:notation ?code .
} order by ?code

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT distinct ?concept ?code ?prefLabel ?definition ?broaderCode ?broaderLabel WHERE {
?concept a skos:Concept .
?concept skos:inScheme <[scheme_uri]> .
?concept skos:notation ?code .
?concept skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
OPTIONAL {?concept skos:definition ?definition } .
OPTIONAL {?concept skos:broader ?broader . ?broader skos:notation ?broaderCode . ?broader skos:prefLabel ?broaderLabel} .
OPTIONAL {?concept skos:narrower ?narrower . ?narrower
skos:prefLabel ?narrowerLabel} .
}
ORDER by asc(?code)
 

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?concept ?code ?enlabel
WHERE {
?concept a skos:Concept .
?concept skos:notation ?code .
?concept skos:inScheme <[scheme_uri]> .
?concept skos:broader+ <[item_uri]> .
?concept skos:prefLabel ?enlabel .
FILTER (lang(?enlabel)="en")
} ORDER BY ?code

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?concept ?code ?enlabel
WHERE {
?concept a skos:Concept .
?concept skos:notation ?code .
?concept skos:inScheme <https://stats.fao.org/classifications/FPCD/v2022/scheme> .
?concept skos:broader+ <https://stats.fao.org/classifications/FPCD/v2022/08> .
?concept skos:prefLabel ?enlabel .
FILTER (lang(?enlabel)="en")

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xkos: <http://rdf-vocabulary.ddialliance.org/xkos#>

SELECT distinct ?subject ?label ?depth
WHERE {
?subject a xkos:ClassificationLevel .
?subject skos:prefLabel ?label .
?subject skos:member ?concept .
?concept skos:inScheme <[scheme_uri]> .
?subject xkos:depth ?depth .
} order by ?depth

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xkos: <http://rdf-vocabulary.ddialliance.org/xkos#>

SELECT distinct ?subject ?label ?depth
WHERE {
?subject a xkos:ClassificationLevel .
?subject skos:prefLabel ?label .
?subject skos:member ?concept .
?concept skos:inScheme <https://stats.fao.org/classifications/ICC/v1.1/scheme> .
?subject xkos:depth ?depth .
} order by ?depth

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xkos: <http://rdf-vocabulary.ddialliance.org/xkos#>


SELECT ?item_uri ?item_code ?item_label ?classification_level
WHERE {
?classification_level rdf:type xkos:ClassificationLevel .
filter regex (str(?classification_level), "level2") .
?classification_level skos:member ?item_uri .
?item_uri rdf:type skos:Concept .
?item_uri skos:inScheme <https://stats.fao.org/classifications/ICC/v1.1/scheme> .
?item_uri skos:prefLabel ?item_label .
?item_uri skos:notation ?item_code .
} order by ?item_code
Queries on correspondences

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?code_ICC10 ?label_en_ICC10 ?concept_ICC10 ?code_ICC11 ?label_en_ICC11 ?concept_ICC11 WHERE {
?concept_ICC10 rdf:type skos:Concept .
?concept_ICC10 skos:inScheme <https://stats.fao.org/classifications/ICC/v1.0/scheme> .
?concept_ICC10 skos:prefLabel ?label_en_ICC10 . FILTER(lang(?label_en_ICC10)='en') .
?concept_ICC10 skos:notation ?code_ICC10 .
?concept_ICC10 skos:closeMatch ?concept_ICC11 .
?concept_ICC11 skos:inScheme <https://stats.fao.org/classifications/ICC/v1.1/scheme> .
?concept_ICC11 rdf:type skos:Concept .
?concept_ICC11 skos:notation ?code_ICC11 .
?concept_ICC11 skos:prefLabel ?label_en_ICC11 . FILTER(lang(?label_en_ICC11)='en') .
} order by ?code_ICC10

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?code ?label ?s ?o WHERE {
    ?s skos:inScheme <https://unstats.un.org/classifications/CPC/v2.1/core> . 
    ?s skos:closeMatch ?o .
    filter regex (str(?o), "cpa") .
    ?s skos:prefLabel ?label .
    FILTER(lang(?label)='en') .
    ?s skos:notation ?code .
}