This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _add_person_record(self, dict): | |
person = { | |
'id': self._get_id(dict), | |
'active': self._get_active(dict), | |
'lastName': self._get_last_name(dict), | |
'firstName': self._get_first_name(dict), | |
'middleName':self._get_middle_name(dict), | |
'gender': self._get_gender(dict), | |
'party': self._get_party(dict), | |
'council' : self._get_council(dict), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _add_person_record(self, dict): | |
person = { | |
'id': self._get_id(dict), | |
'active': self._get_active(dict), | |
'lastName': self._get_last_name(dict), | |
'firstName': self._get_first_name(dict), | |
'middleName':self._get_middle_name(dict), | |
'gender': self._get_gender(dict), | |
'party': self._get_party(dict), | |
'council' : self._get_council(dict), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def match_name(self, name_tuple): | |
match_list = [] | |
combinations = self.generate_combinations(name_tuple) | |
for comb_tuple in combinations: | |
concat_name = self.generate_normalized_name(comb_tuple) | |
metaphone_tuple = doublemetaphone(concat_name) | |
if metaphone_tuple[0] in self.__lookup_dict[0]: | |
match_list.append((concat_name, self.__lookup_dict[0][metaphone_tuple[0]])) | |
# Iterate through all matches and check for single result tuples | |
# Ensure that the singe result tuples are pointing to the same id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def match_name(self, name_tuple): | |
match_list = [] | |
combinations = self.generate_combinations(name_tuple) | |
for comb_tuple in combinations: | |
concat_name = self.generate_normalized_name(comb_tuple) | |
metaphone_tuple = doublemetaphone(concat_name) | |
if metaphone_tuple[0] in self.__lookup_dict[0]: | |
match_list.append((concat_name, self.__lookup_dict[0][metaphone_tuple[0]])) | |
print("Match with "+ match_list.__str__()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_person_to_lookup_directory(self, person_id, name_tuple): | |
tuples = self.generate_combinations(name_tuple) | |
self.add_combinations_to_directory(tuples, person_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
def generate_normalized_name(cls, name_tuple): | |
name_arr = list(name_tuple) | |
name_arr.sort() | |
name_str = ''.join(name_arr) | |
return name_str.lower() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_combinations_to_directory(self, comb_tuples, person_id): | |
for comb in comb_tuples: | |
concat_name = self.generate_normalized_name(comb) | |
metaphone_tuple = doublemetaphone(concat_name) | |
if metaphone_tuple[0] in self.__lookup_dict[0]: | |
if not person_id in self.__lookup_dict[0][metaphone_tuple[0]]: | |
self.__lookup_dict[0][metaphone_tuple[0]].append(person_id) | |
else: | |
self.__lookup_dict[0][metaphone_tuple[0]] = [person_id] | |
if metaphone_tuple[1] in self.__lookup_dict[1]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
def generate_combinations(cls,name_tuple): | |
coms = [] | |
coms.append(name_tuple) | |
i = len(list(name_tuple))-1 | |
while i > 0: | |
coms.extend(itertools.combinations(name_tuple,i)) | |
i -=1 | |
return coms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_tw_politican_table(self, apidef): | |
# Panda Data Frame - Table of all Parliament Members | |
panda_data = { 'ScreenName' : self.__col_screen_name, | |
'Name': self.__col_name, | |
'Description': self.__col_description, | |
"FollowersCount": self.__col_followers_count, | |
"FriendsCount": self.__col_friends_count, | |
"Party": self.__col_party | |
} | |
df = DataFrame(panda_data, index=self.__labels) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __calculate_name_matching(self, row): | |
name = row['Name'] | |
for clean in self.__cfg['twitterNameCleaner']: | |
name = name.replace(clean ,'') | |
for expand in self.__cfg['twitterNamesExpander']: | |
name = name.replace(expand.get('abbreviation'), expand.get('name')) | |
norm_name = sort_words(normalize_unicode_to_ascii(name)) | |
tp = double_metaphone(norm_name) | |
row['col_match1'] = norm_name | |
row['col_match2'] = tp[0] |