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 items in a classification (only the URIs)
(Run on the Geo 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 ?concept WHERE {
  ?concept a skos:Concept .
}

Get all items in a classification (URIs, code and preferred label in English):
(For labels in different languages, replace "en" with the corresponding language tag. Run on the Geo 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 ?concept ?code ?prefLabel WHERE {
  ?concept a skos:Concept .
  ?concept skos:notation ?code .
  ?concept skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)="en")
}

Get all items in a classification, with their code and EN label, sorted alphabetically by the label
(For labels in different languages, replace "en" with the corresponding language tag.)

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

 

Count the number of avaialable Russian preferred labels.
(For labels in different languages, replace "ru" with the corresponding language tag. Try on FLC Sparql endpoint)

SELECT (count(?enlabel) as ?count)
WHERE {
  ?concept a skos:Concept .
  ?concept skos:prefLabel ?enlabel .
  FILTER (lang(?enlabel)='ru')
}

 

List of items in a classification, with their code, preferred EN label, and alternative EN label when available; grouped by preferred label
(For labels in different languages, replace "en" with the corresponding language tag.)

SELECT ?concept ?prefLabel (GROUP_CONCAT ( concat('"',?altLabel,'"@',lang(?altLabel)); separator=", " ) as ?altLabels)
WHERE {
  ?concept a skos:Concept .
  ?concept skos:prefLabel ?prefLabel .
  BIND("en" AS ?lang)
  FILTER(lang(?prefLabel) = ?lang)
  OPTIONAL{
    ?concept skosxl:altLabel ?altLabel .
    FILTER(lang(?altLabel) = ?lang)
  }
}
GROUP BY ?concept ?prefLabel

Get all items in a classification, with EN label, definition, name of the broader item

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

Given a classification, get all correspondences available (code - code), 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 ?concept ?code ?prefLabel ?target WHERE {
  ?concept skos:notation ?code .
  {?concept skos:exactMatch ?target} UNION {?concept skos:closeMatch ?target}
  ?concept skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel)= "en") .
}
ORDER by asc(?code)

 

List all items with EN label but no ES label
(For example, run on SPARQL endpoint listed for CRS 2020-01, see the endpoints page)

SELECT ?concept ?prefLabelEN
where {
      ?concept a skos:Concept .
 
    FILTER NOT EXISTS {
    ?concept skos:prefLabel ?prefLabel .  
    FILTER (lang(?prefLabel)= "es" ) }

    ?concept skos:prefLabel ?prefLabelEN .  
    FILTER (lang(?prefLabelEN)= "en") .
}


CRS 2020-01. List all items "below" code 310 "Agriculture, Forestry, Fishing", using their EN label. 
(You can adapt this query and use it to extract "subtrees" from any classification. For the addresses of SPARQL endpoints, see page endpoints page)

SELECT ?concept ?enlabel
WHERE {
  ?concept a skos:Concept .
  ?concept skos:broader+ <http://stats-class.fao.uniroma2.it/CRS/v2020_01/sector_purpose/310> .
  ?concept skos:prefLabel ?enlabel .
  FILTER (lang(?enlabel)="en")
} ORDER BY ?enlabel

 

CRS 2020-01. List all items "below" code 110 "Education" that do not have an ES label. Use EN label for display.
(You can adapt this query and use it to extract "subtrees" from any classification. For the addresses of SPARQL endpoints, see page endpoints page)

SELECT ?concept ?enlabel
WHERE {
  ?concept a skos:Concept .
  ?concept skos:broader+ <http://stats-class.fao.uniroma2.it/CRS/v2020_01/sector_purpose/110> .
  ?concept skos:prefLabel ?enlabel .
  FILTER (lang(?enlabel)="en")
  FILTER NOT EXISTS {
    ?concept skos:prefLabel ?label .
    FILTER (lang(?label)='es')
  }
} ORDER BY ?enlabel

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 items (code and EN preferred label) together with either FR, ES, RU labels and explanatory note and definitions when available. 
(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)

 

ICC: get all existing mappings between all ICC 1.1 and AGROVOC
(Run on the "ICC v1.1" SPARQL endpoint listed on the endpoints page)

SELECT ?icc_concept ?agrovoc_concept ?enAgrovocLabel_lower ?icc_prefLabelEn_lower

WHERE {
    {
        SERVICE <http://agrovoc.uniroma2.it/sparql>{
            SELECT ?agrovoc_concept ?enAgrovocLabel_lower 
            WHERE {
                ?agrovoc_concept a skos:Concept .
                ?agrovoc_concept skos:prefLabel ?enAgrovocLabel .
                FILTER(lang(?enAgrovocLabel) = 'en')
                BIND (lcase(str(?enAgrovocLabel)) as ?enAgrovocLabel_lower )
            }
        }
    }
    
    {
        SELECT ?icc_concept ?icc_prefLabelEn_lower
        WHERE {
            ?icc_concept a skos:Concept .
            ?icc_concept skos:prefLabel ?icc_prefLabelEn .
            FILTER(lang(?icc_prefLabelEn) = 'en')
            BIND (lcase(str(?icc_prefLabelEn)) as ?icc_prefLabelEn_lower )
        }
    }
    
    FILTER(str(?icc_prefLabelEn_lower) = str(?enAgrovocLabel_lower)) 
    
}

 

Geo: get all countries valid from the year 2000.
(Run on the Geo SPARQL endpoint listed on the endpoints page)

SELECT ?concept_URI ?prefLabelEn ?since
WHERE {
    ?concept_URI a skos:Concept .
    ?concept_URI skos:prefLabel ?prefLabelEn .
    filter (lang(?prefLabelEn) = 'en') .
    ?concept_URI geopol:validSince ?since .
    ?concept_URI geopol:validUntil ?until .
    FILTER(xsd:int(?since) > 2000) .
}