def get_unique_person_id(tidied_speaker, on_date): ids = memberList.match_whole_speaker(tidied_speaker, str(on_date)) if ids is None: # This special return value (None) indicates that the speaker # is something we know about, but not an MSP (e.g Lord # Advocate) return None else: if len(ids) == 0: log_speaker(tidied_speaker, str(on_date), "missing") return None elif len(ids) == 1: Speech.speakers_so_far.append(ids[0]) return ids[0] else: final_id = None # If there's an ambiguity there our best bet is to go # back through the previous IDs used today, and pick # the most recent one that's in the list we just got # back... for i in range(len(Speech.speakers_so_far) - 1, -1, -1): older_id = Speech.speakers_so_far[i] if older_id in ids: final_id = older_id break if final_id: Speech.speakers_so_far.append(final_id) return final_id else: log_speaker(tidied_speaker, str(on_date), "genuine ambiguity")
def get_unique_person_id(tidied_speaker, on_date): ids = memberList.match_whole_speaker(tidied_speaker,str(on_date)) if ids is None: # This special return value (None) indicates that the speaker # is something we know about, but not an MSP (e.g Lord # Advocate) return None else: if len(ids) == 0: log_speaker(tidied_speaker,str(on_date),"missing") return None elif len(ids) == 1: Speech.speakers_so_far.append(ids[0]) return ids[0] else: final_id = None # If there's an ambiguity there our best bet is to go # back through the previous IDs used today, and pick # the most recent one that's in the list we just got # back... for i in range(len(Speech.speakers_so_far) - 1, -1, -1): older_id = Speech.speakers_so_far[i] if older_id in ids: final_id = older_id break if final_id: Speech.speakers_so_far.append(final_id) return final_id else: log_speaker(tidied_speaker,str(on_date),"genuine ambiguity")
def get_unique_person_id(tidied_speaker, on_date): ids = memberList.match_whole_speaker(tidied_speaker,str(on_date)) if ids is None: # This special return value (None) indicates that the speaker # is something we know about, but not an MSP (e.g Lord # Advocate) return None elif len(ids) == 0: log_speaker(tidied_speaker,str(on_date),"missing") return None elif len(ids) == 1: return ids[0] else: raise Exception, "The speaker '%s' could not be resolved, found: %s" % (tidied_speaker, ids)
def valid_speaker(self,speaker_name): tidied_speaker = speaker_name if not tidied_speaker: return None if self.odd_unknowns.has_key(speaker_name): return "unknown" tidied_speaker = re.sub("((on behalf of the )?Scottish Parliamentary Corporate Body)",'',tidied_speaker) ids = memberList.match_whole_speaker(tidied_speaker,str(parser.date)) if ids == None: return "unknown" if not ids: # i.e. it's the empty list... if verbose: print "No match for speaker: "+tidied_speaker+" on date "+str(parser.date) return None elif len(ids) > 1: if verbose: print "Too many matches found for speaker: "+tidied_speaker+" on date "+str(parser.date) return None else: return ids[0]
for msp in msps: id_to_name[msp['PersonID']] = msp['ParliamentaryName'] for min_type in minister_type: type_to_name[min_type['ID']] = min_type['Name'] new_ministers = [] for minister in ministers: name = id_to_name[minister['PersonID']] role = type_to_name[minister['GovernmentRoleID']] start = dateparser.parse(minister['ValidFromDate']).date().isoformat() end = '9999-12-31' if minister['ValidUntilDate']: end = dateparser.parse(minister['ValidUntilDate']).date().isoformat() person_id = memberList.match_whole_speaker(name, start) new_minister = { 'id': 'scot.parliament.data/membergovernmentroles/%s' % minister['ID'], 'source': 'https://data.parliament.scot/api/membergovernmentroles/json', 'role': role, 'person_id': person_id, 'organization_id': 'scottish-parliament', 'start_date': start } if end != '9999-12-31': new_minister['end_date'] = end new_ministers.append(new_minister) with open(os.path.join(members_dir, 'sp-ministers.json'), 'w') as sp_fp: json.dump(new_ministers, sp_fp, indent=2)