query-95d48d9f80ba72fed12c065bc5bb8ead

rq turtle/ttl

Search and update queries

Use at

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#>
#defaultView:Map
SELECT DISTINCT ?loc ?subj ?subjLabel ?startdt ?enddt ?linebusLabel ?didwhatLabel ?hplaceLabel ?adminLabel
WHERE
{
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
  VALUES ?bustypes {
    wd:Q4830453 wd:Q6881511
    wd:Q783794
    wd:Q22687
    wd:Q891723
    wd:Q16274795 wd:Q474200
  }
  {?subj wdt:P31/wdt:P279* ?bustypes} UNION {?subj wdt:P452 ?bustypes}.
  ###Scotland filter begins:
  VALUES ?scotmarks {wd:Q22 wd:Q15060255 }
  {?subj wdt:P131 ?scotmarks.}
  UNION {?subj wdt:P131 ?orgloc1. ?orgloc1 wdt:P31/wdt:P131 ?scotmarks.}
  UNION {?subj wdt:P159 ?orgpl. { ?orgpl wdt:P31/wdt:P131 ?scotmarks.} UNION {?orgpl wdt:P131 ?orgl2. ?orgl2 wdt:P31/wdt:P131 ?scotmarks.}.}.
  ###Scotland filter ends
  ?subj wdt:P571 ?startdt.
    FILTER (YEAR(?startdt) < 1920 && YEAR(?startdt) > 1300).
  ###Map locator begins:
  OPTIONAL {?subj wdt:P625 ?loc1}.
  OPTIONAL {?subj wdt:P159 ?orghq. ?orghq wdt:P625 ?hloc.}.
  OPTIONAL {?subj wdt:P131 ?orgwhere. ?orgwhere wdt:P625 ?aloc.}.
  BIND (IF(BOUND(?loc1),?loc1,IF(BOUND(?hloc),?hloc,IF (BOUND(?aloc),?aloc,?NULL))) AS ?loc).
  ###Map locator ends
  ?subj wdt:P31 ?linebus.
  OPTIONAL {?subj wdt:P576 ?enddt.}
  OPTIONAL {?subj wdt:P1056 ?didwhat.}

}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v12("?aloc") v2("?bustypes") v16("?didwhat") v15("?enddt"):::projected v10("?hloc") v14("?linebus") v13("?loc"):::projected v8("?loc1") v9("?orghq") v7("?orgl2") v5("?orgloc1") v6("?orgpl") v11("?orgwhere") v4("?scotmarks") v1("?startdt"):::projected v3("?subj"):::projected a1((" ")) a2((" ")) a3((" ")) a4((" ")) c4(["bd:serviceParam"]):::iri c6(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["year-from-dateTime(?startdt) < '1920^^xsd:integer'year-from-dateTime(?startdt) > '1300^^xsd:integer'"]] f0 --> v1 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c4 --"wikibase:language"--> c6 end bind1[/VALUES ?bustypes/] bind1-->v2 bind10(["wd:Q4830453"]) bind10 --> bind1 bind11(["wd:Q6881511"]) bind11 --> bind1 bind12(["wd:Q783794"]) bind12 --> bind1 bind13(["wd:Q22687"]) bind13 --> bind1 bind14(["wd:Q891723"]) bind14 --> bind1 bind15(["wd:Q16274795"]) bind15 --> bind1 bind16(["wd:Q474200"]) bind16 --> bind1 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P452"--> v2 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> a1 a1 --"wdt:P279"--> v2 end union0r <== or ==> union0l end bind2[/VALUES ?scotmarks/] bind2-->v4 bind20(["wd:Q22"]) bind20 --> bind2 bind21(["wd:Q15060255"]) bind21 --> bind2 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; v3 --"wdt:P159"--> v6 subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; v6 --"wdt:P131"--> v7 v7 --"wdt:P31"--> a4 a4 --"wdt:P131"--> v4 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v6 --"wdt:P31"--> a3 a3 --"wdt:P131"--> v4 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P131"--> v5 v5 --"wdt:P31"--> a2 a2 --"wdt:P131"--> v4 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P131"--> v4 end union1r <== or ==> union1l end v3 --"wdt:P571"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P625".-> v8 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P159".-> v9 v9 --"wdt:P625"--> v10 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P131".-> v11 v11 --"wdt:P625"--> v12 end bind3[/"if(bound(?loc1),?loc1,if(bound(?hloc),?hloc,if(bound(?aloc),?aloc,?NULL)))"/] v8 --o bind3 v10 --o bind3 v12 --o bind3 null --o bind3 bind3 --as--o v13 v3 --"wdt:P31"--> v14 subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P576".-> v15 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P1056".-> v16 end