Skip to content

Commit

Permalink
Merge pull request #1209 from sul-dlss/description-type
Browse files Browse the repository at this point in the history
Use displayLabel and description[@type] when creating IIIF metadata
  • Loading branch information
corylown authored Feb 24, 2025
2 parents 278cea5 + 8f9bf15 commit 6ecd5d5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 32 deletions.
7 changes: 6 additions & 1 deletion app/models/iiif3_metadata_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ def write

private

def dc_metadata
def dc_metadata # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
nodes_by_name = dc_nodes.group_by(&:name)
nodes_by_name['relation']&.reject! { it['type'] == 'url' }
if nodes_by_name['description']
nodes_with_display_label, description = nodes_by_name['description'].partition { it['displayLabel'] || it['type'] }
nodes_by_name['description'] = description
nodes_by_name.merge!(nodes_with_display_label.group_by { it['displayLabel'] || it['type'] })
end
nodes_by_name.map { |key, values| iiif_key_value(key.upcase_first, values.map(&:text)) }
end

Expand Down
20 changes: 16 additions & 4 deletions spec/model/iiif3_metadata_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<dc:type>Policy brief</dc:type>
<dc:type>Text</dc:type>
<dc:description>This is the abstract field</dc:description>
<dc:description type="preferred citation">
Author, F. (2025). H2 title field. Version 1. Stanford Digital Repository. Available at https://sul-purl-stage.stanford.edu/zw438wf4318/version/1. https://doi.org/10.80343/zw438wf4318.
</dc:description>
<dc:description type="preferred citation">This is the citation</dc:description>
<dc:subject>keyword</dc:subject>
<dc:date>2025-02-20</dc:date>
<dc:date>2024-04-05</dc:date>
Expand All @@ -36,10 +34,24 @@
describe '#write' do
subject(:metadata) { metadata_writer.write }

context 'with relation type="url"' do
context 'with relation[@type="url"]' do
it 'filters out the url value' do
expect(metadata.find { it['label'][:en] == ['Relation'] }['value'][:en]).to eq ['viewer testing']
end
end

context 'with description[@displayLabel]' do
it 'filters uses the displayLabel value' do
expect(metadata.find { it['label'][:en] == ['Description'] }['value'][:en]).not_to include '[email protected]'
expect(metadata.find { it['label'][:en] == ['Contact'] }['value'][:en]).to eq ['[email protected]']
end
end

context 'with description[@type]' do
it 'filters uses the type value' do
expect(metadata.find { it['label'][:en] == ['Description'] }['value'][:en]).not_to include 'This is the citation'
expect(metadata.find { it['label'][:en] == ['Preferred citation'] }['value'][:en]).to eq ['This is the citation']
end
end
end
end
65 changes: 38 additions & 27 deletions spec/requests/iiif3_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@
let(:json) { response.parsed_body }

context 'without a version' do
# rubocop:disable Layout/LineLength
let(:expected_dc_metadata) do
[
{ 'label' => { 'en' => ['Available Online'] }, 'value' => { 'en' => ["<a href='http://www.example.com/bb157hs6068'>http://www.example.com/bb157hs6068</a>"] } },
{ 'label' => { 'en' => ['Title'] }, 'value' => { 'en' => ['NOUVELLE CARTE DE LA SPHERE POUR FAIRE CONNOITRE LES DIVERS MOUVEMENS DES PLANETES ET LEURS DIVERSES REVOLUTIONS, AVEC DES REMARQUES HISTORIQUES POUR CONDUIRE A CETTE CONNOISSANCE'] } },
{ 'label' => { 'en' => ['Creator'] }, 'value' => { 'en' => ['Chatelain, Henri Abraham'] } },
{ 'label' => { 'en' => ['Type'] }, 'value' => { 'en' => ['map', 'Digital Maps', 'Early Maps'] } },
{ 'label' => { 'en' => ['Format'] }, 'value' => { 'en' => ['51.5 x 59.8 cm., including title along top and border, with 10 diagrams/maps and 6 columns of titled text.'] } },
{ 'label' => { 'en' => ['Description'] }, 'value' => { 'en' => [
'Tom.1. No.9. (top right).',
'California, with open northern edge, suggesting it may be an island and that northwest passage may exist, on 2 small hemisphere maps, each with 5 cm. diameter. First with title: Hemisphere terrestre pour faire | observer les 6 grands cercles de la sphere. Second with title: Hemisphere terrestre pour dis= tinguer les 4 petits cercles, et les 5 zo.',
"The larger diagrams are entitled: Le monde selon l'hypothese de copernic et la disposition des planetes ala naissance de Louis XIV, Sphere artificielle, Sisteme de Copernic sur les divers mouvemens des planetes, Sisteme de Ticho Brahe,Sisteme de Ptolomée, Idee generale pour faire comprendre les divers signes que la terre parcourt autour du soleil qui servent a regler les saisons (celestial chart).",
"The text is entitled: Remarque sur les divers mouvemens de la terre, Remarque sur le mouvemens et l'arrangement des planetes, Remarque sur la sphere, Remarque sur la maniere dont se font les saisons, Suite de la remarque sur la sphere, Conclusion et reflection morale, Comment l'hypothese de Copernic est conforme aux loix du mouvemens et de la nature, Inconveniens et difficultez qui resultent des sistemes de Ptolemeé et Ticho Brahe."
] } },
{ 'label' => { 'en' => ['Subject'] }, 'value' => { 'en' => ['Astronomy--Charts, diagrams, etc', 'California as an island--Maps'] } },
{ 'label' => { 'en' => ['Coverage'] }, 'value' => { 'en' => ['W 180° --E 180°/N 85° --S 85°'] } },
{ 'label' => { 'en' => ['Date'] }, 'value' => { 'en' => ['1721'] } },
{ 'label' => { 'en' => ['Identifier'] }, 'value' => { 'en' => ['1040', 'https://purl.stanford.edu/bb157hs6068'] } },
{ 'label' => { 'en' => ['Relation'] }, 'value' => { 'en' => ['The Glen McLaughlin Map Collection of California as an Island'] } },
{ 'label' => { 'en' => ['References'] },
'value' =>
{ 'en' =>
['LC 548, 579; Koeman II, Cha 1,2; UCB; Ashley Baynton-Williams.'] } },
{ 'label' => { 'en' => ['Publications'] },
'value' =>
{ 'en' =>
["First issued in his: Atlas historique, ou nouvelle introduction a l'histoire , à la chronologie & à la géographie ancienne & moderne ... -- Amsterdam. 1705. Reissued in 1721 (with imprint as above)."] } },
{ 'label' => { 'en' => ['Statement of responsibility'] },
'value' => { 'en' => ['[Henry Abraham Châtelain].'] } },
{ 'label' => { 'en' => ['PublishDate'] }, 'value' => { 'en' => ['2023-10-27T10:25:22Z'] } } # publish date was added
]
# rubocop:enable Layout/LineLength
end

it 'is successful' do
get '/bb157hs6068/iiif3/manifest'

Expand Down Expand Up @@ -34,31 +68,8 @@
expect(image['body']['id']).to eq 'https://stacks.stanford.edu/image/iiif/bb157hs6068/bb157hs6068_05_0001/full/full/0/default.jpg'

expect(json['metadata'].class).to eq Array
expect(json['metadata'].size).to eq(12) # 10 DC elements grouped by name are there + the publish date + Available Online
# rubocop:disable Layout/LineLength
expected_dc_metadata = [
{ 'label' => { 'en' => ['Available Online'] }, 'value' => { 'en' => ["<a href='http://www.example.com/bb157hs6068'>http://www.example.com/bb157hs6068</a>"] } },
{ 'label' => { 'en' => ['Title'] }, 'value' => { 'en' => ['NOUVELLE CARTE DE LA SPHERE POUR FAIRE CONNOITRE LES DIVERS MOUVEMENS DES PLANETES ET LEURS DIVERSES REVOLUTIONS, AVEC DES REMARQUES HISTORIQUES POUR CONDUIRE A CETTE CONNOISSANCE'] } },
{ 'label' => { 'en' => ['Creator'] }, 'value' => { 'en' => ['Chatelain, Henri Abraham'] } },
{ 'label' => { 'en' => ['Type'] }, 'value' => { 'en' => ['map', 'Digital Maps', 'Early Maps'] } },
{ 'label' => { 'en' => ['Format'] }, 'value' => { 'en' => ['51.5 x 59.8 cm., including title along top and border, with 10 diagrams/maps and 6 columns of titled text.'] } },
{ 'label' => { 'en' => ['Description'] }, 'value' => { 'en' => [
'Tom.1. No.9. (top right).',
'LC 548, 579; Koeman II, Cha 1,2; UCB; Ashley Baynton-Williams.',
'California, with open northern edge, suggesting it may be an island and that northwest passage may exist, on 2 small hemisphere maps, each with 5 cm. diameter. First with title: Hemisphere terrestre pour faire | observer les 6 grands cercles de la sphere. Second with title: Hemisphere terrestre pour dis= tinguer les 4 petits cercles, et les 5 zo.',
"The larger diagrams are entitled: Le monde selon l'hypothese de copernic et la disposition des planetes ala naissance de Louis XIV, Sphere artificielle, Sisteme de Copernic sur les divers mouvemens des planetes, Sisteme de Ticho Brahe,Sisteme de Ptolomée, Idee generale pour faire comprendre les divers signes que la terre parcourt autour du soleil qui servent a regler les saisons (celestial chart).",
"The text is entitled: Remarque sur les divers mouvemens de la terre, Remarque sur le mouvemens et l'arrangement des planetes, Remarque sur la sphere, Remarque sur la maniere dont se font les saisons, Suite de la remarque sur la sphere, Conclusion et reflection morale, Comment l'hypothese de Copernic est conforme aux loix du mouvemens et de la nature, Inconveniens et difficultez qui resultent des sistemes de Ptolemeé et Ticho Brahe.",
"First issued in his: Atlas historique, ou nouvelle introduction a l'histoire , à la chronologie & à la géographie ancienne & moderne ... -- Amsterdam. 1705. Reissued in 1721 (with imprint as above).",
'[Henry Abraham Châtelain].'
] } },
{ 'label' => { 'en' => ['Subject'] }, 'value' => { 'en' => ['Astronomy--Charts, diagrams, etc', 'California as an island--Maps'] } },
{ 'label' => { 'en' => ['Coverage'] }, 'value' => { 'en' => ['W 180° --E 180°/N 85° --S 85°'] } },
{ 'label' => { 'en' => ['Date'] }, 'value' => { 'en' => ['1721'] } },
{ 'label' => { 'en' => ['Identifier'] }, 'value' => { 'en' => ['1040', 'https://purl.stanford.edu/bb157hs6068'] } },
{ 'label' => { 'en' => ['Relation'] }, 'value' => { 'en' => ['The Glen McLaughlin Map Collection of California as an Island'] } },
{ 'label' => { 'en' => ['PublishDate'] }, 'value' => { 'en' => ['2023-10-27T10:25:22Z'] } } # publish date was added
]
# rubocop:enable Layout/LineLength
expect(json['metadata'].size).to eq(15)

expect(json['metadata']).to eq(expected_dc_metadata)
end
end
Expand Down Expand Up @@ -144,7 +155,7 @@
get '/zf119tw4418/iiif3/manifest'

expect(json['items'].length).to eq 58
expect(json['metadata'].length).to eq 13
expect(json['metadata'].length).to eq 15
end

context 'when pages do not have OCR content' do
Expand Down Expand Up @@ -347,7 +358,7 @@
get "/#{druid}/iiif3/manifest"
expect(response).to have_http_status(:ok)
expect(json['label']['en'].first).to eq '10 Meter Contours: Russian River Basin, California'
expect(json['metadata'].size).to eq 14
expect(json['metadata'].size).to eq 19
end
end

Expand Down

0 comments on commit 6ecd5d5

Please sign in to comment.