query-93c81b4b3f7bd60a6da62c8d3813fd82
Bouzinac
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
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/>
SELECT ?letter ?count (?count / ?total * 100 AS ?pct)
WHERE
{
{
SELECT ?letter (COUNT(*) AS ?count)
WHERE
{
?item wdt:P31 wd:Q5 . # Humans
?item wdt:P27 wd:Q38 . # Italians
# ?item wdt:P21 wd:Q6581097 . # male
?item wdt:P21 wd:Q6581072 . # female
?item p:P735 ?name_statement . # Given name
?name_statement ps:P735 / wdt:P1705 ?name . # Native label for name
OPTIONAL { ?name_statement pq:P1545 ?ordinal . }
FILTER (! BOUND(?ordinal) || ?ordinal = "1") # Use the only name (no ordinal value) or name #1
BIND (SUBSTR(STR(?name), STRLEN(?name)) AS ?letter)
}
GROUP BY ?letter
}
{
SELECT (SUM(?count) AS ?total)
WHERE
{
{
SELECT ?letter (COUNT(*) AS ?count)
WHERE
{
?item wdt:P31 wd:Q5 . # Humans
?item wdt:P27 wd:Q38 . # Italians
# ?item wdt:P21 wd:Q6581097 . # male
?item wdt:P21 wd:Q6581072 . # female
?item p:P735 ?name_statement . # Given name
?name_statement ps:P735 / wdt:P1705 ?name . # Native label for name
OPTIONAL { ?name_statement pq:P1545 ?ordinal . }
FILTER (! BOUND(?ordinal) || ?ordinal = "1") # Use the only name (no ordinal value) or name #1
BIND (SUBSTR(STR(?name), STRLEN(?name)) AS ?letter)
}
GROUP BY ?letter
} }
}}
ORDER BY DESC(?count)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v7("?count"):::projected
v3("?item")
v7("?letter"):::projected
v5("?name")
v4("?name_statement")
v2("?ordinal")
v8("?pct")
v7("?total"):::projected
a1((" "))
a2((" "))
c5(["wd:Q38"]):::iri
c3(["wd:Q5"]):::iri
c7(["wd:Q6581072"]):::iri
f0[["(not bound(?ordinal) || ?ordinal = '1')"]]
f0 --> v2
v3 --"p:direct/P31"--> c3
v3 --"p:direct/P27"--> c5
v3 --"p:direct/P21"--> c7
v3 --"p:P735"--> v4
v4 --"p:statement/P735"--> a1
a1 --"p:direct/P1705"--> v5
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P1545".-> v2
end
bind1[/"substring(str(?name),string-length(?name))"/]
v5 --o bind1
bind1 --as--o v7
bind3[/"count(*)"/]
bind3 --as--o v7
f4[["(not bound(?ordinal) || ?ordinal = '1')"]]
f4 --> v2
v3 --"p:direct/P31"--> c3
v3 --"p:direct/P27"--> c5
v3 --"p:direct/P21"--> c7
v3 --"p:P735"--> v4
v4 --"p:statement/P735"--> a2
a2 --"p:direct/P1705"--> v5
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P1545".-> v2
end
bind5[/"substring(str(?name),string-length(?name))"/]
v5 --o bind5
bind5 --as--o v7
bind7[/"count(*)"/]
bind7 --as--o v7
bind9[/"sum(?count)"/]
v7 --o bind9
bind9 --as--o v7
bind10[/"?count / ?total * '100^^xsd:integer'"/]
v7 --o bind10
v7 --o bind10
bind10 --as--o v8