def get_unique_speaker_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")
Example #2
0
 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]