Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

countries: adds to country list and update enhancer for country #202

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dags/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
("United States", "USA"),
("USA", "USA"),
("U.S.A", "USA"),
("U.S.A.", "USA"),
("America", "USA"),
("Uruguay", "Uruguay"),
("Uzbekistan", "Uzbekistan"),
Expand Down
7 changes: 5 additions & 2 deletions dags/common/enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ def __construct_authors(self, item):
continue

if not affiliation.get("country"):
affiliation["country"] = parse_country_from_value(affiliation.get("value"))
_parsed_country = parse_country_from_value(affiliation.get("value"))
if _parsed_country:
affiliation["country"] = _parsed_country

affiliation["country"] = get_country_ISO_name(affiliation["country"])
if affiliation.get("country"):
affiliation["country"] = get_country_ISO_name(affiliation["country"])

return item

Expand Down
7 changes: 2 additions & 5 deletions dags/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,7 @@ def find_country_match_from_mapping(affiliation_value):
return COUNTRIES_DEFAULT_MAPPING[key]

def get_country_ISO_name(country):
if COUNTRIES_DEFAULT_MAPPING[country]:
if COUNTRIES_DEFAULT_MAPPING.get(country):
return COUNTRIES_DEFAULT_MAPPING[country]
countries = pycountry.countries.search_fuzzy(country)
if len(countries) > 1 or len(countries) == 0:
return country
else:
return countries[0].name
return country
11 changes: 11 additions & 0 deletions tests/units/aps/data/json_response_content.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@
"firstname": "Hailin",
"surname": "Wang",
"affiliationIds": ["a1", "a1"]
},
{
"type": "Person",
"name": "Tim R. Borel",
"firstname": "Tim R.",
"surname": "Borel",
"affiliationIds": ["a2"]
}
],
"affiliations": [
{
"name": "Department of Physics, University of Oregon, Eugene, Oregon 97403, USA",
"id": "a1"
},
{
"name": "Department of Physics, Tsinghua University, Beijing 100084",
"id": "a2"
}
],
"date": "2021-04-12",
Expand Down
12 changes: 12 additions & 0 deletions tests/units/aps/test_aps_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ def parsed_articles(parser, articles):
}
],
},
{
"full_name": "Tim R. Borel",
"given_names": "Tim R.",
"surname": "Borel",
"affiliations": [
{
"value": "Department of Physics, Tsinghua University, Beijing 100084",
"organization": "Department of Physics, Tsinghua University",
# "country": "China",
}
],
},
],
[
{
Expand Down
65 changes: 65 additions & 0 deletions tests/units/common/test_enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,66 @@
"record_creation_date": "2022-05-20T00:00:00",
"titles": [{"title": "title", "subtitle": "subtitle", "source": publisher}],
}
input_with_affiliation_value_only = {
"abstract": "this is abstracts",
"authors": [
{
"affiliations": [
{
"value": "Department of Physics, Tsinghua University, Beijing 100084",
"organization": "Department of Physics, Tsinghua University",
}
],
"email": "[email protected]",
"full_name": "Test Surname, Test names",
"given_names": "Test names",
"surname": "Test Surname",
"orcid": "Test Id",
}
],
"copyright_holder": "copyright_holder",
"copyright_year": "2020",
"copyright_statement": "copyright_statement",
"copyright_material": "copyright_material",
"date_published": "2022-05-20",
"title": "title",
"subtitle": "subtitle",
}
expected_output_with_affiliation_value_only = {
"abstracts": [{"value": "this is abstracts", "source": publisher}],
"authors": [
{
"affiliations": [
{
"value": "Department of Physics, Tsinghua University, Beijing 100084",
"organization": "Department of Physics, Tsinghua University",
# "country": "China"
}
],
"email": "[email protected]",
"full_name": "Test Surname, Test names",
"given_names": "Test names",
"surname": "Test Surname",
"orcid": "Test Id",
}
],
"acquisition_source": {
"source": publisher,
"method": publisher,
"date": "2022-05-20T00:00:00",
},
"copyright": [
{
"holder": "copyright_holder",
"year": "2020",
"statement": "copyright_statement",
"material": "copyright_material",
}
],
"imprints": [{"date": "2022-05-20", "publisher": publisher}],
"record_creation_date": "2022-05-20T00:00:00",
"titles": [{"title": "title", "subtitle": "subtitle", "source": publisher}],
}


@pytest.mark.parametrize(
Expand All @@ -231,6 +291,11 @@
expected_output_with_affiliation_of_cooperation_agreement_with_CERN,
publisher,
),
pytest.param(
input_with_affiliation_value_only,
expected_output_with_affiliation_value_only,
publisher,
),
],
)
@freeze_time("2022-05-20")
Expand Down
Loading