def intake_mon_names( names: Dict[str, NameDefinition] = None) -> Dict[str, NameDefinition]: print(f"reading names from {meaning_of_names_filename}") number_merged = 0 number_added = 0 if names is None: names = {} with open(meaning_of_names_filename) as csvfile: csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"') for row in csvreader: if row['name'] in names and names[row['name']] is not None: existing_name = names[row['name']] existing_name.append_attrs( gender=Gender.from_str(row['gender']), origin=Region.from_str(row['origin']), meaning=row['meaning'], source=NameSource.meaning_of_names) names[row['name']] = existing_name number_merged = number_merged + 1 else: names[row['name']] = NameDefinition( name=row['name'], gender=Gender.from_str(row['gender']), origin=Region.from_str(row['origin']), meaning=row['meaning'], source=NameSource.meaning_of_names) number_added = number_added + 1 print( f"added {number_added} and merged/updated {number_merged} name definitions from the meaning-of-names.com" ) return names
def intake_ssa_names( names: Dict[str, NameDefinition] = None) -> Dict[str, NameDefinition]: print(f"reading names from {ssa_names_filename}") number_merged = 0 number_added = 0 if names is None: names = {} with open(ssa_names_filename) as csvfile: csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"') for row in csvreader: if row['name'] in names and names[row['name']] is not None: existing_name = names[row['name']] existing_name.append_attrs(gender=Gender.from_str(row['sex']), source=NameSource.ssa) names[row['name']] = existing_name number_merged = number_merged + 1 else: names[row['name']] = NameDefinition(name=row['name'], gender=Gender.from_str( row['sex']), source=NameSource.ssa) number_added = number_added + 1 print( f"added {number_added} and merged/updated {number_merged} name definitions from the SSA" ) return names
def intake_indian_names( names: Dict[str, NameDefinition] = None) -> Dict[str, NameDefinition]: print(f"reading names from {indian_names_filename}") number_merged = 0 number_added = 0 if names is None: names = {} with open(indian_names_filename) as csvfile: csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"') for row in csvreader: if row['Name'] in names and names[row['Name']] is not None: existing_name = names[row['Name']] existing_name.append_attrs( gender=Gender.from_str(row['Gender']), meaning=row['Meaning'], origin=Region.from_str(row['Language']), source=NameSource.tamilcube) names[row['Name']] = existing_name number_merged = number_merged + 1 else: names[row['Name']] = NameDefinition( name=row['Name'], gender=Gender.from_str(row['Gender']), meaning=row['Meaning'], origin=Region.from_str(row['Language']), source=NameSource.tamilcube) number_added = number_added + 1 print( f"added {number_added} and merged/updated {number_merged} Indian name definitions" ) return names
def intake_pantheon( names: Dict[str, NameDefinition] = None) -> Dict[str, NameDefinition]: print(f"reading names from {pantheon_filename}") number_merged = 0 number_added = 0 if names is None: names = {} with open(pantheon_filename) as csvfile: csvreader = csv.DictReader(csvfile, delimiter='\t', quotechar='"') for row in csvreader: person_fname = row['name'].split(' ')[0] famous_person = f"{row['occupation'].title()} {row['name']}" if person_fname in names and names[person_fname] is not None: existing_name = names[person_fname] existing_name.append_attrs( gender=Gender.from_str(row['gender']), origin=Region.from_str(row['countryName']), known_persons=famous_person, source=NameSource.pantheon) names[person_fname] = existing_name number_merged = number_merged + 1 else: names[person_fname] = NameDefinition( name=person_fname, gender=Gender.from_str(row['gender']), origin=Region.from_str(row['countryName']), known_persons=famous_person, source=NameSource.pantheon) number_added = number_added + 1 print( f"added {number_added} and merged/updated {number_merged} name definitions from the pantheon" ) return names
def read_names_json(filename: str) -> Dict[str, NameDefinition]: names = {} with open(filename) as jsonfile: data = json.load(jsonfile) number_merged = 0 for record in data: meanings_list = [] for m in record['meanings']: meanings_list.append( NameMeaning(meaning=m['meaning'], origins=m['origins'])) if record['name'] in names and names[record['name']] is not None: existing_name = names[record['name']] existing_name.append_attrs( gender=Gender.from_str(record['gender']), meanings=meanings_list, known_persons=record['known_persons'], source=record['source']) names[record['name']] = existing_name number_merged = number_merged + 1 else: names[record['name']] = NameDefinition( name=record['name'], gender=Gender.from_str(record['gender']), meanings=meanings_list, known_persons=record['known_persons'], source=record['source']) print(f"merged {number_merged} names") return names
def intake_star_trek( names: Dict[str, NameDefinition] = None) -> Dict[str, NameDefinition]: print(f"reading names from {star_trek_filename}") number_merged = 0 number_added = 0 if names is None: names = {} with open(star_trek_filename) as csvfile: csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"') for row in csvreader: if len(row['First Name'].strip()) == 0: continue rank = '' if row['Rank'] and row['Rank'].lower() != "civilian": rank = row['Rank'].split(',')[0].strip() if len(rank) != 0: rank = f"{rank} " first_name = f"{row['First Name']}" character_name = f"{rank}{row['Character']} from Star Trek" if first_name in names and names[first_name] is not None: existing_name = names[first_name] existing_name.append_attrs(gender=Gender.from_str( row['Gender']), known_persons=character_name, source=NameSource.star_trek) names[first_name] = existing_name number_merged = number_merged + 1 else: names[first_name] = NameDefinition( name=first_name, gender=Gender.from_str(row['Gender']), known_persons=character_name, source=NameSource.star_trek) number_added = number_added + 1 print( f"added {number_added} and merged/updated {number_merged} name definitions from Star Trek" ) return names
def test_gender_male(self): assert Gender.from_str('male') is Gender.boy
def test_gender_boy(self): assert Gender.from_str('boy') is Gender.boy
def test_gender_invalid(self): with pytest.raises(NotImplementedError): Gender.from_str('')
def test_gender_other(self): assert Gender.from_str('other') is Gender.unisex
def test_gender_unisex(self): assert Gender.from_str('unisex') is Gender.unisex
def test_gender_morf(self): assert Gender.from_str('m or f') is Gender.unisex
def test_gender_g(self): assert Gender.from_str('g') is Gender.girl
def test_gender_f(self): assert Gender.from_str('f') is Gender.girl
def test_gender_female(self): assert Gender.from_str('female') is Gender.girl
def test_gender_m(self): assert Gender.from_str('m') is Gender.boy