Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonavellecuerdo committed Mar 11, 2024
1 parent 95349bd commit d47375c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions transmogrifier/sources/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,20 @@ def create_locations_from_spatial_subjects(fields: dict) -> dict:
Args:
fields: A dict of fields representing a TIMDEX record.
"""
if not (subjects := fields.get("subjects")):
# this condition is required when Datacite derives None for subjects
if fields.get("subjects") is None:
return fields

if not (
spatial_subjects := list(
filter(
lambda subject: subject.kind == "Dublin Core; Spatial", subjects # type: ignore[arg-type]
)
)
spatial_subjects := [
subject
for subject in fields.get("subjects", []) # defaults to empty list
if subject.kind == "Dublin Core; Spatial" and subject.value is not None
]
):
return fields

for subject in spatial_subjects:
if not subject.value:
continue

for place_name in subject.value:
subject_location = timdex.Location(value=place_name, kind="Place Name")
if subject_location not in fields.setdefault("locations", []):
Expand Down

0 comments on commit d47375c

Please sign in to comment.