sparql-examples

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

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

125

rq turtle/ttl

Pathway aspect: recent articles

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX target: <http://www.wikidata.org/entity/Q28031254>

SELECT ?date ?work ?workLabel ?type ?topics
WITH {
  SELECT DISTINCT ?work 
    WHERE {
      { ?work wdt:P921 / (wdt:P361+ | wdt:P1269+ | (wdt:P31* / wdt:P279*) ) target: . }
      UNION { target: wdt:P2860 ?work . }
    }
} AS %works
WITH {
  SELECT 
    (MAX(?dates) as ?datetime)
    ?work
    (GROUP_CONCAT(DISTINCT ?type_label; separator=", ") AS ?type)
    (GROUP_CONCAT(?topic_label; separator=" // ") AS ?topics) 
  WHERE {
    INCLUDE %works
    OPTIONAL {
      ?work wdt:P921 ?topic .
      ?topic rdfs:label ?topic_label .
      FILTER (lang(?topic_label) = 'en')
    }
    OPTIONAL { 
      ?work wdt:P31 ?type_ .
      ?type_ rdfs:label ?type_label .
      FILTER (LANG(?type_label) = 'en') 
    }
    OPTIONAL { ?work wdt:P577 ?dates . }
  }
  GROUP BY ?work
} AS %result
WHERE {
  INCLUDE %result
  BIND(xsd:date(?datetime) AS ?date)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }
}
ORDER BY DESC(?date)
LIMIT 500
graph TD