query-42ee45f1f12c762571d26efae41cd2f6
Query to find all instances of spacecraft (Q40218) or it's sub-classesI tried this } } "en" language:wikibase serviceParam:bd{ label:wikibase SERVICE } ?linkTo P31:wdt ?item { OPTIONAL Q40218:wd P31:wdt ?item { ?itemLabel ?item DISTINCT SELECT (Q54384)Discovery But it does not include (Q40218)spacecraft which is not an instance of (Q1064394)Space Shuttle orbiter but it also includes (Q54384)Discovery This does include } } "en" language:wikibase serviceParam:bd{ label:wikibase SERVICE } ?linkTo P31:wdt ?item { OPTIONAL Q40218:wd )P279:wdt*/P31:wdt( ?item { ?itemLabel ?item DISTINCT SELECT 21:46, 15 September 2019 (UTC)) talk (Iwan.AucampPlease help. SothoTalKer on irc helped me, this works, 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 bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel {
?item (wdt:P31/wdt:P279*) wd:Q40218
OPTIONAL { ?item wdt:P31 ?linkTo }
SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?item"):::projected
v2("?linkTo")
a1((" "))
c3(["wd:Q40218"]):::iri
c5(["bd:serviceParam"]):::iri
c7(["en"]):::literal
v1 --"wdt:P31"--> a1
a1 --"wdt:P279"--> c3
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P31".-> v2
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c5 --"wikibase:language"--> c7
end