query-4ae60aeed382e8f035dae4f4e91ddc95
TODO
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 ?skip ?skipLabel ?tatt_i_bruk WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?skip wdt:P31 wd:Q11446. # find a ?skip which is a ship
?skip wdt:P17 wd:Q20. # ?skip has country Norway
OPTIONAL { ?skip wdt:P729 ?tatt_i_bruk. } # optionally it has a P729 date
# but we really want to use the
# ?service_entry date which we find
# below and which is the
# 1939-46 date-delimited P729
# so this line is not needed
{?item wdt:729 ?service_entry . FILTER ((year(?service_entry) > 1939) && ( year(?servic_entry) < 1946 )) } # find an *unrelated* ?item with
# a P729 date
# also ?servic_entry typo would
# bork the filter
UNION
{?item wdt:P730 ?service_end . FILTER ((year(?service_end) > 1939 ) && (year(?service_end) < 1946 )) } # or with a P730 date
# so the query looks at ALL items
# and times out because hamster exhaustion
# you really wanted to find the P729
# of the *** ?skip *** here
# and P730 has nothing to do with
# date built. More like date sunk.
OPTIONAL {?item wdt:729 ?service_entry } . # you have already found ?service_entry
# in the UNIONed lines above
OPTIONAL {?item wdt:730 ?service_end } . # ditto service_end ... you do not need
# to find them again, even if you
# ever needed P730, which you did not.
BIND( IF (bound(?service_entry) && !isBlank(?service_entry) , year(?service_entry) , year(?service_end) - 40) AS ?order_date) .
# this is all about setting ?order_date
# but you do not use ?order date anywhere
# in the query
}
LIMIT 10000 # Harmless, but 10k ships in 6/7 years?
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?item")
v7("?order_date")
v4("?servic_entry")
v6("?service_end")
v3("?service_entry")
v1("?skip"):::projected
v2("?tatt_i_bruk"):::projected
c8(["wd:Q20"]):::iri
c2(["bd:serviceParam"]):::iri
c4(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c6(["wd:Q11446"]):::iri
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c2 --"wikibase:language"--> c4
end
v1 --"wdt:P31"--> c6
v1 --"wdt:P17"--> c8
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P729".-> v2
end
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
f0[["year-from-dateTime(?service_end) > '1939^^xsd:integer'year-from-dateTime(?service_end) < '1946^^xsd:integer'"]]
f0 --> v6
v5 --"wdt:P730"--> v6
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
f1[["year-from-dateTime(?service_entry) > '1939^^xsd:integer'year-from-dateTime(?servic_entry) < '1946^^xsd:integer'"]]
f1 --> v3
f1 --> v4
v5 --"wdt:729"--> v3
end
union0r <== or ==> union0l
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v5 -."wdt:729".-> v3
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v5 -."wdt:730".-> v6
end
bind2[/"if(bound(?service_entry)not isBlank(?service_entry),year-from-dateTime(?service_entry),year-from-dateTime(?service_end) - '40^^xsd:integer')"/]
v3 --o bind2
v6 --o bind2
bind2 --as--o v7