query-5c5c11de0f8f6f37937247d26a8e2827

rq turtle/ttl

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

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)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?birth_decade"):::projected v5("?dateOfBirth") v8("?female"):::projected v11("?female_count") v3("?link") v7("?male"):::projected v10("?male_count") v4("?person"):::projected v9("?persons") v2("?precision") v6("?sex") a2((" ")) a1((" ")) c8(["wd:Q33"]):::iri c10(["wd:Q9027"]):::iri c6(["wd:Q5"]):::iri c4([https://sv.wikipedia.org/]):::iri f0[["?precision >= '8^^xsd:integer'"]] f0 --> v2 v3 --"schema:about"--> v4 v3 --"schema:isPartOf"--> c4 v4 --"p:direct/P31"--> c6 v4 --"p:direct/P27"--> c8 v4 --"p:direct/P103"--> c10 a1 --"wikibase:timeValue"--> v5 a1 --"wikibase:timePrecision"--> v2 v4 --"p:P569"--> a2 a2 --"p:statement/value/P569"--> a1 bind1[/"substring(str(?dateOfBirth),'1^^xsd:integer','3^^xsd:integer')"/] v5 --o bind1 bind1 --as--o v6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P21".-> v6 end bind2[/"if(?sex = 'wd:Q6581097','1^^xsd:integer','0^^xsd:integer')"/] v6 --o bind2 bind2 --as--o v7 bind3[/"if(?sex = 'wd:Q6581072','1^^xsd:integer','0^^xsd:integer')"/] v6 --o bind3 bind3 --as--o v8 bind7[/"count(?person)"/] v4 --o bind7 bind7 --as--o v9 bind8[/"sum(?male)"/] v7 --o bind8 bind8 --as--o v10 bind9[/"sum(?female)"/] v8 --o bind9 bind9 --as--o v11