Skip to content

Instantly share code, notes, and snippets.

@tmtmtmtm
Last active July 27, 2020 08:27
Show Gist options
  • Save tmtmtmtm/3ec7c659dc55dfdfcc94084083ee5307 to your computer and use it in GitHub Desktop.
Save tmtmtmtm/3ec7c659dc55dfdfcc94084083ee5307 to your computer and use it in GitHub Desktop.
UK Parliamentary by-election cleanups

Set P31 to "UK Parliamentary by-election"

Look for items that are set as the 'elected in' for a UK MP, but have instance of: 'by-election', rather than 'UK Parliamentary by-election'

SELECT DISTINCT ?item ?itemLabel
WHERE 
{
  ?person p:P39 [ps:P39/wdt:P279 wd:Q16707842; pq:P2715 ?item].
  ?item wdt:P31 wd:Q1057954 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Petscan -> QuickStatements: batch https://tools.wmflabs.org/editgroups/b/QSv2T/1595836635055

Add missing 'successful candidate'

Find by-elections with no 'successful candidate', but which have been set as someone's 'elected in'

SELECT DISTINCT ?item ?itemLabel ?person ?personLabel
WHERE {
  ?person p:P39 [ps:P39/wdt:P279 wd:Q16707842; pq:P2715 ?item].
  ?item wdt:P31/wdt:P279* wd:Q1057954 .
  MINUS { ?item wdt:P991 [] }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Fetch with:

wd sparql derive-successful-candidate.rq | jq -r '.[] | "\(.item.value)\tP991\t\(.person.value)"' | tee >(pbcopy)

And sent to QuickStatements as https://editgroups.toolforge.org/b/QSv2T/1595838252734/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment