def standardized_compound_names(original_names, map_pkl_path=default_map_pkl_path, id_type=standard_name): """ :param original_names: A list of original field names to be standardized :param map_pkl_path: Path to a pkl file containing mappings used to standardize the names :return: A list of standardized field names """ print 'Standardizing names to: {0}'.format(id_type) name_map = NameMap(map_pkl_path) standardized = original_names for i in range(len(standardized)): name = _strip_suffix(standardized[i]) if name in name_map: new_id = name_map[name][id_type] if id_type in name_map[ name] else name print '{0} --> {1}'.format(standardized[i], new_id) standardized[i] = new_id else: standardized[i] = name return standardized
print "Incorporating all name map files in {0}.".format( args.find_in_dir) name_map_files = [ join(args.find_in_dir, f) for f in listdir(args.find_in_dir) if f.endswith('.csv') ] # Find "manual" csv files and move them to the end so that their contents take priority. index_of_manual = filter( lambda j: 'manual' in basename(name_map_files[j]), range(len(name_map_files))) index_of_manual.sort(reverse=True) for i in index_of_manual: name_map_files.append(name_map_files.pop(i)) current_map = NameMap() if args.clear_first: current_map.clear() for f in name_map_files: print f if args.a: current_map.add_mappings(f) elif args.d: current_map.remove_mappings(f) elif args.prune_csv: name_map_utils.prune(f) else: print('There are currently {0} values in the name map.'.format( len(current_map)))
def setUp(self): self.name_map = NameMap('test_data/test_maps/test_map.pkl') self.name_map.clear() self.name_map['existing entry 1'] = {standard_name: 'foo'} self.name_map['existing entry 2'] = {standard_name: 'bar'} self.name_map._commit()
def setUp(self): self.name_map = NameMap('test_data/test_maps/test_map_0.pkl')