コード例 #1
0
ファイル: test_filters.py プロジェクト: Kyle-Falconer/namegen
 def test_exclude_origins_only_in_single(self):
     # assuming Spain appears in the exclude_only_origins list
     name1 = NameDefinition(
         name="name1",
         gender=Gender.girl,
         meanings=[NameMeaning("meaning1", [Region.Spain])])
     name2 = NameDefinition(
         name="name2",
         gender=Gender.girl,
         meanings=[NameMeaning("meaning1", [Region.India])])
     filtered = exclude_origins_only_in({"name1": name1, "name2": name2})
     assert len(filtered) is 1
     assert filtered == {"name2": name2}
コード例 #2
0
ファイル: test_filters.py プロジェクト: Kyle-Falconer/namegen
 def test_exclude_muslim_pure_filter(self):
     # test where the meaning only has the excluded meaning
     name1 = NameDefinition(
         name="name1",
         gender=Gender.girl,
         meanings=[NameMeaning("meaning1", [Region.Muslim])])
     name2 = NameDefinition(
         name="name2",
         gender=Gender.girl,
         meanings=[NameMeaning("meaning1", [Region.India])])
     filtered = exclude_muslim_names({"name1": name1, "name2": name2})
     assert len(filtered) is 1
     assert filtered == {"name2": name2}
コード例 #3
0
ファイル: test_filters.py プロジェクト: Kyle-Falconer/namegen
 def test_exclude_israeli_mixed_filter(self):
     # test where the meaning contains the excluded meaning
     name1 = NameDefinition(name="name1",
                            gender=Gender.girl,
                            meanings=[
                                NameMeaning("meaning1", [Region.Israel]),
                                NameMeaning("meaning2",
                                            [Region.United_States])
                            ])
     name2 = NameDefinition(
         name="name2",
         gender=Gender.girl,
         meanings=[NameMeaning("meaning1", [Region.India])])
     filtered = exclude_israeli_names({"name1": name1, "name2": name2})
     assert len(filtered) is 1
     assert filtered == {"name2": name2}
コード例 #4
0
ファイル: file_utils.py プロジェクト: Kyle-Falconer/namegen
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
コード例 #5
0
ファイル: test_filters.py プロジェクト: Kyle-Falconer/namegen
 def test_exclude_origins_only_in_multiple_exception(self):
     # assuming Spain and Latin_America both appear in the exclude_only_origins list
     name1 = NameDefinition(
         name="name1",
         gender=Gender.girl,
         meanings=[
             NameMeaning(
                 "meaning1",
                 [Region.Spain, Region.Latin_America, Region.United_States])
         ])
     name2 = NameDefinition(
         name="name2",
         gender=Gender.girl,
         meanings=[NameMeaning("meaning1", [Region.India])])
     filtered = exclude_origins_only_in({"name1": name1, "name2": name2})
     assert len(filtered) is 2
     assert filtered == {"name1": name1, "name2": name2}