19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/bolognese/readers/crossref_reader.rb', line 19
def read_crossref(string: nil, **options)
read_options = ActiveSupport::HashWithIndifferentAccess.new(options.except(:doi, :id, :url, :sandbox, :validate, :ra))
if string.present?
m = Maremma.from_xml(string).dig("crossref_result", "query_result", "body", "query", "doi_record") || {}
meta = m.dig("doi_record", "crossref", "error").nil? ? m : {}
query = Maremma.from_xml(string).dig("crossref_result", "query_result", "body", "query") || {}
else
meta = {}
query = {}
end
model = meta.dig("crossref").to_h.keys.last
resource_type = nil
bibliographic_metadata = {}
program_metadata = {}
journal_metadata = nil
journal_issue = {}
journal_metadata = nil
publisher = query.dig("crm_item", 0)
case model
when "book"
book_metadata = meta.dig("crossref", "book", "book_metadata")
book_series_metadata = meta.dig("crossref", "book", "book_series_metadata")
book_set_metadata = meta.dig("crossref", "book", "book_set_metadata")
bibliographic_metadata = meta.dig("crossref", "book", "content_item") || book_metadata || book_series_metadata
resource_type = bibliographic_metadata.fetch("component_type", nil) ? "book-" + bibliographic_metadata.fetch("component_type") : "book"
publisher = book_metadata.present? ? book_metadata.dig("publisher", "publisher_name") : book_series_metadata.dig("publisher", "publisher_name")
when "conference"
event_metadata = meta.dig("crossref", "conference", "event_metadata") ||Â {}
bibliographic_metadata = meta.dig("crossref", "conference", "conference_paper").to_h
when "journal"
journal_metadata = meta.dig("crossref", "journal", "journal_metadata") ||Â {}
journal_issue = meta.dig("crossref", "journal", "journal_issue") || {}
journal_article = meta.dig("crossref", "journal", "journal_article") || {}
bibliographic_metadata = journal_article.presence || journal_issue.presence || journal_metadata
program_metadata = bibliographic_metadata.dig("crossmark", "custom_metadata", "program") || bibliographic_metadata.dig("program")
resource_type = if journal_article.present?
"journal_article"
elsif journal_issue.present?
"journal_issue"
else
"journal"
end
when "posted_content"
bibliographic_metadata = meta.dig("crossref", "posted_content").to_h
publisher = bibliographic_metadata.dig("institution", "institution_name")
when "sa_component"
bibliographic_metadata = meta.dig("crossref", "sa_component", "component_list", "component").to_h
related_identifier = Array.wrap(query.to_h["crm_item"]).find { |cr| cr["name"] == "relation" }
journal_metadata = { "relatedIdentifier" => related_identifier.to_h.fetch("__content", nil) }
when "database"
bibliographic_metadata = meta.dig("crossref", "database", "dataset").to_h
resource_type = "dataset"
end
resource_type = (resource_type || model).to_s.underscore.camelcase.presence
schema_org = Bolognese::Utils::CR_TO_SO_TRANSLATIONS[resource_type] || "ScholarlyArticle"
types = {
"resourceTypeGeneral" => Bolognese::Utils::SO_TO_DC_TRANSLATIONS[schema_org],
"resourceType" => resource_type,
"schemaOrg" => schema_org,
"citeproc" => Bolognese::Utils::CR_TO_CP_TRANSLATIONS[resource_type] || "article-journal",
"bibtex" => Bolognese::Utils::CR_TO_BIB_TRANSLATIONS[resource_type] || "misc",
"ris" => Bolognese::Utils::CR_TO_RIS_TRANSLATIONS[resource_type] || "JOUR"
}.compact
titles = if bibliographic_metadata.dig("titles").present?
Array.wrap(bibliographic_metadata.dig("titles")).map do |r|
if r.blank? || (r["title"].blank? && r["original_language_title"].blank?)
nil
elsif r["title"].is_a?(String)
{ "title" => sanitize(r["title"]) }
elsif r["original_language_title"].present?
{ "title" => sanitize(r.dig("original_language_title", "__content__")), "lang" => r.dig("original_language_title", "language") }
else
{ "title" => sanitize(r.dig("title", "__content__")) }.compact
end
end.compact
else
[{ "title" => ":{unav)" }]
end
date_published = crossref_date_published(bibliographic_metadata)
if date_published.present?
date_published = { "date" => date_published, "dateType" => "Issued" }
else
date_published = Array.wrap(query.to_h["crm_item"]).find { |cr| cr["name"] == "created" }
date_published = { "date" => date_published.fetch("__content__", "")[0..9], "dateType" => "Issued" } if date_published.present?
end
date_updated = Array.wrap(query.to_h["crm_item"]).find { |cr| cr["name"] == "last-update" }
date_updated = { "date" => date_updated.fetch("__content__", nil), "dateType" => "Updated" } if date_updated.present?
date_registered = Array.wrap(query.to_h["crm_item"]).find { |cr| cr["name"] == "deposit-timestamp" }
if date_registered && date_registered.fetch("__content__", nil).to_i > 15000000000000 date_registered = DateTime.strptime(date_registered.fetch("__content__", ""), "%Y%m%d%H%M%S").strftime('%Y-%m-%dT%H:%M:%SZ')
else
date_registered = nil
end
date_published = nil unless Date.edtf(date_published.to_h["date"]).present?
date_updated = nil unless Date.edtf(date_updated.to_h["date"]).present?
dates = [date_published, date_updated].compact
publication_year = date_published.to_h.fetch("date", "")[0..3].presence
state = meta.present? || read_options.present? ? "findable" : "not_found"
related_identifiers = Array.wrap(crossref_is_part_of(journal_metadata)) + Array.wrap(crossref_references(bibliographic_metadata))
container = if journal_metadata.present? || book_metadata.present?
issn = normalize_issn(journal_metadata.to_h.fetch("issn", nil))
{ "type" => "Journal",
"identifier" => issn,
"identifierType" => issn.present? ? "ISSN" : nil,
"title" => parse_attributes(journal_metadata.to_h["full_title"]),
"volume" => parse_attributes(journal_issue.dig("journal_volume", "volume")),
"issue" => parse_attributes(journal_issue.dig("issue")),
"firstPage" => bibliographic_metadata.dig("pages", "first_page"),
"lastPage" => bibliographic_metadata.dig("pages", "last_page") }.compact
elsif book_series_metadata.to_h.fetch("series_metadata", nil).present?
issn = normalize_issn(book_series_metadata.dig("series_metadata", "issn"))
{ "type" => "Book Series",
"identifier" => issn,
"identifierType" => issn.present? ? "ISSN" : nil,
"title" => book_series_metadata.dig("series_metadata", "titles", "title"),
"volume" => bibliographic_metadata.fetch("volume", nil) }.compact
end
identifiers = [{ "identifierType" => "DOI", "identifier" => normalize_doi(options[:doi] || options[:id] || bibliographic_metadata.dig("doi_data", "doi")) }, crossref_alternate_identifiers(bibliographic_metadata)].compact
id = Array.wrap(identifiers).first.to_h.fetch("identifier", nil)
doi = Array.wrap(identifiers).find { |r| r["identifierType"] == "DOI" }.to_h.fetch("identifier", nil)
{ "id" => id,
"types" => types,
"doi" => doi_from_url(doi),
"url" => parse_attributes(bibliographic_metadata.dig("doi_data", "resource"), first: true),
"titles" => titles,
"identifiers" => identifiers,
"creators" => crossref_people(bibliographic_metadata, "author"),
"contributors" => crossref_people(bibliographic_metadata, "editor"),
"funding_references" => crossref_funding_reference(program_metadata),
"publisher" => publisher,
"container" => container,
"agency" => agency = options[:ra] || "Crossref",
"related_identifiers" => related_identifiers,
"dates" => dates,
"publication_year" => publication_year,
"descriptions" => crossref_description(bibliographic_metadata),
"rights_list" => crossref_license(program_metadata),
"version_info" => nil,
"subjects" => nil,
"language" => nil,
"sizes" => nil,
"schema_version" => nil,
"state" => state,
"date_registered" => date_registered
}.merge(read_options)
end
|