query-a3b61e8185913030dacc370036b5f3a5

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?label ?type ?subtypeLabel ?keywords ?properties ?position ?start ?end ?image ?notes WHERE {
SERVICE wikibase:label {bd:serviceParam wikibase:language "en-GB,en,fr,de,es,pt,pl,nl,cs".}
{
SELECT DISTINCT ?item ?type (MIN(?starts) as ?start) (MAX(?ends) AS ?end) 
  (GROUP_CONCAT(DISTINCT ?noteslist; SEPARATOR = ", ") AS ?notes)
  (GROUP_CONCAT(DISTINCT ?keywordlist; SEPARATOR = ", ") AS ?keywords)
  (GROUP_CONCAT(DISTINCT ?propertylist; SEPARATOR = ", ") AS ?properties)
  (SAMPLE (?positions) AS ?position)
  (COALESCE(SAMPLE(?specialimagelist),SAMPLE (?standardimagelist)) AS ?image)
  (COALESCE(SAMPLE(?labellist),?label_) AS ?label)
#  (SAMPLE (DISTINCT ?subtypes) AS ?subtype) WHERE {
  (COALESCE(SAMPLE (DISTINCT ?sta), SAMPLE (DISTINCT ?stb)) AS ?subtype) WHERE {
VALUES ?props {
  wdt:P137  # operator
  wdt:P88   # commissioned by
  wdt:P176  # manufacturer
  wdt:P361  # part of
  wdt:P1343 # described by source
}

VALUES ?st1 { 
  wd:Q18758641 # watercraft class
}
VALUES ?st2 {
  wd:Q57821    # fortification
  wd:Q177597   # naval vessel
}
VALUES ?st3 {
  wd:Q728      # weapon  
  wd:Q1184840  # military vehicle
  wd:Q216916   # military aircraft
}
VALUES ?st4 {
  wd:Q234137   # castle
}
{?item ?props wd:Q112737775}
UNION {?register wdt:P2378 wd:Q112737775.
  ?register wikibase:directClaim ?registerwdt.
  ?item ?registerwdt ?value}

     {?item wdt:P31/wdt:P279 ?st1. BIND(?st1 as ?sta) }
UNION {?item wdt:P31/wdt:P279* ?st2. BIND(?st2 as ?stb) }
UNION {?item wdt:P279* ?st3. }
UNION {?item wdt:P31/wdt:P279* ?st4. 
       ?item wdt:P3134 ?t} # tripadvisor
#FILTER ((BOUND (?sta) && ?sta = ?st1)||(BOUND (?stb) && ?stb = ?st2)||(BOUND (?stc) && ?stc = ?st3)||(BOUND (?std) && ?std = ?st4))

#?note rdfs:label ?notelabel. FILTER (LANG(?notelabel) = "en") # times out
#BIND(CONCAT("{","{Q|",STR(?notelabel),"|",STR(?note),"}","}") as ?noteslist)
#BIND(IF(BOUND(?notelabel),CONCAT("{","{Q|",STR(?notelabel),"|",STR(?note),"}","}"),"") AS ?noteslist)

OPTIONAL { {?item wdt:P279 ?k} UNION {?item wdt:P137 ?t. ?t wdt:P17 ?k} UNION {?item wdt:P17 ?k} 
UNION {?item wdt:P31 ?k} UNION {?item wdt:P279 ?k} UNION {?item wdt:P176 ?k}
  ?k rdfs:label ?keywordlist. FILTER (LANG(?keywordlist) = "en")}

OPTIONAL {
        {?item wdt:P3134 ?t. BIND(CONCAT("[https://www.tripadvisor.com/",?t," tripadvisor]") AS ?propertylist)}
  UNION {?item wdt:P2671 ?g. BIND(CONCAT("[https://www.google.com/search?kgmid£",STR(?g)," google]") AS ?propertylist)} # Google knowledge graph ID
}

OPTIONAL {?item wdt:P625 ?p1}
OPTIONAL {?item wdt:P276 ?l2. ?l2 wdt:P625 ?p2}
OPTIONAL {?item wdt:P131 ?l3. ?l3 wdt:P625 ?p3}
#OPTIONAL {?item wdt:P495 ?origin. ?origin wdt:P625 ?p4}
#OPTIONAL {?item wdt:P176 ?manu. ?manu wdt:P159 ?l4. ?l4 wdt:P625 ?p4}
#OPTIONAL {?item wdt:P17  ?l5. ?l5 wdt:P625 ?p5}
BIND(COALESCE(?p1,?p2,?p3) AS ?positions)

OPTIONAL {?item wdt:P729 ?serviceentry}
OPTIONAL {?item wdt:P571 ?inception}
OPTIONAL {?item wdt:P585 ?pointintime}
OPTIONAL {?item wdt:P580 ?starttime}
BIND(COALESCE(?awarded,?serviceentry,?inception,?pointintime,?starttime) AS ?starts)

OPTIONAL {?item wdt:P730 ?serviceretirement}
OPTIONAL {?item wdt:P576 ?abolished}
OPTIONAL {?item wdt:P582 ?endtime}
BIND(COALESCE(?serviceretirement,?abolished,?pointintime,?endtime) as ?ends)

OPTIONAL { {?item wdt:P18 ?images} BIND (wikibase:decodeUri(STR(?images)) AS ?specialimagelist)} # image

OPTIONAL {?item wdt:P1448 ?labellist. FILTER (lang(?labellist) = "mul")} # official name
{SERVICE wikibase:label {bd:serviceParam wikibase:language "en" . ?item rdfs:label ?label_ .}
  }
    }
    #GROUP by ?item ?starts ?ends ?dist ?label ?type
    GROUP by ?item ?dist ?label_ ?type
  }
}
ORDER BY ASC(?dist) ASC(?label)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v40("?_anon_42b5416610844a34809f33a099ae9de1117295") v41("?_anon_42b5416610844a34809f33a099ae9de1117296") v42("?_anon_42b5416610844a34809f33a099ae9de1117297") v43("?_anon_42b5416610844a34809f33a099ae9de1117298") v44("?_anon_42b5416610844a34809f33a099ae9de1117299") v32("?abolished") v1("?dist") v46("?end"):::projected v34("?ends") v33("?endtime") v19("?g") v51("?image"):::projected v35("?images") v27("?inception") v10("?item"):::projected v17("?k") v4("?keywordlist") v48("?keywords"):::projected v21("?l2") v23("?l3") v52("?label"):::projected v37("?label_") v3("?labellist") v47("?notes"):::projected v38("?noteslist") v20("?p1") v22("?p2") v24("?p3") v28("?pointintime") v50("?position"):::projected v25("?positions") v49("?properties"):::projected v20("?propertylist") v5("?props") v11("?register") v12("?registerwdt") v26("?serviceentry") v31("?serviceretirement") v36("?specialimagelist") v6("?st1") v7("?st2") v8("?st3") v9("?st4") v14("?sta") v39("?standardimagelist") v45("?start"):::projected v30("?starts") v29("?starttime") v15("?stb") v52("?subtype") v16("?t") v13("?value") a1((" ")) a2((" ")) a3((" ")) c4(["en-GB,en,fr,de,es,pt,pl,nl,cs"]):::literal c2(["bd:serviceParam"]):::iri c6(["en"]):::literal c7(["wd:Q112737775"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end bind0[/VALUES ?props/] bind0-->v5 bind00(["wdt:P137"]) bind00 --> bind0 bind01(["wdt:P88"]) bind01 --> bind0 bind02(["wdt:P176"]) bind02 --> bind0 bind03(["wdt:P361"]) bind03 --> bind0 bind04(["wdt:P1343"]) bind04 --> bind0 bind1[/VALUES ?st1/] bind1-->v6 bind10(["wd:Q18758641"]) bind10 --> bind1 bind2[/VALUES ?st2/] bind2-->v7 bind20(["wd:Q57821"]) bind20 --> bind2 bind21(["wd:Q177597"]) bind21 --> bind2 bind3[/VALUES ?st3/] bind3-->v8 bind30(["wd:Q728"]) bind30 --> bind3 bind31(["wd:Q1184840"]) bind31 --> bind3 bind32(["wd:Q216916"]) bind32 --> bind3 bind4[/VALUES ?st4/] bind4-->v9 bind40(["wd:Q234137"]) bind40 --> bind4 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v11 --"wdt:P2378"--> c7 v11 --"wikibase:directClaim"--> v12 v10 -->v12--> v13 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v10 -->v5--> c7 end union0r <== or ==> union0l end subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P31"--> a3 a3 --"wdt:P279"--> v9 v10 --"wdt:P3134"--> v16 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P279"--> v8 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P31"--> a2 a2 --"wdt:P279"--> v7 bind5[/"?st2"/] v7 --o bind5 bind5 --as--o v15 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P31"--> a1 a1 --"wdt:P279"--> v6 bind6[/"?st1"/] v6 --o bind6 bind6 --as--o v14 end union1r <== or ==> union1l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union4[" Union "] subgraph union4l[" "] style union4l fill:#abf,stroke-dasharray: 3 3; subgraph union5[" Union "] subgraph union5l[" "] style union5l fill:#abf,stroke-dasharray: 3 3; subgraph union6[" Union "] subgraph union6l[" "] style union6l fill:#abf,stroke-dasharray: 3 3; subgraph union7[" Union "] subgraph union7l[" "] style union7l fill:#abf,stroke-dasharray: 3 3; subgraph union8[" Union "] subgraph union8l[" "] style union8l fill:#abf,stroke-dasharray: 3 3; v10 -."wdt:P176".-> v17 end subgraph union8r[" "] style union8r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P279"--> v17 end union8r <== or ==> union8l end end subgraph union7r[" "] style union7r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P31"--> v17 end union7r <== or ==> union7l end end subgraph union6r[" "] style union6r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P17"--> v17 end union6r <== or ==> union6l end end subgraph union5r[" "] style union5r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P137"--> v16 v16 --"wdt:P17"--> v17 end union5r <== or ==> union5l end end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P279"--> v17 end union4r <== or ==> union4l end v17 --"rdfs:label"--> v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; subgraph union9[" Union "] subgraph union9l[" "] style union9l fill:#abf,stroke-dasharray: 3 3; v10 -."wdt:P2671".-> v19 bind7[/"concat('#91;https://www.google.com/search?kgmid£',str(?g),' google#93;')"/] v19 --o bind7 bind7 --as--o v20 end subgraph union9r[" "] style union9r fill:#abf,stroke-dasharray: 3 3; v10 --"wdt:P3134"--> v16 bind8[/"concat('#91;https://www.tripadvisor.com/',?t,' tripadvisor#93;')"/] v16 --o bind8 bind8 --as--o v20 end union9r <== or ==> union9l end end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P625".-> v20 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P276".-> v21 v21 --"wdt:P625"--> v22 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P131".-> v23 v23 --"wdt:P625"--> v24 end bind9[/"?p1?p2?p3"/] v20 --o bind9 v22 --o bind9 v24 --o bind9 bind9 --as--o v25 subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P729".-> v26 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P571".-> v27 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P585".-> v28 end subgraph optional8["(optional)"] style optional8 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P580".-> v29 end bind10[/"?awarded?serviceentry?inception?pointintime?starttime"/] null --o bind10 v26 --o bind10 v27 --o bind10 v28 --o bind10 v29 --o bind10 bind10 --as--o v30 subgraph optional9["(optional)"] style optional9 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P730".-> v31 end subgraph optional10["(optional)"] style optional10 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P576".-> v32 end subgraph optional11["(optional)"] style optional11 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P582".-> v33 end bind11[/"?serviceretirement?abolished?pointintime?endtime"/] v31 --o bind11 v32 --o bind11 v28 --o bind11 v33 --o bind11 bind11 --as--o v34 subgraph optional12["(optional)"] style optional12 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P18".-> v35 bind12[/"http://wikiba.se/ontology#decodeUri(str(?images))"/] v35 --o bind12 bind12 --as--o v36 end subgraph optional13["(optional)"] style optional13 fill:#bbf,stroke-dasharray: 5 5; v10 -."wdt:P1448".-> v3 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c6 v10 --"rdfs:label"--> v37 end bind24[/"sample(?specialimagelist)"/] v36 --o bind24 bind24 --as--o v40 bind25[/"sample(?standardimagelist)"/] v39 --o bind25 bind25 --as--o v41 bind26[/"sample(?labellist)"/] v3 --o bind26 bind26 --as--o v42 bind27[/"sample(?sta)"/] v14 --o bind27 bind27 --as--o v43 bind28[/"sample(?stb)"/] v15 --o bind28 bind28 --as--o v44 bind29[/"min(?starts)"/] v30 --o bind29 bind29 --as--o v45 bind30[/"max(?ends)"/] v34 --o bind30 bind30 --as--o v46 bind31[/"?noteslist"/] v38 --o bind31 bind31 --as--o v47 bind32[/"?keywordlist"/] v4 --o bind32 bind32 --as--o v48 bind33[/"?propertylist"/] v20 --o bind33 bind33 --as--o v49 bind34[/"sample(?positions)"/] v25 --o bind34 bind34 --as--o v50 bind35[/""/] null --o bind35 null --o bind35 bind35 --as--o v51 bind36[/"?label_"/] null --o bind36 v37 --o bind36 bind36 --as--o v52 bind37[/""/] null --o bind37 null --o bind37 bind37 --as--o v52