Skip to content

Commit

Permalink
Enhance the RIS files and use the highwire meta tag conventions for m…
Browse files Browse the repository at this point in the history
…etadata output
  • Loading branch information
Adam Constabaris authored and Genia Kazymova committed Jan 19, 2024
1 parent 24616b2 commit c532034
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.15
2.2.16
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @document.highwire_metadata_tags.each do |name, content| %>
<meta name="<%= name %>" content="<%= content %>">
<% end %>
12 changes: 12 additions & 0 deletions app/components/trln_argon/highwire_metadata_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module TrlnArgon
class HighwireMetadataComponent < Blacklight::Component
def initialize(document)
super
@document = document
end

def render?
@document.present?
end
end
end
5 changes: 0 additions & 5 deletions app/views/catalog/_show_main_content.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,3 @@

</div>
</div>

<% if @document.respond_to?(:export_as_openurl_ctx_kev) %>
<!-- COinS, for Zotero among others -->
<span class="Z3988" title="<%= @document.export_as_openurl_ctx_kev %>"></span>
<% end %>
1 change: 1 addition & 0 deletions app/views/layouts/blacklight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<!-- Internet Explorer use the highest version available -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<%= render TrlnArgon::HighwireMetadataComponent.new(@document) %>
<!-- data used by various JS routines -->
<meta name="shared-application-data"
id="shared-application-data"
Expand Down
4 changes: 3 additions & 1 deletion lib/trln_argon/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'trln_argon/solr_document/syndetics_data'
require 'trln_argon/solr_document/urls'
require 'trln_argon/solr_document/work_entry'
require 'trln_argon/solr_document/highwire_field_mapping'

module TrlnArgon
# Mixin for SolrDocument with TRLN Argon Specific Behavior
Expand All @@ -25,6 +26,7 @@ module SolrDocument
include SyndeticsData
include Urls
include WorkEntry
include HighwireFieldMapping

def availability
if self[TrlnArgon::Fields::AVAILABLE].present?
Expand Down Expand Up @@ -90,7 +92,7 @@ def names_to_text
end

def creators_to_text
names.select { |n| n[:type] == 'creator' || n[:type] == 'no_rel' || n[:type] == '' }
names.select { |n| n[:type] == 'creator' || n[:type] == 'director' || n[:type] == 'no_rel' || n[:type] == '' }
.map { |n| n[:name] }.reject(&:empty?)
end

Expand Down
63 changes: 63 additions & 0 deletions lib/trln_argon/solr_document/highwire_field_mapping.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module TrlnArgon
module SolrDocument
module HighwireFieldMapping
# https://raw.githubusercontent.com/zotero/translators/db2771d52d89d1480ff98efbd6968565893f2184/Embedded%20Metadata.js
MAPPING = {
'title_main' => 'citation_title',
'publication_year_sort' => 'citation_publication_date',
'publisher_a' => 'citation_publisher',
'publisher_location_a' => 'citation_place',
'isbn_number_a' => 'citation_isbn',
'statement_of_responsibility_a' => 'citation_author',
'issn_primary_a' => 'citation_issn',
'language_a' => 'citation_language'
}.freeze

def highwire_metadata_tags
result = MAPPING.each_with_object([]) do |(k, v), o|
docvalue = fetch(k, [])
process_docvalue(o, v, docvalue) unless docvalue.empty?
end

auths = highwire_authors
editors = highwire_editors
process_authors(result, auths) if auths
process_editors(result, editors) if editors

result
end

private

def process_docvalue(result, key, docvalue)
if docvalue.is_a?(Array)
docvalue.each { |dv| result << [key, dv] }
else
result << [key, docvalue]
end
end

def process_authors(result, auths)
result.reject! { |x| x[0] == 'citation_author' }
auths.each { |n| result << ['citation_authors', n] }
end

def process_editors(result, editors)
result.reject! { |x| x[0] == 'citation_editor' }
editors.each { |n| result << ['citation_editors', n] }
end

def highwire_authors
named_authors = names.select { |n| n.fetch(:rel, '') == 'author' }
named_directors = names.select { |n| n.fetch(:rel, '') == 'director' }
named_norel = names.select { |n| n.fetch(:rel, '').empty? }
[named_authors, named_directors, named_norel].flat_map { |x| x.map { |h| h[:name] } }
end

def highwire_editors
named_editors = names.select { |n| n.fetch(:rel, '') == 'editor' }
[named_editors].find { |x| !x.empty? }&.map { |x| x[:name] }
end
end
end
end
11 changes: 8 additions & 3 deletions lib/trln_argon/solr_document/ris_field_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def ris_field_mapping
# First Author
A1: proc { creators_to_text },
# Second Author
# A2: ,
# A2: proc { creators_to_text },
# Location in Archives (Inst., Lib., Call No.)
AV: proc { locations_to_text },
# Call Number
Expand All @@ -38,11 +38,12 @@ def ris_field_mapping
# Notes
N1: TrlnArgon::Fields::NOTE_GENERAL,
# Publisher (Note: Combined with Place Published in Argon imprint_main)
PB: proc { imprint_main_to_text },
PB: proc { publisher_name_text },

# Publication year (YYYY/MM/DD)
PY: TrlnArgon::Fields::PUBLICATION_YEAR,
# ISBN/ISSN
# SN: ,
SN: proc { isbn_number } || proc { issn },
# Primary Title
TI: TrlnArgon::Fields::TITLE_MAIN,
# Secondary Title (journal title, if applicable)
Expand Down Expand Up @@ -104,5 +105,9 @@ def ris_type(resource_type)
end
# rubocop:enable Metrics/MethodLength
end

def publisher_name_text
fetch('publisher_a', []).first || ''
end
end
end
5 changes: 5 additions & 0 deletions spec/fixtures/files/documents/DUKE002952265.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
- '{"type":"imprint", "label":"", "value":"Washington : Smithsonian Institution Press, 1986."}'
publisher_location_a:
- 'Washington'
publisher_a:
- ["Smithsonian Institution Press"]
misc_id_qual_a:
- ''
misc_id_type_a:
Expand Down Expand Up @@ -76,3 +78,6 @@
- Echinodermata
statement_of_responsibility_a:
- Maureen E. Downey.
isbn_number_a:
- ["0632020636", "0632019239"]

71 changes: 71 additions & 0 deletions spec/lib/trln_argon/highwire_field_mapping_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# rubocop:disable RSpec/FilePath
describe TrlnArgon::SolrDocument::HighwireFieldMapping do
include described_class
# rubocop:disable RSpec/LeakyConstantDeclaration
class SolrDocumentTestClass
include Blacklight::Solr::Document
include TrlnArgon::SolrDocument
end
# rubocop:enable RSpec/LeakyConstantDeclaration

describe '#highwire_metadata_tags' do
let(:document1) do
SolrDocumentTestClass.new(
'title_main' => 'Title',
'publisher_a' => 'Publisher',
'publication_year_sort' => '2023',
'isbn_number_a' => '12345678',
'publisher_location_a' => 'Durham',
'language_a' => 'English',
'statement_of_responsibility_a' => [
{ name: 'Author 1', rel: 'author' },
{ name: 'Author 2', rel: 'editor' }
]
)
end

let(:document2) do
SolrDocumentTestClass.new(
'title_main' => 'Title',
'publisher_a' => 'Publisher'
)
end

let(:document3) do
SolrDocumentTestClass.new(
'title_main' => 'Title',
'publisher_a' => 'Publisher',
'issn_primary_a' => '123456'
)
end

it 'generates metadata tags based on the mapping' do
result = document1.highwire_metadata_tags
expect(result).to include(
['citation_title', 'Title'],
['citation_publication_date', '2023'],
['citation_publisher', 'Publisher'],
['citation_place', 'Durham'],
['citation_isbn', '12345678'],
['citation_language', 'English'],
['citation_author', { 'name' => 'Author 1', 'rel' => 'author' }],
['citation_author', { 'name' => 'Author 2', 'rel' => 'editor' }]
)
end

it 'does not include citation_author if there are no authors' do
result = document2.highwire_metadata_tags
expect(result).not_to include(['citation_author'])
end

it 'includes issn if there is an issn' do
result = document3.highwire_metadata_tags
expect(result).to include(
['citation_title', 'Title'],
['citation_publisher', 'Publisher'],
['citation_issn', '123456']
)
end
end
end
# rubocop:enable RSpec/FilePath
3 changes: 2 additions & 1 deletion spec/lib/trln_argon/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,9 @@ class SolrDocumentTestClass
"KW - Echinodermata -- Classification\r\n"\
"KW - Echinodermata -- Atlantic Ocean -- Classification\r\n"\
"LA - English\r\n"\
"PB - Washington : Smithsonian Institution Press, 1986.\r\n"\
"PB - Smithsonian Institution Press\r\n"\
"PY - 1986\r\n"\
"SN - [\"0632020636\", \"0632019239\"]\r\n"\
'TI - Revision of the Atlantic Brisingida (Echinodermata:Asteroidea), '\
"with description of a new genus and family /\r\n"\
"UR - https://discovery.trln.org/catalog/DUKE002952265\r\n"\
Expand Down

0 comments on commit c532034

Please sign in to comment.