query-fe25f4d0bee342322f711637f228bec5
Museums in the historic county of Kent. Rather than assume every museum has that defined, I try to infer it from administrative area, but hit the problem that London has lots of museums, and London includes part of Kent, so not only do I get London museums, I get them many times. How can I modify this query to pick up historical county if present, and only deduce it if not, and filter down to one value? (P7959)historic county I want to generate a complete list of museums (and other historical things) across the UK, and a convenient partioning is the
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 psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?organisation ?organisationLabel ?location ?locationLabel ?county ?countyLabel WHERE {
?organisation wdt:P131 ?location;
wdt:P31 wd:Q33506.
?location wdt:P7959 ?county;
wdt:P7959 wd:Q67479626.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
MINUS {
?organisation p:P576 ?statement_2.
?statement_2 psv:P576 ?statementValue_2.
?statementValue_2 wikibase:timeValue ?P576_2.
}
MINUS {
?organisation p:P3999 ?statement_3.
?statement_3 psv:P3999 ?statementValue_3.
?statementValue_3 wikibase:timeValue ?P3999_2.
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v9("?P3999_2")
v6("?P576_2")
v3("?county"):::projected
v2("?location"):::projected
v1("?organisation"):::projected
v5("?statementValue_2")
v8("?statementValue_3")
v4("?statement_2")
v7("?statement_3")
c5(["wd:Q67479626"]):::iri
c3(["wd:Q33506"]):::iri
c7(["bd:serviceParam"]):::iri
c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal
v1 --"p:direct/P131"--> v2
v1 --"p:direct/P31"--> c3
v2 --"p:direct/P7959"--> v3
v2 --"p:direct/P7959"--> c5
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c7 --"wikibase:language"--> c9
end
subgraph minus0["MINUS"]
style minus0 stroke-width:6px,fill:pink,stroke:red;
v1 --"p:P576"--> v4
v4 --"p:statement/value/P576"--> v5
v5 --"wikibase:timeValue"--> v6
end
subgraph minus1["MINUS"]
style minus1 stroke-width:6px,fill:pink,stroke:red;
v1 --"p:P3999"--> v7
v7 --"p:statement/value/P3999"--> v8
v8 --"wikibase:timeValue"--> v9
end