def test_dame_nameapi_guess_list_method_returns_correct_result(self): dna = DameNameapi() if (dna.config['DEFAULT']['nameapi'] == 'yes'): jsonf1 = 'files/names/nameapifiles_names_partial.csv.json' l = dna.json2guess_list(jsonf1, binary=True) self.assertEqual(l, [1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 1, 1])
def test_dame_nameapi_confusion_matrix_json_returns_correct_result(self): dna = DameNameapi() jsonf = 'files/names/nameapifiles_names_min.csv.json' if (dna.config['DEFAULT']['nameapi'] == 'yes'): cm = dna.confusion_matrix_gender(path="files/names/min.csv", dimensions="2x3", jsonf=jsonf) self.assertEqual([[1, 0, 0], [0, 5, 0]], cm)
def test_dame_nameapi_guess_list_method_returns_correct_result(self): g = DameNameapi() if (g.config['DEFAULT']['nameapi'] == 'yes'): self.assertEqual([ 'male', 'male', 'male', 'male', 'male', 'male', 'female', 'female', 'male', 'male', 'male', 'male', 'male', 'male', 'neutral', 'male', 'male', 'male', 'female', 'male', 'male' ], g.guess_list(path="files/names/partial.csv", binary=False)) self.assertEqual([ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 1, 1 ], g.guess_list(path="files/names/partial.csv", binary=True))
def test_dame_nameapi_gender_list_method_returns_correct_result(self): g = DameNameapi() gl = g.gender_list() if (g.config['DEFAULT']['nameapi'] == 'yes'): self.assertEqual(gl, [ 1, 1, 1, 1, 2, 1, 0, 0, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]) self.assertEqual(len(gl), 21) self.assertEqual(g.females, 3) self.assertEqual(g.males, 16) self.assertEqual(g.unknown, 2)
ds = DameSexmachine() ds.pretty_gg_list(path=args.csv, jsonf=args.jsondownloaded, measure=args.measure, api='Damegender') if (dg.config['DEFAULT']['genderapi'] == 'yes'): dga = DameGenderApi() dga.pretty_gg_list(path=args.csv, jsonf=args.jsondownloaded, measure=args.measure, api='Genderapi') if (dg.config['DEFAULT']['nameapi'] == 'yes'): dna = DameNameapi() dna.pretty_gg_list(path=args.csv, jsonf=args.jsondownloaded, measure=args.measure, api='Nameapi') elif (args.api == "namsor"): dn = DameNamsor() dn.pretty_gg_list(path=args.csv, jsonf=args.jsondownloaded, measure=args.measure, api='Namsor') elif (args.api == "genderize"): dg = DameGenderize() dg.pretty_gg_list(path=args.csv,
ds = DameSexmachine() print("################### Dame Gender!!") gl = ds.gender_list(path=args.csv) print("Gender list: " + str(gl)) sl = ds.guess_list(path=args.csv, binary=True) print("Guess list: " +str(sl)) sexmachine_accuracy = ds.accuracy_score_dame(gl,sl) print("Sexmachine accuracy: %s" % sexmachine_accuracy) dga = DameGenderApi() print("################### GenderApi!!") gl = dga.gender_list(pat=args.csv) print("Gender list: " + str(gl)) dna = DameNameapi() print("################### Nameapi!!") gl = dna.gender_list(path=args.csv) print("Gender list: " + str(gl)) sl = dna.guess_list(path=args.csv, binary=True) print("Guess list: " +str(sl)) nameapi_accuracy = dna.accuracy_score_dame(gl,sl) print("Nameapi accuracy: %s" % nameapi_accuracy) elif (args.api == "namsor"): dn = DameNamsor() print("################### Namsor!!") gl = dn.gender_list(path=args.csv) print("Gender list: " + str(gl)) sl = dn.guess_list(path=args.csv, binary=True) print("Guess list: " +str(sl))
args = parser.parse_args() if (args.api == 'genderize'): dg = DameGenderize() text1 = dg.download(path=args.csv, surnames=args.surnames) elif (args.api == 'genderapi'): dga = DameGenderApi() if (dga.config['DEFAULT']['genderapi'] == 'yes'): if (dga.apikey_limit_exceeded_p() == False): text1 = dga.download(path=args.csv) elif (dga.apikey_count_requests() < len(dga.csv2names(args.csv))): print("You don't have enough requests with this api key") elif (dga.apikey_count_requests() >= len(dga.csv2names(args.csv))): text1 = dga.download(path=args.csv) else: print("You have not money with this api key") else: print("You must enable genderapi in config.cfg") elif (args.api == 'namsor'): dn = DameNamsor() if (dn.config['DEFAULT']['namsor'] == 'yes'): text1 = dn.download(path=args.csv) else: print("You must enable namsor in config.cfg") elif (args.api == 'nameapi'): dna = DameNameapi() if (dna.config['DEFAULT']['nameapi'] == 'yes'): text1 = dna.download(path=args.csv) else: print("You must enable nameapi in config.cfg")
dg = DameGenderize() dg.pretty_cm(path=args.csv, jsonf=args.jsondownloaded, reverse=args.reverse, dimensions=args.dimensions, api=args.api.title()) # dg.print_confusion_matrix_gender(path=args.csv, dimensions=args.dimensions) if (dg.config['DEFAULT']['genderapi'] == 'yes'): dga = DameGenderApi() dga.pretty_cm(path=args.csv, jsonf=args.jsondownloaded, reverse=args.reverse, dimensions=args.dimensions, api=args.api.title()) dgg = DameGenderGuesser() dgg.print_confusion_matrix_gender(path=args.csv, dimensions=args.dimensions) ds = DameSexmachine() ds.pretty_cm(path=args.csv, jsonf=args.jsondownloaded, reverse=args.reverse, dimensions=args.dimensions, api=args.api.title()) if (dg.config['DEFAULT']['nameapi'] == 'yes'): dna = DameNameapi() dna.pretty_cm(path=args.csv, jsonf=args.jsondownloaded, reverse=args.reverse, dimensions=args.dimensions, api=args.api.title()) elif (args.api == "namsor"): dn = DameNamsor() dn.pretty_cm(path=args.csv, jsonf=args.jsondownloaded, reverse=args.reverse, dimensions=args.dimensions, api=args.api.title()) elif (args.api == "genderize"): dg = DameGenderize() dg.pretty_cm(path=args.csv, jsonf=args.jsondownloaded, reverse=args.reverse, dimensions=args.dimensions, api=args.api.title()) elif (args.api == "genderapi"): dga = DameGenderApi() dga.pretty_cm(path=args.csv, jsonf=args.jsondownloaded, reverse=args.reverse, dimensions=args.dimensions, api=args.api.title()) elif (args.api == "genderguesser"):
print("+ The error gender bias: %s" % egb) elif (args.api == "genderguesser"): d = DameGenderGuesser() print("Gender Guesser with %s has: " % args.csv) gl1 = d.gender_list(path=args.csv) gl2 = d.guess_list(path=args.csv, binary=True) ec = d.error_coded(gl1, gl2) print("+ The error code: %s" % ec) ecwa = d.error_coded_without_na(gl1, gl2) print("+ The error code without na: %s" % ecwa) naCoded = d.na_coded(gl1, gl2) print("+ The na coded: %s" % naCoded) egb = d.error_gender_bias(gl1, gl2) print("+ The error gender bias: %s" % egb) elif (args.api == "nameapi"): d = DameNameapi() print("Nameapi with %s has: " % args.csv) gl1 = d.gender_list(path=args.csv) if (os.path.isfile(args.jsondownloaded)): gl2 = d.json2guess_list(jsonf=args.jsondownloaded, binary=True) else: gl2 = d.guess_list(path=args.csv, binary=True) # gl2 = d.guess_list(path=args.csv, binary=True) ec = d.error_coded(gl1, gl2) print("+ The error code: %s" % ec) ecwa = d.error_coded_without_na(gl1, gl2) print("+ The error code without na: %s" % ecwa) naCoded = d.na_coded(gl1, gl2) print("+ The na coded: %s" % naCoded) egb = d.error_gender_bias(gl1, gl2) print("+ The error gender bias: %s" % egb)
def test_dame_nameapi_features_list_method_returns_correct_result(self): g = DameNameapi() fl = g.features_list() self.assertTrue(len(fl) > 20)
def test_dame_nameapi_gender_prob_method_returns_correct_result(self): g = DameNameapi() if (g.config['DEFAULT']['nameapi'] == 'yes'): self.assertTrue(0.8 < g.confidence("David", "Arroyo", binary=True))
def test_dame_nameapi_gender_guess_method_returns_correct_result(self): g = DameNameapi() if (g.config['DEFAULT']['nameapi'] == 'yes'): self.assertEqual(1, g.guess("David", "Arroyo", binary=True)) self.assertEqual(0, g.guess("Andrea", "Arroyo", binary=True))
def test_dame_nameapi_init_method_returns_correct_result(self): g = DameNameapi() self.assertEqual(g.males, 0) self.assertEqual(g.females, 0) self.assertEqual(g.unknown, 0)
du = DameUtils() if (len(sys.argv) > 1): if (args.api == "genderguesser"): dgg = DameGenderGuesser() print(dgg.guess(args.name)) elif (args.api == "genderapi"): dga = DameGenderApi() print(dga.guess(args.name, binary=False)) print("accuracy: " + str(dga.accuracy(args.name))) elif (args.api == "genderize"): dg = DameGenderize() print(dg.guess(args.name)) print("probability: " + str(dg.prob(args.name))) elif (args.api == "namsor"): dn = DameNamsor() if (du.is_not_blank(args.surname)): print(dn.guess(str(args.name), str(args.surname))) print("scale: " + str(dn.scale(str(args.name), str(args.surname)))) else: print("Surname is required in namsor api") elif (args.api == "nameapi"): dn = DameNameapi() print(dn.guess(str(args.name), str(args.surname))) print("confidence: " + str(dn.confidence(str(args.name), str(args.surname)))) elif (args.api == "average"): da = DameAll() average = da.average(args.name, args.surname) print("average: " + str(average))
def test_dame_nameapi_json2names(self): dn = DameNameapi() l = dn.json2names(jsonf="files/names/nameapifiles_names_min.csv.json") self.assertEqual(['Pierre', 'Raul', 'Adriano', 'Ralf', 'Guillermo', 'Sabina'], l)
def test_dame_nameapi_json2guess_list(self): dn = DameNameapi() j2gl = dn.json2guess_list(jsonf="files/names/namsorfiles_names_min.csv.json", binary=False) self.assertEqual(['male', 'male', 'male', 'male', 'male', 'female'], j2gl) j2gl = dn.json2guess_list(jsonf="files/names/namsorfiles_names_min.csv.json", binary=True) self.assertEqual([1, 1, 1, 1, 1, 0], j2gl)