query-9d39ef6d8939d48e4008a470454e30f0

rq turtle/ttl

TODO

Use at

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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel (sum(?number) as ?count)
WHERE 
{
  VALUES ?item {wd:Q831870 wd:Q3414614 wd:Q2352641 wd:Q3053508 }
  ?item p:P870 ?stat.
#  ?stat ps:P870 ?instrument.
  OPTIONAL {?stat pq:P1132 ?no1.}
  OPTIONAL {?stat pq:P1114 ?no2.}
  BIND(COALESCE(?no2,?no1,1) as ?number)
  FILTER EXISTS {?item wdt:P870 wd:Q8355, wd:Q5994} # include music having violin and piano
#  FILTERĀ : NEED ADDITIONAL FILTER TO LIMIT RESULTS TO 2 TOTAL INSTRUMENTS IN THE ENSEMBLE  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?item ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?count") v2("?item"):::projected v3("?no1") v4("?no2") v5("?number"):::projected v2("?stat") c2(["wd:Q8355"]):::iri c8(["bd:serviceParam"]):::iri c3(["wd:Q5994"]):::iri c10(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[[" "]] subgraph f0e0["Exists Clause"] e0v1 --"p:direct/P870"--> e0c2 e0v1 --"p:direct/P870"--> e0c3 e0v1("?item"):::projected e0c2(["wd:Q8355"]):::iri e0c3(["wd:Q5994"]):::iri end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> c2 f0 --> c3 v2 --"p:direct/P870"--> c2 v2 --"p:direct/P870"--> c3 bind1[/VALUES ?item/] bind1-->v2 bind10(["wd:Q831870"]) bind10 --> bind1 bind11(["wd:Q3414614"]) bind11 --> bind1 bind12(["wd:Q2352641"]) bind12 --> bind1 bind13(["wd:Q3053508"]) bind13 --> bind1 v2 --"p:P870"--> v2 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P1132".-> v3 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P1114".-> v4 end bind2[/"?no2?no1'1^^xsd:integer'"/] v4 --o bind2 v3 --o bind2 bind2 --as--o v5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end bind4[/"sum(?number)"/] v5 --o bind4 bind4 --as--o v6