Skip to content

Commit

Permalink
Map Aardvark.dct_spatial_sm to Locations@kind="Place Name"
Browse files Browse the repository at this point in the history
Why these changes are being introduced:
* Support place names for location-based searching

How this addresses that need:
* Update MITAardvark.get_locations field method to use 'dct_spatial_sm'

Side effects of this change:
* None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/GDT-217
  • Loading branch information
jonavellecuerdo committed Mar 11, 2024
1 parent 599097f commit 82f81d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tests/sources/json/test_aardvark.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def test_aardvark_get_locations_success(aardvark_record_all_fields):
kind="Bounding Box", geoshape="BBOX (-111.1, -104.0, 45.0, 40.9)"
),
timdex.Location(kind="Geometry", geoshape="BBOX (-111.1, -104.0, 45.0, 40.9)"),
timdex.Location(value="Some city, Some country", kind="Place Name"),
]


Expand All @@ -253,7 +254,9 @@ def test_parse_get_locations_string_invalid_geostring_logs_warning(
aardvark_record = next(aardvark_record_all_fields)
aardvark_record["dcat_bbox"] = "Invalid"
aardvark_record["locn_geometry"] = "Invalid"
assert MITAardvark.get_locations(aardvark_record, "123") == []
assert MITAardvark.get_locations(aardvark_record, "123") == [
timdex.Location(value="Some city, Some country", kind="Place Name")
]
assert (
"Record ID '123': Unable to parse geodata string 'Invalid' in 'dcat_bbox'"
in caplog.text
Expand Down
10 changes: 10 additions & 0 deletions transmogrifier/sources/json/aardvark.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,20 @@ def get_locations(
aardvark_location_fields = {
"dcat_bbox": "Bounding Box",
"locn_geometry": "Geometry",
"dct_spatial_sm": "Place Name",
}
for aardvark_location_field, kind_value in aardvark_location_fields.items():
if aardvark_location_field not in source_record:
continue

if aardvark_location_field == "dct_spatial_sm":
locations.extend(
[
timdex.Location(value=place_name, kind=kind_value)
for place_name in source_record.get(aardvark_location_field, [])
]
)

if (
geodata_string := source_record[aardvark_location_field]
) and "ENVELOPE" in source_record[aardvark_location_field]:
Expand Down

0 comments on commit 82f81d8

Please sign in to comment.