query-fe4b65d7402754fc6fb4bc20ba3be8be
SPARQL code to find items in an arbitrary administrative unit, called Q800000000,
using the proposed qualifier, called P8000
SELECT ?item WHERE { VALUES ?searched_unit { wd:Q800000000 } { ?item wdt:P131 ?searched_unit . # located in the searched unit } MINUS { ?item wdt:P131/p:P131/pq:P8000 ?other_unit . # unless next level in hierarchy is a unit ?other_unit wdt:P131/^wdt:P131 ?searched_unit . # at same level in the hierarchy FILTER (?other_unit != ?searched_unit) # and different from the sought unit } }
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
# SPARQL code to find items in an arbitrary administrative unit, called Q800000000,
# using the proposed qualifier, called P8000
SELECT ?item
WHERE
{
VALUES ?searched_unit { wd:Q800000000 }
{
?item wdt:P131* ?searched_unit . # located in the searched unit
}
MINUS
{
?item wdt:P131*/p:P131/pq:P8000 ?other_unit . # unless next level in hierarchy is a unit
?other_unit wdt:P131/^wdt:P131 ?searched_unit . # at same level in the hierarchy
FILTER (?other_unit != ?searched_unit) # and different from the sought unit
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?item"):::projected
v3("?other_unit")
v1("?searched_unit")
a1((" "))
a2((" "))
a3((" "))
bind0[/VALUES ?searched_unit/]
bind0-->v1
bind00(["wd:Q800000000"])
bind00 --> bind0
v2 --"p:direct/P131"--> v1
subgraph minus1["MINUS"]
style minus1 stroke-width:6px,fill:pink,stroke:red;
f2[["?other_unit != ?searched_unit"]]
f2 --> v3
f2 --> v1
v2 --"p:direct/P131"--> a1
a1 --"p:P131"--> a2
a2 --"p:qualifier/P8000"--> v3
v3 --"p:direct/P131"--> a3
v1 --"p:direct/P131"--> a3
end