Query data with SPARQL



(leave empty to query whole database)



SPARQL is a query language for RDF. It's the same as SQL for relational databases. RDF is a triple comprised of a subject, predicate and object. A SPARQL query consists of a set of triples where the subject, predicate and/or object can consist of variables. The idea is to match the triples in the SPARQL query with the existing RDF triples and find solutions to the variables. A SPARQL query is executed on a RDF dataset in SPARQL endpoint, which accept queries and return results via HTTP. More information

Exemplary queries

Here is a list of exemplary queries that can be run against this endpoint.

Show all graphs in the endpoint, ordered by number of triples

SELECT ?g (COUNT(*) AS ?count)
WHERE {
    GRAPH ?g {
        ?s ?p ?o.
    }
}
GROUP BY ?g
ORDER BY DESC ?count


Show what types of things are in the endpoint

SELECT DISTINCT ?Concept WHERE {
    [] a ?Concept
} 


Show all datasets

SELECT DISTINCT ?s
WHERE {
    ?s a <http://purl.org/linked-data/cube#DataSet>
} 


Learn about predicates for an exemplary dataset

In this case the exemplary dataset is: http://data.cso.ie/census-2011/dataset/age-group-gender-population/ga

SELECT DISTINCT ?p ?o
WHERE {
    <http://data.cso.ie/census-2011/dataset/age-group-gender-population/ga> ?p ?o
} 


Show the structure of an exemplary dataset

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?type
WHERE {
    <http://data.cso.ie/census-2011/structure/age-group-gender-population> ?p ?o.
    ?o ?predicate ?type.
} 
                                    


Observations for a given dataset

SELECT DISTINCT ?observation
WHERE {
    ?observation ?p <http://data.cso.ie/census-2011/dataset/age-group-gender-population/ga>
}
                                    


Structure of an exemplary observation

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?observationElement ?label 
WHERE {
    <http://data.cso.ie/census-2011/dataset/age-group-gender-population/GA/G01;0;both> ?p ?observationElement.
    OPTIONAL {
        ?observationElement rdfs:label ?label
    }
} 
                                    


Structure of an exemplary observation and classifications, where it comes from

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?observationElement ?label?inScheme ?classification 
WHERE {
    <http://data.cso.ie/census-2011/dataset/age-group-gender-population/GA/G01;0;both> ?p ?observationElement.
    OPTIONAL {
        ?observationElement rdfs:label ?label
    }.
    OPTIONAL {
        ?observationElement skos:inScheme ?inScheme.
        ?inScheme rdfs:label ?classification
    }
} 
                                    


Find observations and their values that refer to Galway

Please note that it may take a while to run this query

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX sdmx-d: <http://purl.org/linked-data/sdmx/2009/dimension#>
SELECT DISTINCT ?classificationArea ?datasetName ?value 
WHERE {
    ?classificationArea sdmx-d:refArea ?refArea;
        ?has ?value;
        ?datasetPred ?dataset.
    ?dataset a qb:DataSet;
        rdfs:label ?datasetName.
    ?refArea rdfs:label ?label.
    Filter (?label = "GALWAY"@en)
    Filter (datatype(?value) = xsd:int)
} 
LIMIT 10000    
                                    


List of DCs by population

SELECT SUM(?observation) as ?population ?areaLabel 
WHERE {
    GRAPH <http://data.cso.ie/census-2011/graph/DC_age-group-gender-population> {
        ?s ?p <http://data.cso.ie/census-2011/classification/gender/both>. 
        ?s <http://data.cso.ie/census-2011/property/population> ?observation
    }.
    ?s <http://purl.org/linked-data/sdmx/2009/dimension#refArea> ?area.
    ?area rdfs:label ?areaLabel
}
GROUP BY ?areaLabel 
ORDER BY desc(?population)