<jupyter_start><jupyter_text>Using corpus of names<jupyter_code>def format_names():
    female_fn = '../names/female.txt'
    male_fn = '../names/male.txt'

    males = pd.read_csv(male_fn, skiprows=4)
    males.rename(columns={males.columns[0]:'MaleNames'}, inplace=True)

    females = pd.read_csv(female_fn, skiprows=4)
    females.rename(columns={females.columns[0]:'FemaleNames'}, inplace=True)

    merged = females.combine_first(males)
    merged = merged.applymap(lambda s:s.lower() if type(s) == str else s)
    
    return merged
merged = format_names()
merged.head()
def check_name_sex(name, merged):
    name = name.lower()
    maleflags = merged['MaleNames'].eq(name).any()
    femaleflags = merged['FemaleNames'].eq(name).any()
    if maleflags and femaleflags:
        val = 'ambiguous'
    elif maleflags:
        val = 'male'
    elif femaleflags:
        val = 'female'
    else:
        val = 'unknown'
    print('The name {0} was decided to be {1}'.format(name, val))
    return val
        
benchmark_names = ['john', 'mary', 'jean', 'ali', 'susan','mamta','harry','hermione','ron','peter','marvin','julie','jeremy','salvador']
for i in benchmark_names:
    check_name_sex(i, merged)<jupyter_output>The name john was decided to be male
The name mary was decided to be female
The name jean was decided to be ambiguous
The name ali was decided to be ambiguous
The name susan was decided to be female
The name mamta was decided to be unknown
The name harry was decided to be male
The name hermione was decided to be female
The name ron was decided to be male
The name peter was decided to be male
The name marvin was decided to be male
The name julie was decided to be ambiguous
The name jeremy was decided to be male
The name salvador was decided to be male<jupyter_text>Using gender guesser<jupyter_code>import gender_guesser.detector as gender
d = gender.Detector()

for i in benchmark_names:
    #check_str = unicode(i.capitalize(), "utf-8")
    #check_str = i.capitalize().decode("utf-8")
    print("The name {0} was decided to be {1}".format(i, d.get_gender(i.capitalize())))
def gender_guesser(name):
    import gender_guesser.detector as gender
    d = gender.Detector()
    return(d.get_gender(name.capitalize()))
def check_name_contigency(name, names_df):
    val = check_name_sex(name, names_df)
    if val == 'unknown':
        val = gender_guesser(name)
        if val == 'mostly_female':
            return('female')
        elif val == 'mostly_male':
            return('male')
        elif val == 'andy':
            return('ambiguous')
    return(val)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11850152905198777, 'fraction_numerical': 0.00382262996941896, 'mean_word_length': 3.7755474452554743, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '250087', 'license': 'MIT', 'n_tokens_mistral': 888, 'n_tokens_neox': 864, 'n_words': 252, 'path': 'notebooks/data-wrangling.ipynb', 'repo_name': 'ssadhukha/hackdartmouth-v', 'size': '2616'}