query-f67c34ef521fa3cc9d2ee86f1e364367

rq turtle/ttl

WSJ journalists ordered by number of articles in Wikidata (including the ones w 0 articles) SELECT ?author ?authorLabel (COALESCE((SAMPLE(?count)), 0) AS $totalArticles) WHERE { { SELECT DISTINCT ?author ?count WHERE { ?author wdt:P31 wd:Q5; p:P6872 ?n. ?n ps:P6872 wd:Q164746. } } UNION { SELECT DISTINCT ?author (COUNT(?item) AS ?count) WHERE {
?item wdt:P1433 wd:Q164746. hint:Prior hint:runFirst "true"^^xsd:boolean. ?item (wdt:P31/(wdt:P279*)) wd:Q191067; wdt:P50 ?author. } GROUP BY ?author } SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } GROUP BY ?author ?authorLabel ORDER BY DESC ($totalArticles)

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# WSJ journalists ordered by number of articles in Wikidata (including the ones w 0 articles)
SELECT ?author ?authorLabel (COALESCE((SAMPLE(?count)), 0) AS $totalArticles) WHERE {
  {
    SELECT DISTINCT ?author ?count WHERE {
      ?author wdt:P31 wd:Q5;
        p:P6872 ?n.
      ?n ps:P6872 wd:Q164746.
    }
  } UNION {
    SELECT DISTINCT ?author (COUNT(?item) AS ?count) 
    WHERE {  
      ?item wdt:P1433 wd:Q164746.

      ?item (wdt:P31/(wdt:P279*)) wd:Q191067;
        wdt:P50 ?author.
    }
    GROUP BY ?author
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?author ?authorLabel
ORDER BY DESC ($totalArticles)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?author"):::projected v5("?count") v4("?item") v3("?n") v6("?totalArticles") a1((" ")) c13(["en"]):::literal c11(["bd:serviceParam"]):::iri c5(["wd:Q164746"]):::iri c2(["wd:Q5"]):::iri c8(["wd:Q191067"]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P1433"--> c5 v4 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c8 v4 --"p:direct/P50"--> v2 bind1[/"count(?item)"/] v4 --o bind1 bind1 --as--o v5 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"p:direct/P31"--> c2 v2 --"p:P6872"--> v3 v3 --"p:statement/P6872"--> c5 end union0r <== or ==> union0l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end bind3[/"'0^^xsd:integer'"/] null --o bind3 bind3 --as--o v6