sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

083

rq turtle/ttl

Event aspect: past events

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?time ?short_name 
?event ?eventLabel (CONCAT("/event/", SUBSTR(STR(?event), 32)) AS ?eventUrl)
?location ?locationLabel (CONCAT("/location/", SUBSTR(STR(?location), 32)) AS ?locationUrl)
WITH {
  SELECT DISTINCT ?event WHERE {
    # This union seems to be faster than a VALUES-based query
    { ?event wdt:P31 / wdt:P279* wd:Q52260246 . }
    UNION 
    { ?event wdt:P31 / wdt:P279* wd:Q46855 . }
  }
} AS %events
WITH {
  SELECT 
    ?event 
    (xsd:date(MIN(?times)) AS ?time)
    (SAMPLE(?locations) AS ?location)
    (SAMPLE(?short_names) AS ?short_name)
  WHERE {
    INCLUDE %events
    
    ?event wdt:P580 | wdt:P585 ?times .
    FILTER (?times < NOW())
  
    OPTIONAL { ?event wdt:P276 ?locations }
    OPTIONAL { ?event wdt:P1813 ?short_names }
  }
  GROUP BY ?event
} AS %result
WHERE {
  INCLUDE %result
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en,da,de,fr,jp,nl,no,pl,ru,sv,zh". }
}
ORDER BY DESC(?time)
LIMIT 200

graph TD