Skip to content

Instantly share code, notes, and snippets.

@tmtmtmtm
Created June 8, 2020 06:12
Show Gist options
  • Save tmtmtmtm/c96c70920ab72d4fba8af5e6e79c00d2 to your computer and use it in GitHub Desktop.
Save tmtmtmtm/c96c70920ab72d4fba8af5e6e79c00d2 to your computer and use it in GitHub Desktop.
Female Heads of Government of UN Member States
SELECT ?person ?personLabel ?country ?countryLabel ?office ?officeLabel ?heldStart ?heldEnd ?daysInOffice WHERE {
# Current UN Member States
?country wdt:P31 wd:Q3624078 ; p:P463 ?ms .
?ms ps:P463 wd:Q1065 ; pq:P580 ?joined .
FILTER NOT EXISTS { ?ms pq:P582 [] }
BIND(FLOOR(NOW()-?joined) AS ?daysInUN)
# what office(s) = head of government, and when?
?country p:P1313 ?os .
?os ps:P1313 ?office .
OPTIONAL { ?os pq:P580 ?office580 }
OPTIONAL { ?os pq:P582 ?office582 }
FILTER ( !BOUND(?office582) || (?office582 > ?joined) )
BIND(IF(BOUND(?office580), IF(?office580 < ?joined, ?joined, ?office580), ?joined) AS ?officeStart)
BIND(IF(BOUND(?office582), ?office582, NOW()) AS ?officeEnd)
# Who has held office in that period?
?person wdt:P31 wd:Q5 ; wdt:P21 wd:Q6581072 ; p:P39 ?ps .
?ps ps:P39 ?office ; pq:P580 ?heldStart .
OPTIONAL { ?ps pq:P582 ?heldEnd }
BIND(IF(BOUND(?heldEnd), ?heldEnd, NOW()) AS ?effectiveEnd)
BIND(IF(?effectiveEnd > ?officeEnd, ?officeEnd, ?effectiveEnd) AS ?hogEnd)
BIND(IF(?heldStart < ?officeStart, ?officeStart, ?heldStart) AS ?hogStart)
FILTER ((?heldStart < ?officeEnd) && (?effectiveEnd > ?officeStart))
BIND(FLOOR(?hogEnd - ?hogStart) AS ?daysInOffice)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?heldStart ?countryLabel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment