query-5be6d9b7f37ede7bdf56a2ce5cc218f3

rq turtle/ttl

.on Mastodon and on TwitterOriginally posted

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:BarChart
SELECT (REPLACE(REPLACE(?nobelPrizeLabel_, "^Nobel Prize in ", ""), "^Nobel (.*) Prize$", "$1") AS ?nobelPrizeLabel) (COUNT(DISTINCT ?winner) AS ?winners) (COALESCE(?genderLabel_, "N/A"@en) AS ?genderLabel) WHERE {
  ?nobelPrize wdt:P361 wd:Q7191.
  ?winner p:P166 [
            ps:P166 ?nobelPrize;
            pq:P585 ?date
          ].
  OPTIONAL { ?winner wdt:P21 ?gender. } # optional because organizations can win the Peace Prize
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    ?nobelPrize rdfs:label ?nobelPrizeLabel_.
    ?gender rdfs:label ?genderLabel_.
  }
}
GROUP BY ?nobelPrizeLabel_ ?genderLabel_

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?date") v4("?gender") v9("?genderLabel") v6("?genderLabel_"):::projected v1("?nobelPrize") v7("?nobelPrizeLabel") v5("?nobelPrizeLabel_"):::projected v3("?winner"):::projected v8("?winners") a1((" ")) c8(["bd:serviceParam"]):::iri c10(["#91;AUTO_LANGUAGE#93;,en"]):::literal c2(["wd:Q7191"]):::iri v1 --"p:direct/P361"--> c2 a1 --"p:statement/P166"--> v1 a1 --"p:qualifier/P585"--> v2 v3 --"p:P166"--> a1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P21".-> v4 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 v1 --"rdfs:label"--> v5 v4 --"rdfs:label"--> v6 end bind1[/"replace(replace(?nobelPrizeLabel_,'^Nobel Prize in ',''),'^Nobel (.*) Prize$','$1')"/] v5 --o bind1 bind1 --as--o v7 bind2[/"count(?winner)"/] v3 --o bind2 bind2 --as--o v8 bind3[/"?genderLabel_sN/A^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'"/] v6 --o bind3 bind3 --as--o v9