From 28f587edb790b11b9ecb71ad61fb6e9b7b92cf07 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 23 Mar 2021 11:30:44 +0100 Subject: [PATCH 1/2] Add support for multiple geolocation polygons This is to match what is supported in datacite metadata. Fixes #68 --- lib/bolognese/readers/datacite_reader.rb | 5 +- .../datacite-geolocationpolygons-multiple.xml | 56 +++++++++++++++++++ spec/readers/datacite_reader_spec.rb | 22 ++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/datacite-geolocationpolygons-multiple.xml diff --git a/lib/bolognese/readers/datacite_reader.rb b/lib/bolognese/readers/datacite_reader.rb index 28b1bc61..fe93a10c 100644 --- a/lib/bolognese/readers/datacite_reader.rb +++ b/lib/bolognese/readers/datacite_reader.rb @@ -237,7 +237,10 @@ def read_datacite(string: nil, **options) "southBoundLatitude" => gl.dig("geoLocationBox", "southBoundLatitude"), "northBoundLatitude" => gl.dig("geoLocationBox", "northBoundLatitude") }.compact.presence, - "geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon", "polygonPoint")).map { |glp| { "polygonPoint" => glp } }.compact.presence, + "geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon")).map do |glp| + Array.wrap(glp.dig("polygonPoint")).map { |glpp| { "polygonPoint" => glpp } }.compact.presence + end, + # "geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon", "polygonPoint")).map { |glp| { "polygonPoint" => glp } }.compact.presence, "geoLocationPlace" => parse_attributes(gl["geoLocationPlace"], first: true).to_s.strip.presence }.compact end diff --git a/spec/fixtures/datacite-geolocationpolygons-multiple.xml b/spec/fixtures/datacite-geolocationpolygons-multiple.xml new file mode 100644 index 00000000..e5e3bf6f --- /dev/null +++ b/spec/fixtures/datacite-geolocationpolygons-multiple.xml @@ -0,0 +1,56 @@ + + +10.5072/multiplegeopolygons + + + John Smithy + + + + Multiple Geopolygon testing + + XML + DataCite + 2021 + + + + + 41 + 71 + + + 45 + 75 + + + 55 + 85 + + + 41 + 71 + + + + + 65 + 80 + + + 55 + 75 + + + 45 + 73 + + + 65 + 80 + + + + + diff --git a/spec/readers/datacite_reader_spec.rb b/spec/readers/datacite_reader_spec.rb index 0b7f4b21..533bdf07 100644 --- a/spec/readers/datacite_reader_spec.rb +++ b/spec/readers/datacite_reader_spec.rb @@ -1545,4 +1545,26 @@ expect(subject.formats.first).to eq("application/xml") end + it "Parsing multiple geolocationpolygon elements" do + input = fixture_path + "datacite-geolocationpolygons-multiple.xml" + subject = Bolognese::Metadata.new(input: input) + expect(subject.valid?).to be true + expect(subject.id).to eq("https://doi.org/10.5072/multiplegeopolygons") + expect(subject.geo_locations).to eq([ + { "geoLocationPolygon"=> [ + [ {"polygonPoint"=>{"pointLatitude"=>"71", "pointLongitude"=>"41"}}, + {"polygonPoint"=>{"pointLatitude"=>"75", "pointLongitude"=>"45"}}, + {"polygonPoint"=>{"pointLatitude"=>"85", "pointLongitude"=>"55"}}, + {"polygonPoint"=>{"pointLatitude"=>"71", "pointLongitude"=>"41"}}], + [ + {"polygonPoint"=>{"pointLatitude"=>"80", "pointLongitude"=>"65"}}, + {"polygonPoint"=>{"pointLatitude"=>"75", "pointLongitude"=>"55"}}, + {"polygonPoint"=>{"pointLatitude"=>"73", "pointLongitude"=>"45"}}, + {"polygonPoint"=>{"pointLatitude"=>"80", "pointLongitude"=>"65"}} + ] + ] } + ] + ) + end + end From 183ea9f1f06f50cd9a20dc5ebb591d43d247dcfe Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 23 Mar 2021 11:36:38 +0100 Subject: [PATCH 2/2] Remove dead code --- lib/bolognese/readers/datacite_reader.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bolognese/readers/datacite_reader.rb b/lib/bolognese/readers/datacite_reader.rb index fe93a10c..c81de246 100644 --- a/lib/bolognese/readers/datacite_reader.rb +++ b/lib/bolognese/readers/datacite_reader.rb @@ -240,7 +240,6 @@ def read_datacite(string: nil, **options) "geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon")).map do |glp| Array.wrap(glp.dig("polygonPoint")).map { |glpp| { "polygonPoint" => glpp } }.compact.presence end, - # "geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon", "polygonPoint")).map { |glp| { "polygonPoint" => glp } }.compact.presence, "geoLocationPlace" => parse_attributes(gl["geoLocationPlace"], first: true).to_s.strip.presence }.compact end