query-1815c7ed3652ddfc9d39f10bc08e6c4d

rq turtle/ttl

most ender-imbalanced occupations in odia wikipedia SELECT ?occupation ?occupationLabel ?women ?men WITH { SELECT ?occupation (SUM(?woman) AS ?women) (SUM(?man) AS ?men) WHERE { #BIND(wd:Q668 AS ?country). # substitute country of your choice here (remove the Q668, hit Ctrl+Space and start typing the country name, select the right one from the suggestions with the arrow keys and insert it with Enter) ?person wdt:P31 wd:Q5;. #?person wdt:P27 ?country. # remove this to search world-wide – results in query timeout unless you reduce the dataset in some other fashion ?person p:P106/ps:P106 ?occupation. ?article schema:about ?person . ?article schema:isPartOf https://bg.wikipedia.org/ . { ?person wdt:P21 wd:Q6581097. BIND(1 AS ?man). } UNION { ?person wdt:P21 wd:Q2449503. BIND(1 AS ?man). } UNION { ?person wdt:P21 wd:Q6581072. BIND(1 AS ?woman). } UNION { ?person wdt:P21 wd:Q1052281. BIND(1 AS ?woman). } # TODO consider how to count P21: Q48270 (genderqueer) and Q1097630 (intersex) } GROUP BY ?occupation } AS %results WHERE { INCLUDE %results. # subquery as optimization: don’t make the label service fetch labels for every ?person in the subquery SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY

divide ?variable+1 instead of ?variable to avoid division by zero

# (unfortunately, we can’t use ABS(LOG(x/y)) instead of the IF() because SPARQL has no LOG function) DESC(IF(?women > ?men, (?women+1)/(?men+1), (?men+1)/(?women+1))) # if the ratio is the same, show results with more people in total first DESC(?women + ?men)

Use at

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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# most ender-imbalanced occupations in odia wikipedia 
SELECT ?occupation ?occupationLabel ?women ?men WHERE {
   {
  SELECT ?occupation (SUM(?woman) AS ?women) (SUM(?man) AS ?men) WHERE {
    #BIND(wd:Q668 AS ?country). # substitute country of your choice here (remove the Q668, hit Ctrl+Space and start typing the country name, select the right one from the suggestions with the arrow keys and insert it with Enter)
    ?person wdt:P31 wd:Q5;.
    #?person wdt:P27 ?country. # remove this to search world-wide – results in query timeout unless you reduce the dataset in some other fashion
     ?person p:P106/ps:P106 ?occupation.
?article schema:about ?person . ?article schema:isPartOf <https://bg.wikipedia.org/> .
    { ?person wdt:P21 wd:Q6581097. BIND(1 AS ?man). } UNION
    { ?person wdt:P21 wd:Q2449503. BIND(1 AS ?man). } UNION
    { ?person wdt:P21 wd:Q6581072. BIND(1 AS ?woman). } UNION
    { ?person wdt:P21 wd:Q1052281. BIND(1 AS ?woman). }
    # TODO consider how to count P21: Q48270 (genderqueer) and Q1097630 (intersex)
  }
  GROUP BY ?occupation
} # subquery as optimization: don’t make the label service fetch labels for every ?person in the subquery
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY
# divide ?variable+1 instead of ?variable to avoid division by zero
  # (unfortunately, we can’t use ABS(LOG(x/y)) instead of the IF() because SPARQL has no LOG function)
  DESC(IF(?women > ?men, (?women+1)/(?men+1), (?men+1)/(?women+1)))
  # if the ratio is the same, show results with more people in total first
  DESC(?women + ?men)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?article") v7("?man") v8("?men"):::projected v4("?occupation"):::projected v3("?person") v8("?woman") v8("?women"):::projected a1((" ")) c11(["wd:Q2449503"]):::iri c10(["wd:Q6581097"]):::iri c12(["wd:Q6581072"]):::iri c8([https://bg.wikipedia.org/]):::iri c15(["bd:serviceParam"]):::iri c13(["wd:Q1052281"]):::iri c3(["wd:Q5"]):::iri c17(["#91;AUTO_LANGUAGE#93;,en"]):::literal v3 --"p:direct/P31"--> c3 v3 --"p:P106"--> a1 a1 --"p:statement/P106"--> v4 v5 --"schema:about"--> v3 v5 --"schema:isPartOf"--> c8 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P21"--> c13 bind0[/"'1^^xsd:integer'"/] bind0 --as--o v8 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P21"--> c12 bind1[/"'1^^xsd:integer'"/] bind1 --as--o v8 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P21"--> c11 bind2[/"'1^^xsd:integer'"/] bind2 --as--o v7 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P21"--> c10 bind3[/"'1^^xsd:integer'"/] bind3 --as--o v7 end union0r <== or ==> union0l end bind6[/"sum(?woman)"/] v8 --o bind6 bind6 --as--o v8 bind7[/"sum(?man)"/] v7 --o bind7 bind7 --as--o v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c15 --"wikibase:language"--> c17 end