Skip to content

Commit

Permalink
Infer geometry type if subjects include a geometry type
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
thatbudakguy committed Feb 27, 2023
1 parent e3d91fa commit 03bfb92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/geo_combine/geoblacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def enhance_metadata
metadata.each do |key, value|
translate_formats(key, value)
enhance_subjects(key, value)
infer_geometry_type_from_subject(key, value)
format_proper_date(key, value)
fields_should_be_array(key, value)
translate_geometry_type(key, value)
Expand Down Expand Up @@ -106,6 +107,17 @@ def translate_geometry_type(key, value)
metadata[key] = geometry_types[value]
end

##
# Enhances empty 'layer_geom_type_s' field by populating from related subject
def infer_geometry_type_from_subject(key, value)
return unless key == 'layer_geom_type_s' && value.blank?

# If any subjects match a known geometry type, use the first that does as the geometry type
metadata['dc_subject_sm'].find { |subject| geometry_types.value?(subject.capitalize) }&.tap do |subject|
metadata[key] = subject.capitalize
end
end

##
# Enhances the 'dc_subject_sm' field by translating subjects to ISO topic
# categories
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/geo_combine/geoblacklight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
it 'formats the geometry type field' do
expect(enhanced_geobl.metadata['layer_geom_type_s']).to eq 'Polygon'
end

it 'populates the geometry type field from the subject field if not set' do
enhanced_from_subject_geobl = described_class.new(basic_geoblacklight, 'dc_subject_sm' => ['polygon'])
enhanced_from_subject_geobl.enhance_metadata
expect(enhanced_from_subject_geobl.metadata['layer_geom_type_s']).to eq 'Polygon'
end
end

describe '#valid?' do
Expand Down

0 comments on commit 03bfb92

Please sign in to comment.