query-5c5c11de0f8f6f37937247d26a8e2827
20:24, 30 January 2020 (UTC)) talk (Dipsacus fullonum: Below is code to find all citizens of Finland which have Swedish as native language grouped after decade of birth. It will show the number of articles in Swedish Wikipeia, and how many of these is male and female. If the sum of male and female is less than the total count, then some of the persons are something else (transgender) or the gender isn't specified. You can change the Wikipedia language code to show number for other Wikipedias, and you outcomment the Wikipedia line to show count for all persons on Wikidata. --Robertsilen@: I'm interested in people with ethnic group "Swedish speaking population of Finland" and their Wikipedia page, or lack of such, in Swedish, Finnish, English, French and German. I'm trying to split the search result of 1430 people into gender & birth date by decade (as mentioned). I'm also trying to figure out what kind of search/grouping I could do with Occupation (P106) - maybe I could find contributers interested in writing about people in certain professions. Happy for all help with this :) Dipsacus@ 17:27, 30 January 2020 (UTC)) talk (Dipsacus fullonum: Do you want gender only for persons with an article on a Wikipedia (in which language?), or for all persons with items on Wikidata? --Robertsilen@
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT ?birth_decade (COUNT(?person) as ?persons) (SUM(?male) as ?male_count) (SUM(?female) as ?female_count)
WHERE
{
?link schema:about ?person; schema:isPartOf <https://sv.wikipedia.org/>.
?person wdt:P31 wd:Q5. # is a human
?person wdt:P27 wd:Q33. # citizen of Finland
?person wdt:P103 wd:Q9027. # native language Swedish
?person p:P569/psv:P569 [
wikibase:timeValue ?dateOfBirth;
wikibase:timePrecision ?precision
].
FILTER(?precision >= "8"^^xsd:integer) # Precision is decade or smaller
BIND(SUBSTR(STR(?dateOfBirth),1,3) as ?birth_decade)
OPTIONAL { ?person wdt:P21 ?sex. }
BIND(IF(?sex = wd:Q6581097,1,0) as ?male).
BIND(IF(?sex = wd:Q6581072,1,0) as ?female).
}
GROUP BY ?birth_decade
ORDER BY ASC(?birth_decade)