query-5830dab1c6c5a93872f7c2f819cf361b

rq turtle/ttl

Using qualifier as optional valueI've made this query to list all ships built in Japan with shipbreaking and/or shipwrecking as significant events. I also want to list the date and the place, which means I have to fetch the qualifiers:

Use at

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 DISTINCT ?item ?itemLabel ?yardLabel ?date ?placeLabel ?eventLabel WHERE {
  { ?item wdt:P793 wd:Q336332. }
  UNION
  { ?item wdt:P793 wd:Q906512. }
  ?item wdt:P176 ?yard.
  ?yard wdt:P17 wd:Q17.
  ?item (wdt:P31/(wdt:P279*)) wd:Q11446;
    p:P793 _:b1.
  _:b1 ps:P793 ?event;
    pq:P276 ?place;
    pq:P585 ?date.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  FILTER(?event IN(wd:Q336332, wd:Q906512))
}
ORDER BY (?yard)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?date"):::projected v2("?event") v3("?item"):::projected v4("?place") v1("?yard") a2((" ")) a1((" ")) c1(["wd:Q336332"]):::iri c17(["en"]):::literal c6(["wd:Q17"]):::iri c15(["bd:serviceParam"]):::iri c2(["wd:Q906512"]):::iri c9(["wd:Q11446"]):::iri list0c1(["wd:Q336332"]):::iri list0c2(["wd:Q906512"]):::iri list0c1 --o f0 list0c2 --o f0 f0[[" in "]] f0 --> v2 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P793"--> c2 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P793"--> c1 end union0r <== or ==> union0l end v3 --"p:direct/P176"--> v1 v1 --"p:direct/P17"--> c6 v3 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c9 v3 --"p:P793"--> a2 a2 --"p:statement/P793"--> v2 a2 --"p:qualifier/P276"--> v4 a2 --"p:qualifier/P585"--> v5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c15 --"wikibase:language"--> c17 end