query-62c5a6a2bbebbf81c41382662cc61e2e

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 DISTINCT ?id ?name WHERE {
    # Current members of the Riigikogu
    ?item p:P39 ?ps .
    ?ps ps:P39 wd:Q61976148 .
    FILTER NOT EXISTS { ?ps pq:P582 [] }

    # A Riigikogu ID, and optional "named as"
    OPTIONAL { 
      ?item p:P4287 ?idstatement .
      ?idstatement ps:P4287 ?id .
      OPTIONAL { ?idstatement pq:P1810 ?riigikoguName }
    }

    # Their on-wiki label as a fall-back if no Riigikogu name
    OPTIONAL { ?item rdfs:label ?etLabel FILTER(LANG(?etLabel) = "et") }
    BIND(COALESCE(?riigikoguName, ?etLabel) AS ?name)
  }

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?etLabel") v5("?id"):::projected v4("?idstatement") v3("?item") v7("?name"):::projected v2("?ps") v6("?riigikoguName") a1((" ")) c5(["wd:Q61976148"]):::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 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:P4287".-> v4 v4 --"p:statement/P4287"--> v5 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:qualifier/P1810".-> v6 end end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v3 -."rdfs:label".-> v1 end bind1[/"?riigikoguName?etLabel"/] v6 --o bind1 v1 --o bind1 bind1 --as--o v7