Querying the classifications

RDF data can be queried using the SPARQL query language. Here below a few examples of SPARQL queries to query the classifications in Caliper.

The list of SPARQL endpoints where to fire the SPARQL queries is here (experimental content: when prompted use password caliper to acknowledge this and access content).

Get all distinct URIs in the scheme:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT distinct ?sub WHERE {
  ?sub ?pred ?obj .
}
LIMIT 10

Get all distinct pair of URI and 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 ?sub ?code WHERE {
  ?sub skos:notation ?code .
}

Get all pairs of distinct code and label (title)

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 ?sub ?code ?prefLabel WHERE {
  ?sub skos:notation ?code .
  ?sub skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
}

Get all pairs of distinct code and label (title) filtered by language (in the example, English)

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 ?sub ?code ?prefLabel WHERE {
  ?sub skos:notation ?code .
  ?sub skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
}

Get all pairs of distinct code and label (title) filtered by language (in the example, English), with sorted alphabetically by the label

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 ?sub ?code ?prefLabel WHERE {
  ?sub skos:notation ?code .
  ?sub skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
}
ORDER by asc((str(?prefLabel)))

Get all pairs of mappings (correspondences), sorted by the code of the mapping' source

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 ?sub ?code ?prefLabel ?target WHERE {
  ?sub skos:notation ?code .
  {?sub skos:exactMatch ?target} UNION {?sub skos:closeMatch ?target}
  ?sub skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
}
ORDER by asc(?code)

Get all human-readable information about all concepts

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 ?uri ?code ?prefLabel ?definition ?broaderLabel ?narrowerLabel WHERE {
  ?uri skos:notation ?code .
  ?uri skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
    OPTIONAL {?uri skos:definition ?definition } .
    OPTIONAL {?uri skos:broader ?broader . ?broader skos:prefLabel ?broaderLabel} .
    OPTIONAL {?uri skos:narrower ?narrower . ?narrower skos:prefLabel ?narrowerLabel} .
}
ORDER by asc(?code)

FCL: export a format similar to the one published by FAO, sorted by code.
(Run on the FCL SPARQL endpoint listed on the endpoints page)

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 ?prefLabel ?definition ?group_name ?group_code WHERE {
  ?commodity_URI skos:notation ?code .
  ?commodity_URI skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
  ?commodity_URI skos:definition ?definition . FILTER (lang(?prefLabel)= "en") .
  ?group_URI skos:narrower ?commodity_URI .
  ?group_URI skos:prefLabel ?group_name . FILTER (lang(?group_name)= "en") .
  ?group_URI skos:notation ?group_code .
}
ORDER by asc((str(?code)))

 

CPC 2.1 and 2.1 FAO Expansions: get all entries relevant to the Fisheries division in FAO, with labels and code, ordered by code.
(Run on the CPC 2.1 SPARQL endpoint listed on the endpoints page)

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 ?prefLabel ?uri WHERE {
  <http://stats-class.fao.uniroma2.it/cpc/cpc_v2.1/fisheries> skos:member ?uri .
  ?uri skos:prefLabel ?prefLabel .
  ?uri skos:notation ?code .
}
ORDER by asc((str(?code)))

FCL: get all terms that have NOT been translated in either French, Spanish or Russian.
(Run on the FCL SPARQL endpoint listed on the endpoints page)

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 ?prefLabel ?prefLabelFR ?prefLabelES ?prefLabelRU ?uri ?definition ?note 
 WHERE {
       ?uri rdf:type skos:Concept . ?uri skos:notation ?code .
      ?uri skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
      OPTIONAL {?uri skos:prefLabel ?prefLabelFR . FILTER (lang(?prefLabelFR)= "fr") . FILTER (str(?prefLabelFR) = "")} .
      OPTIONAL {?uri skos:prefLabel ?prefLabelES . FILTER (lang(?prefLabelES)= "es") . FILTER (str(?prefLabelES) = "")} .
      OPTIONAL {?uri skos:prefLabel ?prefLabelRU . FILTER (lang(?prefLabelRU)= "ru") . FILTER (str(?prefLabelRU) = "")} .
      OPTIONAL {?uri skos:scopeNote ?note } .
      OPTIONAL {?uri skos:definition ?definition } .
}
ORDER by asc(?code) 

CPC 2.0: get all correspondences with CPC 2.1
(Run on the "ALL CLASSIFICATIONS" SPARQL endpoint listed on the endpoints page)

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 ?CPC20_code ?CPC20_label 
    (group_concat (distinct ?mappedCode;separator=",") as ?CPC21_corr)
    (group_concat (distinct ?partialMappedCode;separator=",") as ?CPC21_partialCorr)  
  WHERE {
  ?uri rdf:type skos:Concept . ?uri skos:notation ?CPC20_code .  ?uri skos:prefLabel ?CPC20_label . FILTER (lang(?CPC20_label)= "en") .
  FILTER(STRSTARTS(STR(?uri), "http://stats-class.fao.uniroma2.it/cpc/cpc_v2.0/")) .
  OPTIONAL { ?uri skos:exactMatch ?exactMatch .   ?exactMatch skos:notation ?mappedCode . 
      FILTER(STRSTARTS(STR(?exactMatch), "http://stats-class.fao.uniroma2.it/cpc/cpc_v2.1/")) } .
  OPTIONAL {?uri skos:closeMatch ?closeMatch .   ?closeMatch skos:notation ?partialMappedCode . 
  FILTER(STRSTARTS(STR(?closeMatch), "http://stats-class.fao.uniroma2.it/cpc/cpc_v2.1/")) } .
   {?uri skos:exactMatch ?match1 . FILTER(STRSTARTS(STR(?match1), "http://stats-class.fao.uniroma2.it/cpc/cpc_v2.1/"))} 
   UNION {?uri skos:closeMatch ?match2 . FILTER(STRSTARTS(STR(?match2), "http://stats-class.fao.uniroma2.it/cpc/cpc_v2.1/"))} 
} GROUP BY ?CPC20_code ?CPC20_label ORDER by ?CPC20_code 

ALL classifications: get all existing mappings between all classifications
(Run on the "ALL CLASSIFICATIONS" SPARQL endpoint listed on the endpoints page)

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 ?classification ?code ?label ?mappedClassification ?mappedCode ?mappedLabel WHERE {
  ?uri rdf:type skos:Concept .   ?uri skos:notation ?code .  ?uri skos:prefLabel ?label . FILTER (lang(?label)= "en") .
  ?uri skos:inScheme ?scheme .   ?scheme skos:prefLabel ?classification . FILTER (lang(?classification)= "en") .
  ?uri skos:exactMatch ?exactMatch .   ?exactMatch skos:notation ?mappedCode . 
  ?exactMatch skos:prefLabel ?mappedLabel . FILTER (lang(?mappedLabel)= "en") .
  ?exactMatch skos:inScheme ?mappedScheme . 
  ?mappedScheme skos:prefLabel ?mappedClassification . FILTER (lang(?mappedClassification)= "en") .
} ORDER by asc(?uri)