Skip to content

Instantly share code, notes, and snippets.

@tmtmtmtm
Last active August 22, 2020 16:49
Show Gist options
  • Save tmtmtmtm/cbb986176f41db7e31d4369efc2b33c7 to your computer and use it in GitHub Desktop.
Save tmtmtmtm/cbb986176f41db7e31d4369efc2b33c7 to your computer and use it in GitHub Desktop.
Ensure UK Parliament Constituencies in Wikidata know which legislature the 'number of representatives' qualifier applies to

All Wikidata items for UK Parliamentary Constituencies (current and historic) should have a P1410 "number of representatives in legislature" claim (currently this is always 1, but historically some had more than this). The main statement generally exists, but in the vast majority of cases (2136) it is missing the required qualifier to say which legislature this applies to, and in 17 of the ones with the qualifier, it's pointing at Parliament rather than the House of Commons.

Step 1: Migrate 'Parliament' to 'House of Commons'

fix-constituency-body-uk.rb:

SELECT DISTINCT ?reps
WHERE {
  ?item wdt:P31 wd:Q27971968 ; p:P1410 ?reps .
  ?reps pq:P194 wd:Q11010 .
}

Run as:

wd sparql fix-constituency-body-uk.rb | awk '{ print $1, "P194 Q11010 Q11005" }' | 
  wd uq --batch --summary "Migrate body to HoC"

-> https://tools.wmflabs.org/editgroups/b/wikibase-cli/aa0f5efe99424

Step 2: Add missing qualifiers

add-constituency-body-uk.rb:

SELECT DISTINCT ?reps
WHERE {
  ?item wdt:P31 wd:Q27971968 ; p:P1410 ?reps .
  FILTER NOT EXISTS { ?reps pq:P194 [] }
}

Run as:

wd sparql add-constituency-body-uk.rb | awk '{ print $1, "P194 Q11005" }' |
  wd aq --batch --summary "Add missing 'body' qualifier for HoC constituencies"

-> https://tools.wmflabs.org/editgroups/b/wikibase-cli/1ef613d11db

Still to do

89 constituencies don't have a "number of respresenatives" claim at all: https://w.wiki/a8t

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