def name_frec(self, name, *args, **kwargs): # guess list method dataset = kwargs.get('dataset', 'es') du = DameUtils() name = du.drop_accents(name) path_males = 'files/names/names_es/esmasculinos.csv' if ((dataset == 'ine') or (dataset == 'es')): path_males = 'files/names/names_es/esmasculinos.csv' elif (dataset == 'uy'): path_males = 'files/names/names_uy/uymasculinos.csv' elif (dataset == 'uk'): path_males = 'files/names/names_uk/ukmales.csv' elif (dataset == 'us'): path_males = 'files/names/names_us/usmales.csv' file_males = open(path_males, 'r') readerm = csv.reader(file_males, delimiter=',', quotechar='|') males = 0 for row in readerm: if ((len(row) > 1) and (row[0].lower() == name.lower())): males = row[1] males = du.drop_dots(males) path_females = 'files/names/names_es/esfemeninos.csv' if ((dataset == 'ine') or (dataset == 'es')): path_females = 'files/names/names_es/esfemeninos.csv' elif (dataset == 'uy'): path_females = 'files/names/names_uy/uyfemeninos.csv' elif (dataset == 'uk'): path_females = 'files/names/names_uk/ukfemales.csv' elif (dataset == 'us'): path_females = 'files/names/names_us/usfemales.csv' file_females = open(path_females, 'r') readerf = csv.reader(file_females, delimiter=',', quotechar='|') females = 0 for row in readerf: if ((len(row) > 1) and (row[0].lower() == name.lower())): females = row[1] females = du.drop_dots(females) dicc = {"females": females, "males": males} return dicc
def test_drop_dots_method_returns_correct_result(self): u = DameUtils() self.assertEqual(1212, int(u.drop_dots(12.12)))
def test_drop_dots(self): u = DameUtils() self.assertEqual(1212, int(u.drop_dots(12.12)))
def name_frec(self, name, dataset='ine'): if (dataset == 'ine'): du = DameUtils() name = du.drop_accents(name) file_males = open('files/names/names_es/masculinos_original.csv', 'r') inereader_males = csv.reader(file_males, delimiter=',', quotechar='|') males = 0 for row in inereader_males: if ((len(row) > 1) and (row[1].lower() == name.lower())): males = row[2] males = du.drop_dots(males) file_females = open('files/names/names_es/femeninos_original.csv', 'r') inereader_females = csv.reader(file_females, delimiter=',', quotechar='|') females = 0 for row in inereader_females: if ((len(row) > 1) and (row[1].lower() == name.lower())): females = row[2] females = du.drop_dots(females) dicc = {"females": females, "males": males} elif (dataset == 'uscensus'): du = DameUtils() usfile = open('files/names/yob2017.txt', 'r') usreader = csv.reader(usfile, delimiter=',', quotechar='|') males = 0 females = 0 for row in usreader: if ((len(row) > 1) and (row[0].lower() == name.lower())): if (row[1] == 'F'): females = row[2] elif (row[1] == 'M'): males = row[2] dicc = {"females": females, "males": males} elif (dataset == 'ukcensus'): du = DameUtils() name = du.drop_accents(name) file_males = open('files/names/2017boysnames-uk.csv', 'r') reader_males = csv.reader(file_males, delimiter=',', quotechar='|') males = 0 for row in reader_males: if (len(row) > 1): ukname = du.drop_accents(du.drop_white_space( row[1])).lower() if (ukname == name.lower()): ukname = du.drop_accents(du.drop_white_space( row[1])).lower() males = row[2] males = du.drop_dots(males) file_females = open('files/names/2017girlsnames-uk.csv', 'r') reader_females = csv.reader(file_females, delimiter=',', quotechar='|') females = 0 for row in reader_females: if (len(row) > 1): ukname = du.drop_accents(du.drop_white_space( row[1])).lower() if (ukname == name.lower()): females = row[2] females = du.drop_dots(females) dicc = {"females": females, "males": males} return dicc