query-29d85fb29389af8ad30f677c563c55c1
Twice-broken lighthouse colour query 18:05, 5 January 2018 (UTC)) talk (TagishsimonThis query has (at least) two faults: it miscounts the number of colours possessed by the lighthouse item; and when the filter is applied, fails to find a lighthouse that has a colour with no P518 qualifier. If anyone would like to explain the query's failings to me, I'd be grateful. I was kinda expecting that the query would find & hence count only combinations of lighthouse-colour-noP518 ... it has other ideas. Thanks --
Use at
- https://query.wikidata.org/sparql
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 (count(?colour) as ?count) WHERE {
?item wdt:P31 wd:Q39715 . #instance of lighthouse
?item wdt:P17 wd:Q34 . #country of Sweden
?item wdt:P462 ?colour . #must have a colour
OPTIONAL {?item p:P462 ?mem . #item has a colour
?mem ps:P462 ?colour2; pq:P518 ?qual . } # colour has a P518 qualifier
FILTER(!BOUND(?qual)) # qualifier is null
SERVICE wikibase:label { bd:serviceParam wikibase:language "se,en,fr,nl,de,it,es". }
values ?value {wd:Q40125473}
filter(?item=?value)
}
group by ?item ?itemLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?colour"):::projected
v6("?colour2")
v7("?count")
v1("?item"):::projected
v5("?mem")
v3("?qual")
v7("?value")
c10(["bd:serviceParam"]):::iri
c2(["wd:Q39715"]):::iri
c12(["se,en,fr,nl,de,it,es"]):::literal
c4(["wd:Q34"]):::iri
f0[["?item = ?value"]]
f0 --> v1
f0 --> v7
f1[["not bound(?qual)"]]
f1 --> v3
v1 --"p:direct/P31"--> c2
v1 --"p:direct/P17"--> c4
v1 --"p:direct/P462"--> v4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:P462".-> v5
v5 --"p:statement/P462"--> v6
v5 --"p:qualifier/P518"--> v3
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c10 --"wikibase:language"--> c12
end
bind2[/VALUES ?value/]
bind2-->v7
bind20(["wd:Q40125473"])
bind20 --> bind2
bind4[/"count(?colour)"/]
v4 --o bind4
bind4 --as--o v7