query-77b878a22e9ac81bdf553929adeb16b9

rq turtle/ttl

or

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#>
SELECT distinct ?organisation ?organisationLabel ?location ?locationLabel ?tag
WHERE {
  { ?organisation wdt:P31/wdt:P279* wd:Q33506 .
    ?organisation wdt:P131 ?location .
    ?organisation wdt:P7959 wd:Q67479626 . 
    bind("Kent (stated on item)" as ?tag) .
  } # option A, it's in the historic county
  union
  { ?organisation wdt:P31/wdt:P279* wd:Q33506 .
    ?organisation wdt:P131 ?location . ?location wdt:P7959 wd:Q67479626 . 
    filter not exists { ?organisation wdt:P7959 wd:Q67479626 } . # not option A
    filter not exists { ?location wdt:P7959 ?elsewhere . filter (?elsewhere != wd:Q67479626) } # not option C
    bind("Kent (deduced via location)" as ?tag) .
  } # option B, it's in somewhere in historic Kent but not tagged as Kent itself, and no other historic county
  union
  { ?organisation wdt:P31/wdt:P279* wd:Q33506 .
    ?organisation wdt:P131 ?location . ?location wdt:P7959 wd:Q67479626 . 
    ?location wdt:P7959 ?elsewhere . filter (?elsewhere != wd:Q67479626) .
    filter not exists { ?organisation wdt:P7959 wd:Q67479626 } . # not option A
    bind("Maybe (location is somewhere which was partly in Kent)" as ?tag) 
  } # option C, it's in somewhere in historic Kent and another historic county

  filter not exists { ?organisation wdt:P576 ?closed }
  filter not exists { ?organisation wdt:P3999 ?closed }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en-gb,en,mul". }

} order by ?organisationLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?closed") v6("?elsewhere") v4("?location"):::projected v2("?organisation"):::projected v1("?organisationLabel"):::projected v7("?tag"):::projected a1((" ")) a2((" ")) a3((" ")) c8(["wd:Q67479626"]):::iri c12(["en-gb,en,mul"]):::literal c5(["wd:Q33506"]):::iri c10(["bd:serviceParam"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"wdt:P3999"--> e0v2 e0v2("?closed"):::projected e0v1("?organisation"):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> v3 v2 --"wdt:P3999"--> v3 f1[["not "]] subgraph f1e1["Exists Clause"] e1v1 --"wdt:P576"--> e1v2 e1v2("?closed"):::projected e1v1("?organisation"):::projected end f1--EXISTS--> f1e1 f1 --> v2 f1 --> c2 f1 --> v3 v2 --"wdt:P576"--> v3 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; f2[["not "]] subgraph f2e2["Exists Clause"] e2v1 --"wdt:P7959"--> e2c2 e2v1("?organisation"):::projected e2c2(["wd:Q67479626"]):::iri end f2--EXISTS--> f2e2 f2 --> v2 f2 --> c7 f2 --> c8 v2 --"wdt:P7959"--> c8 f3[["?elsewhere != 'wd:Q67479626'"]] f3 --> v6 v2 --"wdt:P31"--> a3 a3 --"wdt:P279"--> c5 v2 --"wdt:P131"--> v4 v4 --"wdt:P7959"--> c8 v4 --"wdt:P7959"--> v6 bind4[/"'Maybe (location is somewhere which was partly in Kent)'"/] bind4 --as--o v7 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; f5[["not "]] subgraph f5e3["Exists Clause"] e3f0[["?elsewhere != 'wd:Q67479626'"]] e3f0 --> e3v1 e3v2 --"wdt:P7959"--> e3v1 e3v1("?elsewhere"):::projected e3v2("?location"):::projected end f5--EXISTS--> f5e3 f5 --> v6 f5 --> v4 f5 --> c7 f6[["?elsewhere != 'wd:Q67479626'"]] f6 --> v6 v4 --"wdt:P7959"--> v6 f7[["not "]] subgraph f7e4["Exists Clause"] e4v1 --"wdt:P7959"--> e4c2 e4v1("?organisation"):::projected e4c2(["wd:Q67479626"]):::iri end f7--EXISTS--> f7e4 f7 --> v2 f7 --> c7 f7 --> c8 v2 --"wdt:P7959"--> c8 v2 --"wdt:P31"--> a2 a2 --"wdt:P279"--> c5 v2 --"wdt:P131"--> v4 v4 --"wdt:P7959"--> c8 bind8[/"'Kent (deduced via location)'"/] bind8 --as--o v7 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c5 v2 --"wdt:P131"--> v4 v2 --"wdt:P7959"--> c8 bind9[/"'Kent (stated on item)'"/] bind9 --as--o v7 end union0r <== or ==> union0l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end