query-247c2d530d647586168ff55d1eae780d

rq turtle/ttl

SPARQL query

Use at

PREFIX wd: <http://www.wikidata.org/entity/>
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/>
SELECT ?id ?item ?name ?group ?district WHERE { 
    # Current members of the 38th Parliament of Finland
    ?item p:P39 ?ps . 
    ?ps ps:P39 wd:Q17592486 ; pq:P2937 wd:Q47459902 .
    FILTER NOT EXISTS { ?ps pq:P582 [] }
    OPTIONAL { 
      ?ps pq:P4100 ?groupItem .
      OPTIONAL { ?groupItem rdfs:label ?group FILTER(LANG(?group) = "en") }
    }
    OPTIONAL { 
      ?ps pq:P768 ?districtItem .
      OPTIONAL { ?districtItem rdfs:label ?district FILTER(LANG(?district) = "en") }
    }

    # An Eduskunta ID, and optional "named as"
    OPTIONAL { 
      ?item p:P2181 ?idstatement .
      ?idstatement ps:P2181 ?id .
      OPTIONAL { ?idstatement pq:P1810 ?eduskuntaName }
    }

    # Their on-wiki label as a fall-back if no Eduskunta name
    OPTIONAL { ?item rdfs:label ?fiLabel FILTER(LANG(?fiLabel) = "fi") }
    BIND(COALESCE(?eduskuntaName, ?fiLabel) AS ?name)
  }

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?district"):::projected v7("?districtItem") v10("?eduskuntaName") v1("?fiLabel") v4("?group"):::projected v5("?groupItem") v9("?id"):::projected v8("?idstatement") v3("?item"):::projected v11("?name"):::projected v2("?ps") a1((" ")) c7(["wd:Q47459902"]):::iri c5(["wd:Q17592486"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0a1 e0v1("?ps"):::projected e0a1((" ")):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c2 f0 --> a1 v2 --"p:qualifier/P582"--> a1 v3 --"p:P39"--> v2 v2 --"p:statement/P39"--> c5 v2 --"p:qualifier/P2937"--> c7 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P4100".-> v5 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."rdfs:label".-> v4 end end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P768".-> v7 subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v7 -."rdfs:label".-> v6 end end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:P2181".-> v8 v8 --"p:statement/P2181"--> v9 subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v8 -."p:qualifier/P1810".-> v10 end end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v3 -."rdfs:label".-> v1 end bind1[/"?eduskuntaName?fiLabel"/] v10 --o bind1 v1 --o bind1 bind1 --as--o v11