Skip to content

Commit

Permalink
legacy: fix name parsing in API
Browse files Browse the repository at this point in the history
  • Loading branch information
lnielsen committed Sep 18, 2023
1 parent 5a3a565 commit accaf1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
20 changes: 14 additions & 6 deletions migrator/zenodo_rdm_migrator/transform/entries/records/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from idutils import detect_identifier_schemes
from invenio_rdm_migrator.transform import Entry, drop_nones
from nameparser import HumanName
from zenodo_legacy.funders import FUNDER_DOI_TO_ROR
from zenodo_legacy.licenses import LEGACY_LICENSES, legacy_to_rdm

Expand All @@ -32,11 +31,20 @@ def _person_or_org(cls, creatibutor):
r["identifiers"] = [
{"scheme": "orcid", "identifier": creatibutor["orcid"]},
]
name = HumanName(creatibutor["name"])
r["given_name"] = name.first
r["family_name"] = name.surnames
# autocompleted by RDM Metadata schema
r["name"] = f"{name.surnames}, {name.first}"

name = creatibutor["name"]

# We only split if users have strictly followed the input format.
if name.count(",") == 1:
family, given = name.split(",")
r["given_name"] = given.strip()
r["family_name"] = family.strip()
# autocompleted by RDM Metadata schema
r["name"] = name
else:
r["family_name"] = name
# autocompleted by RDM Metadata schema
r["name"] = name

return r

Expand Down
9 changes: 6 additions & 3 deletions site/zenodo_rdm/legacy/deserializers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ def load_names(self, result, original, **kwargs):
name = original.get("name")

if name:
human_name = HumanName(name)
result["given_name"] = human_name.first
result["family_name"] = human_name.surnames
if name.count(",") == 1:
family, given = name.split(",")
result["given_name"] = given.strip()
result["family_name"] = family.strip()
else:
result["family_name"] = name

return result

Expand Down

0 comments on commit accaf1a

Please sign in to comment.