Skip to content

Commit

Permalink
Allow MP names that differ only in honourifics.
Browse files Browse the repository at this point in the history
This means if WriteToThem has Sir Malcolm Rifkind but TheyWorkForYou only has
Malcolm Rifkind, we still consider that a match. This might well apply to all
types this script handles, but will restrict just to MPs for now, seems to be
most likely place it could happen.
  • Loading branch information
dracos authored and DaDem cron jobs committed Nov 18, 2014
1 parent 0516f4a commit 145d367
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 11 additions & 2 deletions services/mapit-dadem-loading/CouncilMatch.pm
Expand Up @@ -384,6 +384,9 @@ sub canonicalise_council_name ($) {
return $_;
}

my $titles = "Cllr|Councillor|Dr|Hon|hon|rah|rh|Mrs|Ms|Mr|Miss|Rt Hon|Reverend|The Rev|The Reverend|Sir|Dame|Rev|Prof";
my $honourifics = "MP|CBE|OBE|MBE|QC|BEM|rh|RH|Esq|QPM|JP|FSA|Bt|BEd|Hons|TD|MA|QHP|DL|CMG|BB|AKC|Bsc|Econ|LLB|GBE|QSO|BA|FRSA|FCA|DD|KBE|PhD";

# canonicalise_person_name NAME
# Convert name from various formats "Fred Smith", "Smith, Fred",
# "Fred R Smith", "Smith, Fred RK" to uniform one "fred smith". Removes
Expand All @@ -393,8 +396,6 @@ sub canonicalise_person_name ($) {
($_) = @_;

# Remove fancy words
my $titles = "Cllr|Councillor|Dr|Hon|hon|rah|rh|Mrs|Ms|Mr|Miss|Rt Hon|Reverend|The Rev|The Reverend|Sir|Dame|Rev|Prof";
my $honourifics = "MP|CBE|OBE|MBE|QC|BEM|rh|RH|Esq|QPM|JP|FSA|Bt|BEd|Hons|TD|MA|QHP|DL|CMG|BB|AKC|Bsc|Econ|LLB|GBE|QSO|BA|FRSA|FCA|DD|KBE|PhD";
while (s#(\b(?:$titles)\b)##) {};
while (s#(\b(?:$honourifics)\b)##) {};

Expand All @@ -420,6 +421,14 @@ sub canonicalise_person_name ($) {
return $_;
}

# remove_honourifics NAME
sub remove_honourifics ($) {
($_) = @_;
while (s#(\b(?:$titles)\b)##) {};
while (s#(\b(?:$honourifics)\b)##) {};
return $_;
}

# Internal use
# get_extradata COUNCIL_ID
# Checks we have the councillor names webpage URL, and any other needed data.
Expand Down
10 changes: 9 additions & 1 deletion services/mapit-dadem-loading/dadem_csv_load
Expand Up @@ -262,10 +262,18 @@ while (my $line = <MAIN>) {
$updates_required = 1;
$conflict .= "Party changed ";
}

# ... changing name is also (even though it must have matched canonical name)
if ($cur_repinfo->{name} ne $finalname) {
if ($kind ne 'mp' && $cur_repinfo->{name} ne $finalname) {
$updates_required = 1;
$conflict .= "Name changed ";
} elsif ($kind eq 'mp') {
my $curname_nohonourifics = CouncilMatch::remove_honourifics($cur_repinfo->{name});
my $finalname_nohonourifics = CouncilMatch::remove_honourifics($finalname);
if ($curname_nohonourifics ne $finalname_nohonourifics) {
$updates_required = 1;
$conflict .= "Name changed ";
}
}

# Use old fax/email if we don't have a new one
Expand Down

0 comments on commit 145d367

Please sign in to comment.