Skip to content

Commit

Permalink
Merge pull request #190 from mlibrary/LIBSEARCH-1016
Browse files Browse the repository at this point in the history
Libsearch-1016
  • Loading branch information
bertrama authored Oct 14, 2024
2 parents e804edc + 61baf2a commit 416ec3f
Showing 1 changed file with 122 additions and 108 deletions.
230 changes: 122 additions & 108 deletions local-gems/spectrum-json/lib/spectrum/json/ris.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,85 @@
module Spectrum
module Json
class Ris
TYPES = Hash.new('GEN').merge(
'book' => 'BOOK',
'book / ebook' => 'BOOK',
'journal article' => 'JOUR',
'publication article' => 'JOUR',
'trade publication article' => 'JOUR',
'journal / ejournal' => 'JFULL',
'journal' => 'JFULL',
'serial' => 'SER',
'map' => 'MAP',
'maps-atlas' => 'MAP',
'atlas' => 'MAP',
'ebook' => 'EBOOK',
'motion picture' => 'VIDEO',
'video recording' => 'VIDEO',
'video (blu-ray)' => 'VIDEO',
'video (dvd)' => 'VIDEO',
'video (vhs)' => 'VIDEO',
'video games' => 'VIDEO',
'streaming video' => 'VIDEO',
'audio' => 'SOUND',
'audio recording' => 'SOUND',
'audio (spoken word)' => 'SOUND',
'audio cd' => 'SOUND',
'audio lp' => 'SOUND',
'streaming audio' => 'SOUND',
'spoken word recording' => 'SOUND',
'audio (music)' => 'MUSIC',
'music' => 'MUSIC',
'music recording' => 'MUSIC',
'musical score' => 'MUSIC',
'music score' => 'MUSIC',
'sheet music' => 'MUSIC',
'thesis' => 'THES',
'student thesis' => 'THES',
'dissertation' => 'THES',
'dictionaries' => 'DICT',
'data file' => 'DBASE',
'data set' => 'DBASE',
'computer file' => 'DBASE',
'cdrom' => 'DBASE',
'software' => 'DBASE',
'magazine' => 'MGZN',
'magazine article' => 'MGZN',
'newspaper' => 'NEWS',
'newspaper article' => 'NEWS',
'encyclopedias' => 'ENCYC',
'conference' => 'CONF',
'conference proceeding' => 'CONF',
'paper' => 'CPAPER',
'book chapter' => 'CHAP',
'internet communication' => 'ICOMM',
'electronic resource' => 'ICOMM',
'web resource' => 'ICOMM',
'gen' => 'GEN',
'*' => 'GEN'
TYPES = Hash.new("JOUR").merge(
"archival material manuscript" => "MANSCPT",
"article" => "JOUR",
"atlas" => "MAP",
"audio" => "SOUND",
"audio (music)" => "MUSIC",
"audio (spoken word)" => "SOUND",
"audio cd" => "SOUND",
"audio lp" => "SOUND",
"audio recording" => "SOUND",
"book" => "BOOK",
"book / ebook" => "BOOK",
"book chapter" => "CHAP",
"cdrom" => "DBASE",
"computer file" => "DBASE",
"conference" => "CONF",
"conference proceeding" => "CONF",
"data file" => "DBASE",
"data set" => "DBASE",
"dictionaries" => "DICT",
"dissertation" => "THES",
"ebook" => "EBOOK",
"electronic resource" => "WEB",
"encyclopedias" => "ENCYC",
"gen" => "GEN",
"government document" => "GOVDOC",
"image" => "ADVS",
"internet communication" => "ICOMM",
"journal" => "JFULL",
"journal / ejournal" => "JFULL",
"journal article" => "JOUR",
"magazine" => "MGZN",
"magazine article" => "MGZN",
"map" => "MAP",
"maps-atlas" => "MAP",
"motion picture" => "VIDEO",
"music" => "MUSIC",
"music recording" => "MUSIC",
"musical score" => "MUSIC",
"music score" => "MUSIC",
"newsletter" => "NEWS",
"newsletter article" => "NEWS",
"newsletter articles" => "NEWS",
"newspaper" => "NEWS",
"newspaper article" => "NEWS",
"newspaper articles" => "NEWS",
"paper" => "CPAPER",
"patent" => "PAT",
"publication article" => "JOUR",
"reference entry" => "JOUR",
"report" => "RPRT",
"review" => "JOUR",
"serial" => "SER",
"sheet music" => "MUSIC",
"software" => "DBASE",
"spoken word recording" => "SOUND",
"streaming audio" => "SOUND",
"streaming video" => "VIDEO",
"student thesis" => "THES",
"text resource" => "JOUR",
"thesis" => "THES",
"trade publication article" => "JOUR",
"video" => "VIDEO",
"video recording" => "VIDEO",
"video (blu-ray)" => "VIDEO",
"video (dvd)" => "VIDEO",
"video (vhs)" => "VIDEO",
"video games" => "VIDEO",
"web resource" => "WEB",
"*" => "GEN"
)

TAG_ARITY = Hash.new(:single_valued_tag).merge(
'AU' => :multi_valued_tag,
'KW' => :multi_valued_tag,
'M1' => :multi_valued_tag,
'N1' => :multi_valued_tag,
'PB' => :multi_valued_tag,
'UR' => :multi_valued_tag,
"AU" => :multi_valued_tag,
"KW" => :multi_valued_tag,
"M1" => :multi_valued_tag,
"N1" => :multi_valued_tag,
"PB" => :multi_valued_tag,
"UR" => :multi_valued_tag
)

class << self
Expand All @@ -94,85 +108,85 @@ def configure!(_config)
end

def publication(item)
single_valued(item, 'T2', 'publication_title')
single_valued(item, "T2", "publication_title")
end

def issue(item)
single_valued(item, 'IS', 'issue')
single_valued(item, "IS", "issue")
end

def volume(item)
single_valued(item, 'VL', 'volume')
single_valued(item, "VL", "volume")
end

def doi(item)
single_valued(item, 'DO', 'doi')
single_valued(item, "DO", "doi")
end

def url(item)
field(item, 'links').map do |link|
link.find { |attr| attr['uid'] == 'href' }
field(item, "links").map do |link|
link.find { |attr| attr["uid"] == "href" }
end.compact.map do |item|
"L2 - #{item['value']}"
"L2 - #{item["value"]}"
end.join("\n")
end

def id(item)
single_valued(item, 'ID', 'id')
single_valued(item, "ID", "id")
end

def sn(item)
%w[issn isbn eisbn eissn].each_with_object([]) do |uid, acc|
acc << multi_valued(item, 'SN', uid)
acc << multi_valued(item, "SN", uid)
end.compact.reject(&:empty?).join("\n")
end

def cn(item)
multi_valued(item, 'CN', 'callnumber')
multi_valued(item, "CN", "callnumber")
end

def sp(item)
single_valued(item, 'SP', 'start_page')
single_valued(item, "SP", "start_page")
end

def ep(item)
single_valued(item, 'EP', 'end_page')
single_valued(item, "EP", "end_page")
end

def message(items)
items.map { |item| ris(item) }.join("\n\n\n")
end

def title(item)
multi_valued(item, 'TI', 'title')
multi_valued(item, "TI", "title")
end

def author(item)
multi_valued(item, 'AU', 'author')
multi_valued(item, "AU", "author")
end

def publisher(item)
multi_valued(item, 'PB', 'publisher')
multi_valued(item, "PB", "publisher")
end

def publication_year(item)
multi_valued(item, 'PY', 'published_year')
multi_valued(item, "PY", "published_year")
end

def publication_place(item)
multi_valued(item, 'PP', 'place_of_publication')
multi_valued(item, "PP", "place_of_publication")
end

def ris(item)
ret = []
ret << type(item)
ret << db(item)
ret << 'DP - University of Michigan Library'
ret << "Y2 - #{DateTime.now.strftime('%Y-%m-%d')}"
datastore = item.find {|el| el[:uid] == 'datastore'}[:value]
ret << "DP - University of Michigan Library"
ret << "Y2 - #{DateTime.now.strftime("%Y-%m-%d")}"
datastore = item.find { |el| el[:uid] == "datastore" }[:value]
fields = ::Spectrum::Json.foci[datastore].fields
item.each do |field|
next unless field_def = fields.by_uid(field[:uid])
next unless (field_def = fields.by_uid(field[:uid]))
next unless field_def.ris
field_def.ris.each do |tag|
ret += ris_line(tag, field[:value])
Expand All @@ -198,60 +212,60 @@ def single_valued_tag(tag, value)
return []
end
end
["#{tag} - #{value.to_s.gsub(/[\r\n]/, ' ')}"]
["#{tag} - #{value.to_s.gsub(/[\r\n]/, " ")}"]
end

def multi_valued_tag(tag, values)
return [] unless tag && values
return [] if tag.empty? || values.empty?
[values].flatten.map do |value|
if Hash === value
if value.has_key?(:value)
value = value[:value]
value = if value.has_key?(:value)
value[:value]
else
value = []
[]
end
end
[value].flatten.map do |val|
if val.nil? || val.empty?
nil
else
"#{tag} - #{val.to_s.gsub(/[\r\n]/, ' ')}"
"#{tag} - #{val.to_s.gsub(/[\r\n]/, " ")}"
end
end.compact
end.flatten.compact
end

def db(item)
case field(item, 'datastore').first
when 'mirlyn'
'DB - U-M Catalog Search'
when 'primo', 'articles', 'articlesplus'
'DB - U-M Articles Search'
when 'databases'
'DB - U-M Database Search'
when 'journals', 'onlinejournals'
'DB - U-M Online Journals Search'
when 'website'
'DB - U-M Library Website Search'
case field(item, "datastore").first
when "mirlyn"
"DB - U-M Catalog Search"
when "primo", "articles", "articlesplus"
"DB - U-M Articles Search"
when "databases"
"DB - U-M Database Search"
when "journals", "onlinejournals"
"DB - U-M Online Journals Search"
when "website"
"DB - U-M Library Website Search"
end
end

def type(item)
case field(item, 'datastore').first
when 'databases'
'TY - DBASE'
when 'journals', 'onlinejournals'
'TY - JFULL'
when 'website'
'TY - ICOMM'
case field(item, "datastore").first
when "databases"
"TY - DBASE"
when "journals", "onlinejournals"
"TY - JFULL"
when "website"
"TY - WEB"
else
single_valued(item, 'TY', 'format', 'gen', TYPES)
single_valued(item, "TY", "format", "article", TYPES)
end
end

def er(_item)
'ER -'
"ER -"
end

def single_valued(item, tag, uid, default = nil, map = nil)
Expand Down

0 comments on commit 416ec3f

Please sign in to comment.