query-adb3636644a769435cbd4315036527ac

rq turtle/ttl

TODO

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
#defaultView:BarChart
SELECT ?letter (100* ?m/(?m+?f) AS ?m_pct) (100* ?f/(?m+?f) AS ?f_pct) WHERE {
  {
    SELECT ?letter (COUNT(?item) AS ?count) (COUNT(?male) AS ?m) (COUNT(?female) AS ?f) {
      ?item wdt:P3217 [] .
      OPTIONAL {
         ?item wdt:P21 wd:Q6581097 .
         BIND (1 AS ?male) 
      }
      OPTIONAL {
         ?item wdt:P21 wd:Q6581072 .
         BIND (1 AS ?female) 
      }
      ?item wdt:P734 ?surname .
      ?surname rdfs:label ?surname_label FILTER(LANG(?surname_label) = "en") .
      BIND (substr(?surname_label, 1, 1) AS ?letter) .
   } GROUP BY ?letter 
 }
} ORDER BY ?letter

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?count") v9("?f"):::projected v11("?f_pct") v5("?female") v3("?item") v7("?letter"):::projected v8("?m"):::projected v10("?m_pct") v4("?male") v6("?surname") v2("?surname_label") a1((" ")) c4(["wd:Q6581097"]):::iri c5(["wd:Q6581072"]):::iri f0[["?surname_label = 'en'"]] f0 --> v2 v3 --"wdt:P3217"--> a1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P21".-> c4 bind1[/"'1^^xsd:integer'"/] bind1 --as--o v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P21".-> c5 bind2[/"'1^^xsd:integer'"/] bind2 --as--o v5 end v3 --"wdt:P734"--> v6 v6 --"rdfs:label"--> v2 bind3[/"substring(?surname_label,'1^^xsd:integer','1^^xsd:integer')"/] v2 --o bind3 bind3 --as--o v7 bind7[/"count(?item)"/] v3 --o bind7 bind7 --as--o v7 bind8[/"count(?male)"/] v4 --o bind8 bind8 --as--o v8 bind9[/"count(?female)"/] v5 --o bind9 bind9 --as--o v9 bind10[/"'100^^xsd:integer' * ?m / ?m + ?f"/] v8 --o bind10 v9 --o bind10 bind10 --as--o v10 bind11[/"'100^^xsd:integer' * ?f / ?m + ?f"/] v9 --o bind11 v8 --o bind11 bind11 --as--o v11