Frequently Asked Queries
On this page, we are collecting some SPARQL Query Patterns that are useful to work with the LINDAS Linked Data.
Multilingual Labels to Monolingual Columns
The following Query returns the names of all seven federal departments in the four official languages and optional in English in separate columns:
PREFIX schema: <http://schema.org/>
SELECT DISTINCT * WHERE {
?department schema:inDefinedTermSet <https://ld.admin.ch/department>.
?department schema:name ?name_DE. FILTER(lang(?name_DE) = "de")
?department schema:name ?name_FR. FILTER(lang(?name_FR) = "fr")
?department schema:name ?name_IT. FILTER(lang(?name_IT) = "it")
?department schema:name ?name_RM. FILTER(lang(?name_RM) = "rm")
OPTIONAL {?department schema:name ?name_EN. FILTER(lang(?name_EN) = "en")}
}
Run this query in the YASGUI Interface of LINDAS
Reduce Language-Tagged Strings to a Single String (with Language Preferences)
The following query reduces multiple schema:name
attributes (with different or non existent language tags) to a single answer (depening on given language preferences):
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX schema: <http://schema.org/>
SELECT DISTINCT ?creator ?name WHERE {
?s dct:creator ?creator.
OPTIONAL {?creator schema:name ?nameDE. FILTER(lang(?nameDE) = "de")}
OPTIONAL {?creator schema:name ?nameFR. FILTER(lang(?nameFR) = "fr")}
OPTIONAL {?creator schema:name ?nameIT. FILTER(lang(?nameIT) = "it")}
OPTIONAL {?creator schema:name ?nameRM. FILTER(lang(?nameRM) = "rm")}
OPTIONAL {?creator schema:name ?nameEN. FILTER(lang(?nameEN) = "en")}
OPTIONAL {?creator schema:name ?nameUndef. FILTER(lang(?nameUndef) = "")}
BIND (
COALESCE(
IF(BOUND(?nameEN), ?nameEN, 1/0),
IF(BOUND(?nameDE), ?nameDE, 1/0),
IF(BOUND(?nameFR), ?nameFR, 1/0),
IF(BOUND(?nameIT), ?nameIT, 1/0),
IF(BOUND(?nameRM), ?nameRM, 1/0),
IF(BOUND(?nameUndef), ?nameUndef, 1/0),
""
) AS ?name
)
} ORDER BY ?name
Run this query in the YASGUI Interface of LINDAS
Resources that Belong to at Least one Class of a List
The following Query returns all the datasets in LINDAS. The problem with a dataset is that at least four different classes for datasets exist and not all datasets belong to all these four classes:
PREFIX void: <http://rdfs.org/ns/void#>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX schema: <http://schema.org/>
SELECT DISTINCT ?dataset WHERE {
?dataset a ?class.
FILTER(?class IN (schema:Dataset, void:Dataset, dcat:Dataset, <https://schema.ld.admin.ch/Dataset>))
}
Run this query in the YASGUI Interface of LINDAS
Finding the Latest Version of a Cube
Cube Creator generated Cubes in LINDAS have versions. To find the latest version of a cube (given by its dcterms:identifier
), the following SPARQL query can be helpful:
PREFIX schema: <http://schema.org/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT ?dataset WHERE {
BIND("ubd0104" as ?id)
?dataset a schema:Dataset;
dcterms:identifier ?id.
FILTER NOT EXISTS {?dataset schema:expires ?expDate}
}