query-d4e1cdb5c73d5c726a1e2434e4734dfd

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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map
SELECT  ?employer ?employerLabel ?item ?itemLabel ?coord ?layer ?startyear ?length {
  ?item p:P106 ?wir .
  ?wir ps:P106 wd:Q3809586 .
  OPTIONAL { ?wir pq:P582 ?end . ?wir pqv:P582 [ wikibase:timePrecision ?tp_end]  }
  OPTIONAL { ?wir pq:P580 ?start . ?wir pqv:P580 [ wikibase:timePrecision ?tp_start] }
#  BIND(CONCAT('duration:', STR(MONTH(?end-?start)), 'months') AS ?length) # <- how would one calculate the duration of ?end-?start`
   BIND(IF(?tp_end=?tp_start,CONCAT('duration:', STR(12*(YEAR(?end)-YEAR(?start))+MONTH(?end)-MONTH(?start)), ' months'),'duration: not possible to calculate') AS ?length) # NOTE if end and start dates dont have the same precision, you may get strange results like -3 months if you just use the formula 
  BIND(IF(!BOUND(?end),   'no end date',   CONCAT('end: ',   STR(YEAR(?end))))   AS ?layer)
  BIND(IF(!BOUND(?start), 'no start date', CONCAT('start: ', STR(YEAR(?start)))) AS ?startyear)
  OPTIONAL { ?wir pq:P937 ?location. ?location wdt:P625 ?coord. }
  OPTIONAL { ?wir pq:P108 ?employer }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?end)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v11("?coord"):::projected v12("?employer"):::projected v1("?end") v2("?item"):::projected v8("?layer"):::projected v7("?length"):::projected v10("?location") v5("?start") v9("?startyear"):::projected v4("?tp_end") v6("?tp_start") v3("?wir") a1((" ")) a2((" ")) c13(["bd:serviceParam"]):::iri c15(["#91;AUTO_LANGUAGE#93;,en"]):::literal c3(["wd:Q3809586"]):::iri v2 --"p:P106"--> v3 v3 --"p:statement/P106"--> c3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P582".-> v1 a1 --"wikibase:timePrecision"--> v4 v3 --"p:qualifier/value/P582"--> a1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P580".-> v5 a2 --"wikibase:timePrecision"--> v6 v3 --"p:qualifier/value/P580"--> a2 end bind0[/"if(?tp_end = ?tp_start,concat('duration:',str('12^^xsd:integer' * year-from-dateTime(?end) - year-from-dateTime(?start) + month-from-dateTime(?end) - month-from-dateTime(?start)),' months'),'duration: not possible to calculate')"/] v4 --o bind0 v6 --o bind0 v1 --o bind0 v5 --o bind0 bind0 --as--o v7 bind1[/"if(not bound(?end),'no end date',concat('end: ',str(year-from-dateTime(?end))))"/] v1 --o bind1 bind1 --as--o v8 bind2[/"if(not bound(?start),'no start date',concat('start: ',str(year-from-dateTime(?start))))"/] v5 --o bind2 bind2 --as--o v9 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P937".-> v10 v10 --"p:direct/P625"--> v11 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P108".-> v12 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c13 --"wikibase:language"--> c15 end