query-14e604685f9a961e985282b6c9145b16
TODO: this returns the German registries repeated many times because the two OPTIONAL "?jur1, ?jur2" cause a Cartesian Explosion. So I need to use UNION inside OPTIONAL. But I can't force it to first bind "?item, ?stat" even if I use a subquery:
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
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 ?co ?jurLabel ?ral ?item ?itemLabel WHERE {
{select * {?item p:P9487 ?stat. ?stat ps:P9487 ?ral} }
optional {?item wdt:P17/wdt:P297 ?co}
optional {
{?stat pq:P1001 ?jur1} union {?item wdt:P1001 ?jur2}
bind(coalesce(?jur1,?jur2) as ?jur)
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,bg,no,nn,nb" } .
} order by ?co ?jurLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?co"):::projected
v3("?item"):::projected
v8("?jur")
v6("?jur1")
v7("?jur2")
v2("?jurLabel"):::projected
v5("?ral"):::projected
v4("?stat")
a1((" "))
c8(["bd:serviceParam"]):::iri
c10(["en,bg,no,nn,nb"]):::literal
v3 --"p:P9487"--> v4
v4 --"p:statement/P9487"--> v5
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P17".-> a1
a1 --"p:direct/P297"--> v1
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v3 -."p:direct/P1001".-> v7
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v4 --"p:qualifier/P1001"--> v6
end
union0r <== or ==> union0l
end
bind0[/"?jur1?jur2"/]
v6 --o bind0
v7 --o bind0
bind0 --as--o v8
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end