query-058fa993c66d1cb808bf67bff43a3c86

rq turtle/ttl

Demographics of Current Members of US CongressSo, I've never used Wikidata queries before. I am sure this ought to be easy, but right now it is defeating me. I would like to have a query that reports the demographic characteristics of current members of the US Congress. Returning something like: Name, Party, Chamber (House/Senate), State, District (for House), Age, Gender, Ethnic Group (if specified), Religion (if specified) 11:50, 12 May 2020 (UTC)) talk (Dragons flightThanks in advance. qualifiers are missing or when there are multiple values for some properties.(P582)end time and (P580)start time : Here is a query. There are some problems with the data causing in some cases too many results when Dragons flight@

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wdno: <http://www.wikidata.org/prop/novalue/>
PREFIX wd: <http://www.wikidata.org/entity/>
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 ?item ?itemLabel ?partyLabel ?chamberLabel ?stateLabel ?districtLabel
       ((NOW() - ?date_of_birth)/365.25 AS ?age)
       ?genderLabel ?etnic_groupLabel ?religionLabel
WHERE
{
  ?item wdt:P31 wd:Q5. # item is a human
  VALUES ?chamber { wd:Q4416090 wd:Q13218630 } # US senator, US representative
  ?item p:P39 ?position_statement.
  ?position_statement ps:P39 ?chamber.
  ?position_statement a wikibase:BestRank.
  OPTIONAL { ?position_statement pq:P582 ?endtime. }
  FILTER (! BOUND(?endtime)) # No end time, ?item still has the position
  OPTIONAL
  {
    ?position_statement ps:P39 wd:Q4416090. # senator
    ?position_statement pq:P768 ?state.
  }
  OPTIONAL
  {
    ?position_statement ps:P39 wd:Q13218630. # representative
    ?position_statement pq:P768 ?district. 
    ?district wdt:P131 ?state.
    ?state wdt:P31 wd:Q35657. # ?state is a US state
  }
  OPTIONAL { ?position_statement pq:P4100 ?parliamentary_group. }
  OPTIONAL { ?position_statement a wdno:P4100. BIND("No party" AS ?parliamentary_group) }
  OPTIONAL { ?item wdt:P102 ?party_member. }
  OPTIONAL { ?item a wdno:P102. BIND("No party" AS ?party_member) }
  BIND (COALESCE(?parliamentary_group,?party_member) AS ?party)
  OPTIONAL { ?item wdt:P569 ?date_of_birth. }
  OPTIONAL { ?item wdt:P21 ?gender. }
  OPTIONAL { ?item wdt:P172 ?etnic_group. }
  OPTIONAL { ?item wdt:P140 ?religion. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v14("?age") v3("?chamber") v10("?date_of_birth"):::projected v6("?district") v1("?endtime") v12("?etnic_group") v11("?gender") v2("?item"):::projected v8("?parliamentary_group") v9("?party") v9("?party_member") v4("?position_statement") v13("?religion") v5("?state") c16(["p:novalue/P102"]):::iri c6(["wikibase:BestRank"]):::iri c10(["wd:Q13218630"]):::iri c22(["bd:serviceParam"]):::iri c8(["wd:Q4416090"]):::iri c2(["wd:Q5"]):::iri c24(["#91;AUTO_LANGUAGE#93;,en"]):::literal c12(["wd:Q35657"]):::iri c14(["p:novalue/P4100"]):::iri f0[["not bound(?endtime)"]] f0 --> v1 v2 --"p:direct/P31"--> c2 bind1[/VALUES ?chamber/] bind1-->v3 bind10(["wd:Q4416090"]) bind10 --> bind1 bind11(["wd:Q13218630"]) bind11 --> bind1 v2 --"p:P39"--> v4 v4 --"p:statement/P39"--> v3 v4 --"a"--> c6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:qualifier/P582".-> v1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:statement/P39".-> c8 v4 --"p:qualifier/P768"--> v5 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:statement/P39".-> c10 v4 --"p:qualifier/P768"--> v6 v6 --"p:direct/P131"--> v5 v5 --"p:direct/P31"--> c12 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:qualifier/P4100".-> v8 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v4 -."a".-> c14 bind2[/"'No party'"/] bind2 --as--o v8 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P102".-> v9 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v2 -."a".-> c16 bind3[/"'No party'"/] bind3 --as--o v9 end bind4[/"?parliamentary_group?party_member"/] v8 --o bind4 v9 --o bind4 bind4 --as--o v9 subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P569".-> v10 end subgraph optional8["(optional)"] style optional8 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P21".-> v11 end subgraph optional9["(optional)"] style optional9 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P172".-> v12 end subgraph optional10["(optional)"] style optional10 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P140".-> v13 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c22 --"wikibase:language"--> c24 end bind5[/"NOW() - ?date_of_birth / '365.25^^xsd:decimal'"/] v10 --o bind5 bind5 --as--o v14