query-6a3569eef220ca91cd7f1cbea62126f7

rq turtle/ttl

Russian districts). (Q7948)Kamchatka Krai -> (Q204809)Koryak Okrug -> (P131)located in the administrative territorial entity (which has the chain of properties (Q1042950)Tigilsky District , but it should also select entities such as (Q7948)Kamchatka Krai matches (P131)located in the administrative territorial entity I'm using this query to map Russian districts. Right now it only selects a district if

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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#>
SELECT ?id
  (if(BOUND(?link),
      concat('[[', substr(str(?link),31,500),  '|', ?idLabel, ']]'),
      ?idLabel)
   as ?title)
WHERE {
  ?id p:P31/ps:P31/wdt:P279* wd:Q1849719 .
  ?id p:P131 ?locst .
  ?locst ps:P131 wd:Q7948
  MINUS { ?locst pq:P582 [] }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language 'en' .
    ?id rdfs:label ?idLabel .
  }
  OPTIONAL {?link schema:about ?id .
  ?link schema:isPartOf <https://en.wikipedia.org/> . }
} GROUP BY ?id ?link ?idLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?id"):::projected v3("?idLabel"):::projected v4("?link"):::projected v2("?locst") v5("?title") a3((" ")) a1((" ")) a2((" ")) c4(["wd:Q1849719"]):::iri c7(["wd:Q7948"]):::iri c12(["en"]):::literal c16([https://en.wikipedia.org/]):::iri c10(["bd:serviceParam"]):::iri v1 --"p:P31"--> a1 a1 --"p:statement/P31"--> a2 a2 --"p:direct/P279"--> c4 v1 --"p:P131"--> v2 v2 --"p:statement/P131"--> c7 subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v2 --"p:qualifier/P582"--> a3 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 v1 --"rdfs:label"--> v3 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."schema:about".-> v1 v4 --"schema:isPartOf"--> c16 end bind1[/"if(bound(?link),concat('#91;#91;',substring(str(?link),'31^^xsd:integer','500^^xsd:integer'),'|',?idLabel,'#93;#93;'),?idLabel)"/] v4 --o bind1 v3 --o bind1 bind1 --as--o v5