query-67cf5473c691055842c68fa62de2dd80

rq turtle/ttl

title: Genera of species with no habitat statements SELECT DISTINCT ?topicparent ?taxonname (COUNT(DISTINCT ?item) AS ?count)

WHERE { hint:Query hint:optimizer "None".

{ SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "Search"; wikibase:endpoint "www.wikidata.org"; mwapi:srsearch "habitat and haswbstatement:P31=Q13442814 -haswbstatement:P921=Q52105". ?page_title wikibase:apiOutput mwapi:title. } } UNION { SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "Search"; wikibase:endpoint "www.wikidata.org"; mwapi:srsearch "habitat -and haswbstatement:P31=Q13442814 -haswbstatement:P921=Q52105". ?page_title wikibase:apiOutput mwapi:title. } } BIND(IRI(CONCAT(STR(wd:), ?page_title)) AS ?item)

?item wdt:P1476 ?title. FILTER REGEX(LCASE(?title), "habitat").

?item wdt:P921 ?topic. ?topic wdt:P171 ?topicparent . ?topicparent wdt:P105 wd:Q34740 . ?topicparent wdt:P225 ?taxonname . FILTER NOT EXISTS { ?topic wdt:P2974 [] } .

} GROUP BY ?topicparent ?taxonname ORDER BY DESC(?count)

Use at

PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#title: Genera of species with no habitat statements
SELECT 
  DISTINCT
    ?topicparent ?taxonname (COUNT(DISTINCT ?item) AS ?count)

WHERE {


{  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "Search";
                    wikibase:endpoint "www.wikidata.org";
                    mwapi:srsearch "habitat and haswbstatement:P31=Q13442814 -haswbstatement:P921=Q52105".
      ?page_title wikibase:apiOutput mwapi:title.
  }
 }
UNION
{  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "Search";
                    wikibase:endpoint "www.wikidata.org";
                    mwapi:srsearch "habitat -and haswbstatement:P31=Q13442814 -haswbstatement:P921=Q52105".
      ?page_title wikibase:apiOutput mwapi:title.
  }
 }
  BIND(IRI(CONCAT(STR(wd:), ?page_title)) AS ?item)

  ?item wdt:P1476 ?title.
  FILTER REGEX(LCASE(?title), "habitat").

  ?item wdt:P921 ?topic.
  ?topic wdt:P171 ?topicparent .
  ?topicparent wdt:P105 wd:Q34740 .
  ?topicparent wdt:P225 ?taxonname .
  FILTER NOT EXISTS { ?topic wdt:P2974 [] } .

}
GROUP BY ?topicparent ?taxonname
ORDER BY DESC(?count)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?count") v5("?item"):::projected v4("?page_title") v7("?taxonname"):::projected v3("?title") v2("?topic") v6("?topicparent"):::projected a1((" ")) c8(["www.wikidata.org"]):::literal c10(["habitat and haswbstatement:P31=Q13442814 -haswbstatement:P921=Q52105"]):::literal c4(["bd:serviceParam"]):::iri c18(["wd:Q34740"]):::iri c6(["Search"]):::literal c13(["habitat -and haswbstatement:P31=Q13442814 -haswbstatement:P921=Q52105"]):::literal c12(["mwapi:title"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"wdt:P2974"--> e0a1 e0v1("?topic"):::projected e0a1((" ")):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> a1 v2 --"wdt:P2974"--> a1 f1[["regex(lower-case(?title),'habitat')"]] f1 --> v3 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c4 --"mwapi:api"--> c6 c4 --"mwapi:endpoint"--> c8 c4 --"mwapi:srsearch"--> c13 v4 --"mwapi:apiOutput"--> c12 end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c4 --"mwapi:api"--> c6 c4 --"mwapi:endpoint"--> c8 c4 --"mwapi:srsearch"--> c10 v4 --"mwapi:apiOutput"--> c12 end end union0r <== or ==> union0l end bind2[/"concat(str('wd:'),?page_title)"/] v4 --o bind2 bind2 --as--o v5 v5 --"wdt:P1476"--> v3 v5 --"wdt:P921"--> v2 v2 --"wdt:P171"--> v6 v6 --"wdt:P105"--> c18 v6 --"wdt:P225"--> v7 bind4[/"count(?item)"/] v5 --o bind4 bind4 --as--o v8