Skip to main content Link Menu Expand (external link) Document Search Copy Copied

SPARQL Sample Queries

To help you get started, input these sample queries into the query interface of the Skynet SPARQL Endpoint.

Omit LIMIT X or change to any other value to get more results.

Get commodity data

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

SELECT *
WHERE {
    ?thing a coy:Commodity ;
        rdfs:label ?name ;
        coy:hasTimestamp ?time ;
        coy:hasValue ?value ;
        coy:hasVolatility ?volatility .
    }

Get properties of a specific entity

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX coy: <https://schema.coypu.org/global#>
SELECT DISTINCT ?label ?time
WHERE {
    <IRI> a ?type ;
        rdfs:label ?label ;
        coy:hasTimestamp ?time.
    }

Note: replace IRI with any IRI from the graph and adjust the properties to your needs

Get most recent natural disasters

PREFIX coy: <https://schema.coypu.org/global#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>

SELECT ?name ?description ?location ?time
WHERE {
    ?event a coy:Disaster ;
        rdfs:label ?name ;
        rdfs:comment ?description ;
        geo:hasGeometry/geo:asWKT ?location ;
        coy:hasPublicationTimestamp ?time .
    }
ORDER BY DESC(?time) 
LIMIT 100

Note: the location is provided as WKT literal with scheme "POINT(longitude latitude)"

Get recent events within a radius around a coordinate

PREFIX coy: <https://schema.coypu.org/global#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX spatial: <http://jena.apache.org/spatial#>
PREFIX units: <http://www.opengis.net/def/uom/OGC/1.0/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?feature ?type ?label {
    BIND(now() - "P2M"^^xsd:duration as ?minStartTime).
    VALUES ?myPoint {
        "Point(23.91 -28.38)"^^geo:wktLiteral
    }
    ?feature spatial:nearbyGeom(?myPoint 1000 units:kilometre) .
    ?feature rdfs:label ?label ;
           a ?type .
  
    ?feature coy:hasTimestamp|coy:hasStartTimestamp ?startTime .
    FILTER ( xsd:dateTime(?startTime) >= ?minStartTime )
}
LIMIT 200

Modify Point(lon lat) for different coordinates and P2M for a different timeframe than 2 months

What is the distance between two points?

PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX spatialF: <http://jena.apache.org/function/spatial#>
PREFIX units: <http://www.opengis.net/def/uom/OGC/1.0/>

SELECT * 
WHERE {
    VALUES (?point1 ?point2) {("Point(33.38213 22.83736)"^^geo:wktLiteral "Point(31.38213 24.8236)"^^geo:wktLiteral)}
    BIND (spatialF:greatCircleGeom(?point1, ?point2, units:kilometre) AS ?distance)
}
LIMIT 1

This functionality is also available as an API

In which country or region is this point?

PREFIX coy: <https://schema.coypu.org/global#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?region ?regionLabel 
WHERE {
    GRAPH <https://data.coypu.org/administrative-regions/> {
        BIND ("POINT(12.0 12.0)"^^geo:wktLiteral as ?loc)
        ?geometry geo:sfContains ?loc .
        ?region a coy:AdministrativeRegion ;
            geo:hasGeometry ?geometry ;
            rdfs:label ?regionLabel .
    }
} 
LIMIT 1

Get all distinct ports

PREFIX coy: <https://schema.coypu.org/global#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>

SELECT ?port
    (sample(?id_) AS ?id)
    (sample(?portLabel_) AS ?portLabel)
    (sample(?location_) AS ?location)
WHERE {
    ?port a coy:Port ;
        rdfs:label ?portLabel_ ;
        geo:hasGeometry/geo:asWKT ?location_ ;
        coy:hasId ?id_
}
GROUP BY ?port
LIMIT 5000

This will return all ports including duplicates with the same features:

PREFIX coy: <https://schema.coypu.org/global#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>

SELECT *
WHERE {
    ?port a coy:Port ;
        rdfs:label ?portLabel ;
        geo:hasGeometry/geo:asWKT ?location ;
        coy:hasId ?id
}
LIMIT 6000

Get all members of various international organizations

PREFIX coy: <https://schema.coypu.org/global#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?org ?orgLabel 
    (group_concat(distinct ?altLabel; separator="; ") as ?alt_labels)  
    (count(distinct ?member) as ?num_members) 
    (group_concat(distinct ?memberLabel; separator="; ") as ?members)
{
    ?org a coy:InternationalOrganization ;
        rdfs:label ?orgLabel ;
        skos:altLabel ?altLabel .
    ?member coy:memberOf ?org ;
        rdfs:label ?memberLabel .
    FILTER (lang(?memberLabel) = "en")
} 
GROUP BY ?org ?orgLabel
ORDER BY ?orgLabel
LIMIT 200

Get relevant countries for Exiobase queries

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

SELECT DISTINCT (sample(?labelX) as ?label) ?code ?country 
WHERE {
	?industry a coy:RegionalIndustry ;
  		coy:hasLocation ?region .
  	FILTER ( ?region NOT IN (<https://data.coypu.org/region/WA>, 
      					   <https://data.coypu.org/region/WL>, 
      					   <https://data.coypu.org/region/WE>, 
      					   <https://data.coypu.org/region/WF>, 
      					   <https://data.coypu.org/region/WM>) ) . 
    ?region coy:hasSubRegion ?country .
    ?country coy:hasIsoCode ?code ;
    	rdfs:label ?labelX .
} GROUP BY ?code ?country

Get relevant NACE codes for Exiobase queries

PREFIX coy: <https://schema.coypu.org/global#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT DISTINCT ?code ?label
WHERE {
	?industry a coy:ExiobaseIndustry ;
  		coy:hasIndustry ?nace .
  	?nace skos:prefLabel ?label ;
       	skos:notation ?code .
} ORDER BY ?code

Get Dataset Metadata

Note: Full DCAT compliance is ongoing work.

PREFIX dct: <http://purl.org/dc/terms/>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX meta: <https://schema.coypu.org/metadata-template#>

select ?id ?record ?graph ?licenseNote {
  ?s
    a meta:Catalog ;
    dcat:record ?record ;
    .
  ?record
    dct:identifier ?id ;
    meta:graph ?graph ;    
    meta:licenseNote ?licenseNote ;
    .
}