query-4e3c1c967fcc45c755d70288cfbac1e4

rq turtle/ttl

Images of sailboatsSPARQL Query to view images of sailboats SPARQL Query to view images of sailboats

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#>
#ImageGrid of all sailboats (Q1075310)
#boat = wikidata item id (qid)
#boatLabel = wikidata item name
#home_portLabel (optional) = home port name
#boat_name (optional) = boat name
#image (optional) = picture

#defaultView:ImageGrid
SELECT DISTINCT ?boat ?boatLabel ?boat_name ?instance_ofLabel ?home_portLabel ?image WHERE {
  ?boat wdt:P31/wdt:P279* wd:Q1075310; #'?boat' are 'instance of'(P31) and any number of 'subclass of' (P279*) of 'sailboat'(Q1075310)
        wdt:P31 ?instance_of. #'?boat' 'instance of' (P31) are '?instance_of'

  OPTIONAL { ?boat wdt:P18 ?image . } 

  #'?boat' 'home port' (P504) are '?home_port'
  OPTIONAL {
    ?boat wdt:P504 ?home_port . 
    #filter out home ports that are no longer current (home port (P504) with an 'end time' qualifier (P582))
    ?boat p:P504 ?statement1 .
    ?statement1 ps:P504 ?home_port .
    FILTER NOT EXISTS { ?statement1 pq:P582 ?x }
    ?home_port wdt:P625 ?home_port_coord. #'?home_port' 'coordinate location' (P625) are '?home_port_coord'
    }

  #'?boat" 'short name' (P1813) are '?boat_name'
  OPTIONAL {
    ?boat wdt:P1813 ?boat_name.
    #filter out names that are no longer current (short name (P1813) with an 'end time' qualifier (P582))
    ?boat p:P1813 ?statement2 .
    ?statement2 ps:P1813 ?boat_name .
    FILTER NOT EXISTS { ?statement2 pq:P582 ?x } 
    }  

  #xxxLabel is the label for any variable called xxx
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?boat"):::projected v9("?boat_name"):::projected v7("?home_port") v8("?home_port_coord") v6("?image"):::projected v5("?instance_of") v3("?statement1") v1("?statement2") v2("?x") a1((" ")) c4(["wd:Q1075310"]):::iri c14(["bd:serviceParam"]):::iri c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal v4 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c4 v4 --"p:direct/P31"--> v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P18".-> v6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P504".-> v7 v4 --"p:P504"--> v3 v3 --"p:statement/P504"--> v7 v7 --"p:direct/P625"--> v8 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P1813".-> v9 v4 --"p:P1813"--> v1 v1 --"p:statement/P1813"--> v9 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 end