query-7d54b258502531cab0ace4b45383797a
Count frequency of tv show cast member appearances by genderI want to count the occurrence of cast member gender in television series episode. Let's say for a given show there are 100 episodes in Wikidata with cast member (P161) statements, for three distinct persons: C (male) appears in 1 episode. B (female) appears in 1 episode. A (female) appears in all 100 episodes.I'm looking for two queries: The other should return female 2, male 1 (number of distinct persons appearing by gender). One should return female 101, male 1 (number of overall appearances by gender).I have come up with the following, which does neither:
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
select ?genderLabel (count(distinct ?actorLabel) as ?count) where
{
?ep wdt:P31 wd:Q21191270.
?ep wdt:P179 wd:Q79784.
?ep wdt:P161 ?actor.
?actor wdt:P21 ?gender.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} group by ?genderLabel order by desc(?count)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?actor")
v5("?actorLabel"):::projected
v6("?count")
v2("?ep")
v4("?gender")
c8(["bd:serviceParam"]):::iri
c4(["wd:Q79784"]):::iri
c10(["en"]):::literal
c2(["wd:Q21191270"]):::iri
v2 --"wdt:P31"--> c2
v2 --"wdt:P179"--> c4
v2 --"wdt:P161"--> v3
v3 --"wdt:P21"--> v4
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end
bind1[/"count(?actorLabel)"/]
v5 --o bind1
bind1 --as--o v6