About SPARQL | data.europa.eu
Direkt zum Inhalt

About SPARQL

To access the data of data.europa.eu, a machine-readable SPARQL endpoint allows querying the RDF descriptions of datasets.

SPARQL is an RDF query language, i.e. a semantic query language for databases.

The SPARQL search of the portal offers a graphical user interface to enter your SPARQL queries.

For programmatic use, a machine-readable endpoint is available at the following URL: https://data.europa.eu/data/sparql?locale=de

The following section provides a short introduction to the SPARQL language and some examples that are specific to the context of data.europa.eu.

For a complete documentation of the language, the specifications of SPARQL can be found on the W3C web site.

 

SPARQL Query Language

If you are not familiar with using SPARQL Query Language, we invite you to read this short summary of useful SPARQL clauses which are used in the queries below. For further reading please refer to W3C recommendation https://www.w3.org/TR/rdf-sparql-query/.

  • PREFIX - Shorthand to avoid writing full URIs in the queries, prefixes can be defined in a query. Below is a list of most common prefixes used in the RDFs of data.europa.eu datasets. The syntax to use is the following.
    PREFIX ${PREFIX_NAME}: ${FULL_URI}
    Where:
    • ${PREFIX_NAME} is the name of the shorthand that will be used in the query instead of the full URI.
    • ${FULL_URI} is the URI that will be replaced by the prefix.
  • SELECT - The 'SELECT' clause is used to indicate which piece of information (variable) should be returned from the query. The syntax 'SELECT *' is an abbreviation to select all the variables of a query.
    It is possible to select multiple variables. When using 'SELECT DISTINCT' variables that occur multiple times in the result will only be selected once.
  • WHERE - The 'WHERE' clause is used to specify a list of patterns to restrict the information for retrieval. Those patterns are triples where any of the elements can be replaced by a variable.
    To separate multiple patterns, the character '.' is used as a separator. This allows the option of combining patterns. Their combination works as a logical 'AND'.
  • LIMIT - The 'LIMIT' clause allows putting a limit to the number of results that will be returned.
  • OPTIONAL - With the 'OPTIONAL' clause, some patterns in the 'WHERE' clause can be set as not mandatory. When a appears in an 'OPTIONAL' clause the result will only display values when present and would appear blank when missing.
  • FROM - In the triple store (which stores the RDF information), the triples can be grouped by graph. It is possible to restrict a query to a specific graph by using FROM <[URIofGraph]>>. In the context of data.europa.eu, each dataset is stored in its own graph. Other named graphs include metrics of the data quality evaluation, Controlled Vocabularies used in DCAT-AP (e.g. http://publications.europa.eu/resource/authority/data-theme; <http://publications.europa.eu/resource/authority/access-right>) NUTS codes (e.g. http://publications.europa.eu/resource/authority/nuts-gisco-links; <http://publications.europa.eu/resource/authority/nuts>) and more.
  • FILTER - The 'FILTER' clause provides a way to further restrict the solutions of a 'WHERE' clause. The restrictions can be, for instance, regex for string patterns or language selection.

A list of PREFIXES used in data.europa.eu RDFs

PREFIX dcat: <http://www.w3.org/ns/dcat#>

PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>

PREFIX dct: <http://purl.org/dc/terms/>

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

PREFIX adms: <http://www.w3.org/ns/adms#>

PREFIX dcatapop: <http://data.europa.eu/88u/ontology/dcatapop>

PREFIX gsp: <http://www.opengis.net/ont/geosparql#>

PREFIX locn: <http://www.w3.org/ns/locn#>

PREFIX owl: <http://www.w3.org/2002/07/owl#>

PREFIX prov: <http://www.w3.org/ns/prov#>

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

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

PREFIX schema: <http://schema.org/>

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

PREFIX spdx: <http://spdx.org/rdf/terms#>

PREFIX vcard: http://www.w3.org/2006/vcard/ns#

 

Sample SPARQL Queries

Get a list of all catalogues on data.europa.eu

This query retrieves a full list catalogues published on data.europa.eu. It then retrieves with an OPTIONAL clause the catalogue's title, homepage, geographical coverage etc.

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?parentCatalog ?catalog ?title ?spatial ?typePublisher ?homepage ?email
WHERE {?catalog ?p ?o.
FILTER (?o=<http://www.w3.org/ns/dcat#Catalog>)
OPTIONAL {?catalog <http://purl.org/dc/terms/title> ?title}
OPTIONAL {?parentCatalog <http://purl.org/dc/terms/hasPart> ?catalog}
OPTIONAL {?catalog <http://purl.org/dc/terms/spatial> ?spatial.}
OPTIONAL {?catalog <http://purl.org/dc/terms/publisher> ?publisher.
OPTIONAL {?publisher <http://xmlns.com/foaf/0.1/homepage> ?homepage.}
OPTIONAL {?publisher <http://xmlns.com/foaf/0.1/mbox> ?email.}
OPTIONAL {?publisher <http://purl.org/dc/terms/type> ?typePublisher.}
}
}
ORDER BY DESC (?spatial)

 

Show all datasets, distributions and data service of the former EU Open Data Portal

When the former EU Open Data Portal was consolidated with the European Data Portal to the data.europa.eu portal, datasets of each publisher were modelled as individual catalogues that are expressed as part of the EU Open Data Portal. We the URI <http://data.europa.eu/88u/catalogue/european-union-open-data-portal> to indicate the EU Portal and the property dct:hasPart to call all catalogues that are part of it. The OPTIONAL clause used to call data-services allows calling all datasets and distribution even when these are not linked to a data-service.

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT DISTINCT *
WHERE {
<http://data.europa.eu/88u/catalogue/european-union-open-data-portal> a dcat:Catalog;
dct:hasPart ?subCatalogue.
?subCatalogue dcat:dataset ?datasetURI.
?datasetURI a dcat:Dataset;
dcat:distribution ?distributionURI.
?distributionURI a dcat:Distribution.
OPTIONAL {
?distributionURI dcat:accessService ?dataServiceURI.
?dataServiceURI a dcat:DataService;
dcat:servesDataset ?datasetURI}}

 

Datasets, their publisher and keywords in the Environment thematic category

Thematic categories of datasets are expressed using the dcat:theme property using terms from the data-theme controlled vocabulary. Another property used to describe the subject-matter of datasets is dcat:keyword which uses literal values (i.e. free-text). The following query calls all datasets for which the URI corresponding to the concept "Environment" is defined and retrieves the name of the publisher (defined as either rdfs:label or skos:prefLabel), the title of the dataset and groups all keywords used to describe it. Because datasets on the portal are potentially available in all official EU Languages, a language filter is used to restrict results to wither English or no language tag. The GROUP_CONCAT clause groups all keywords used for each dataset together using "|" as a separator.

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT DISTINCT ?datasetURI ?datasetTitle ?publisher (GROUP_CONCAT(?keyword; SEPARATOR = " | ") AS ?keywords)
WHERE {
?datasetURI a dcat:Dataset;
dct:publisher/rdfs:label|dct:publisher/skos:prefLabel ?publisher;
dcat:theme <http://publications.europa.eu/resource/authority/data-theme/ENVI>; #this is the theme for Environment
dcat:keyword ?keyword;
dct:title ?datasetTitle.
FILTER(LANG(?datasetTitle)= "" || LANG(?datasetTitle) = "en").
FILTER (LANG(?publisher) = "" || LANG(?publisher) = "en") .
}
ORDER BY ?datasetURI

 

Retrieve datasets for which a Eurovoc term is defined

Eurovoc is the multilingual multi-disciplinary thesaurus curated by the publications Office of the European Union. It is widely used by both EU and national institutions in a variety of contexts. The following query retrieves datasets that have one of the indicated terms defined for them (using the syntax "||" to mark an "OR" function) via the dct:subject or dcat:theme property. Being a controlled vocabulary, all terms are indicated by a URI. The labels are available in 24 languages and the language filter used in the query restricts results to labels provided in English.

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT DISTINCT ?datasetTitle ?eurovocURI ?eurovocLabel
WHERE {
?datasetURI a dcat:Dataset;
dct:title ?datasetTitle;
dcat:theme |dct:subject ?eurovocURI. FILTER(?eurovocURI= <http://eurovoc.europa.eu/437655> || ?eurovocURI=
<http://eurovoc.europa.eu/7219> || ?eurovocURI = <http://eurovoc.europa.eu/7939> ).
?eurovocURI skos:prefLabel ?eurovocLabel. FILTER (LANGMATCHES(LANG(?eurovocLabel), "en")) .
FILTER(LANG(?datasetTitle)= "" || LANG(?datasetTitle) = "en").
}

 

Retrieve dates related to a specific dataset

This query retrieves different dates recorded via the dct:issued and dct:modified proporties for a specific dataset. The query is done on the classes:​

  • Catalogue record
  • Dataset
  • Distribution

For Datasets an additional property is dct:temporal, of type dct:PeriodOfTime which registers the period of time covered by the dataset. For Distributions, the dct:accrualPeriodicity indicates how often the data is updated.

The OPTIONAL clause is used to search for the metadata even when no value is provided.

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT DISTINCT ?datasetTitle ?recordDateCreated ?recordDateUpdated ?datasetDateCreated ?datasetDateModified ?periodoStart ?periodEnd ?distributionDateCreated ?distributionDateUpdated ?frequencyOfUpdate
WHERE {
?recordURI a dcat:CatalogRecord;
foaf:primaryTopic ?datasetURI. FILTER(?datasetURI=<http://data.europa.eu/88u/dataset/eurobarometer-2012-on-perceptions-of-discrimination-in-the-eu>).
?recordURI dct:issued ?recordDateCreated;
dct:modified ?recordDateUpdated.
?datasetURI a dcat:Dataset;
dct:title ?datasetTitle;
dcat:distribution ?distributionURI.
OPTIONAL {
?datasetURI dct:issued ?datasetDateCreated; dct:modified ?datasetDateModified.}
OPTIONAL {
?datasetURI dct:temporal ?periodOfTime. ?periodOfTime dcat:startDate ?periodoStart; dcat:endDate ?periodEnd.}
OPTIONAL {
?distributionURI dct:issued ?distributionDateCreated; dct:modified ?distributionDateUpdated; dct:accrualPeriodicity ?frequencyOfUpdate.}
FILTER(LANGMATCHES(LANG(?datasetTitle), "en"))
}

 

Find dataset distributions of a specific file-type

File types are assigned to Distributions of dataset as IANA media types (MIME types) using dcat:mediaType - a subproperty of dct:format. dct:format further specifies file types of distributions using terms for the Publications Office of the European Union File Type vocabulary.

The following query looks for Distribution with a dcat:accessURL - the URL giving access to the file itself - that are of XML file type. The file type is expressed using the File Type vocabulary using a FILTER clause to restrict results. Because different publishers encode values in to assign IANA file types an OPTIONAL clause is used.

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT distinct ?datastURI ?accessURL ?IANAfileType ?IANALabel ?OPLabel
WHERE {
?datastURI a dcat:Dataset;
dcat:distribution ?distributionURI.
?distributionURI dcat:accessURL ?accessURL;
dct:format ?OPFileType. FILTER(?OPFileType=<http://publications.europa.eu/resource/authority/file-type/XML>)
?OPFileType skos:prefLabel ?OPLabel. FILTER(LANGMATCHES(LANG(?OPLabel),"en"))
OPTIONAL {
?distributionURI dcat:mediaType ?IANAfileType.
?IANAfileType rdf:value ?IANALabel}
}
ORDER BY ?datastURI

 

See the status of Distributions of a selected dataset

Values used to define the status of a Distribution are drawn from a Controlled Vocabulary and can be either "Completed", "Deprecated", "Under Development" or "Withdrawn". The following query retrieves all distributions of a specific dataset (identified by the URI <http://data.europa.eu/88u/dataset/eurovoc>) for which the property adms:status is assigned.

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX adms: <http://www.w3.org/ns/adms#>

SELECT DISTINCT ?distributionURI ?distribtuionTitle ?statusLabel
WHERE {
<http://data.europa.eu/88u/dataset/eurovoc> a dcat:Dataset;
dcat:distribution ?distributionURI.
?distributionURI adms:status ?distributionStatus.
OPTIONAL {?distributionURI dct:title ?distribtuionTitle. FILTER(LANGMATCHES(LANG(?distribtuionTitle), "en"))}
?distributionStatus skos:prefLabel ?statusLabel.
FILTER(LANGMATCHES(LANG(?statusLabel), "en"))
}

 

Publishers by catalogue

This query looks for up to 25 publishers who publish datasets in a defined catalogue (identified by the URI <http://data.europa.eu/88u/catalogue/nkod-opendata-cz>).

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX odp: <http://data.europa.eu/euodp/ontologies/ec-odp#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT DISTINCT ?publisher ?publisherName ?publisherLabel
WHERE {
<http://data.europa.eu/88u/catalogue/nkod-opendata-cz> a dcat:Catalog;
dcat:dataset ?datatsetURI.
?datatsetURI dct:publisher ?publisher.
OPTIONAL {?publisher foaf:name ?publisherName}
OPTIONAL {?publisher skos:prefLabel ?publisherLabel}
}
LIMIT 25