query-cb2f1ddb8d922b58b19607b81784de9d

rq turtle/ttl

Topics through time

PREFIX target: http://www.wikidata.org/entity/Q2284414

SELECT ?year ?works ?topic ?topicLabel WITH { SELECT ?work WHERE { ?work wdt:P1433 target: . } } AS %works WITH { SELECT (COUNT(?work) AS ?count) ?topic WHERE { INCLUDE %works ?work wdt:P921 ?topic . } GROUP BY ?topic ORDER BY DESC(?count) LIMIT 5 } AS %topics WITH { SELECT ?year (COUNT(?work) AS ?works) ?topic WHERE { INCLUDE %works INCLUDE %topics ?work wdt:P921 ?topic ; wdt:P577 ?publication_datetime . BIND(STR(YEAR(?publication_datetime)) AS ?year) } GROUP BY ?year ?topic } AS %result WHERE { INCLUDE %result SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?year

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Topics through time

PREFIX target: <http://www.wikidata.org/entity/Q2284414>

SELECT
  ?year
  ?works
  ?topic ?topicLabel
WHERE {
   {
  SELECT
    ?year 
    (COUNT(?work) AS ?works)
    ?topic
  WHERE {
     {
  SELECT 
    ?work
  WHERE {
    ?work wdt:P1433 target: .
  }
}     {
  SELECT
    (COUNT(?work) AS ?count)
    ?topic
  WHERE {
    INCLUDE %works
    ?work wdt:P921 ?topic .
  }
  GROUP BY ?topic
  ORDER BY DESC(?count)
  LIMIT 5
}    ?work wdt:P921 ?topic ;
          wdt:P577 ?publication_datetime .
    BIND(STR(YEAR(?publication_datetime)) AS ?year)
  }
  GROUP BY ?year ?topic
}  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?year

Query found at