commonmeta-ruby 3.2.8 → 3.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/commonmeta/crossref_utils.rb +79 -81
- data/lib/commonmeta/version.rb +1 -1
- data/spec/writers/crossref_xml_writer_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e05b0fedfc5074f16bf6b04dd73150dcae6f75d3392dd3abe82bd52eafea1531
|
4
|
+
data.tar.gz: 12700c970a507ae36013334f0e942413f0092d6bf4735aa27b6709a12bc7d84e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74c86b93355c0337df66c15d519f51f5336f2f883924f1c6b2edad8b6460d509d2e3443653d8545b201004e6407afffe79a505044f8cae88bbeede9f25e16171
|
7
|
+
data.tar.gz: 903e7a8af1ec1025f8e7125ed96eea07f0994ed71f1473c5111947e5d7c8c1e42c5dcbe2b0562e261f60515c374c5f23e1d593cf448b9a87962cd4f3c831e2a3
|
data/Gemfile.lock
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
module Commonmeta
|
4
4
|
module CrossrefUtils
|
5
5
|
def write_crossref_xml
|
6
|
-
@crossref_xml ||= Nokogiri::XML::Builder.new(encoding:
|
6
|
+
@crossref_xml ||= Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
7
7
|
xml.doi_batch(crossref_root_attributes) do
|
8
8
|
xml.head do
|
9
9
|
# we use a uuid as batch_id
|
10
10
|
xml.doi_batch_id(SecureRandom.uuid)
|
11
|
-
xml.timestamp(Time.now.utc.strftime(
|
11
|
+
xml.timestamp(Time.now.utc.strftime("%Y%m%d%H%M%S"))
|
12
12
|
xml.depositor do
|
13
13
|
xml.depositor_name(depositor)
|
14
14
|
xml.email_address(email)
|
@@ -23,12 +23,12 @@ module Commonmeta
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def crossref_errors(xml: nil)
|
26
|
-
filepath = File.expand_path(
|
27
|
-
File.open(filepath,
|
26
|
+
filepath = File.expand_path("../../resources/crossref/crossref5.3.1.xsd", __dir__)
|
27
|
+
File.open(filepath, "r") do |f|
|
28
28
|
schema = Nokogiri::XML::Schema(f)
|
29
29
|
end
|
30
30
|
|
31
|
-
schema.validate(Nokogiri::XML(xml, nil,
|
31
|
+
schema.validate(Nokogiri::XML(xml, nil, "UTF-8")).map(&:to_s).unwrap
|
32
32
|
rescue Nokogiri::XML::SyntaxError => e
|
33
33
|
e.message
|
34
34
|
end
|
@@ -37,9 +37,9 @@ module Commonmeta
|
|
37
37
|
return xml if doi_from_url(id).blank?
|
38
38
|
|
39
39
|
case type
|
40
|
-
when
|
40
|
+
when "JournalArticle"
|
41
41
|
insert_journal(xml)
|
42
|
-
when
|
42
|
+
when "Article"
|
43
43
|
insert_posted_content(xml)
|
44
44
|
end
|
45
45
|
end
|
@@ -47,21 +47,21 @@ module Commonmeta
|
|
47
47
|
def insert_journal(xml)
|
48
48
|
xml.journal do
|
49
49
|
if language.present?
|
50
|
-
xml.journal_metadata(
|
51
|
-
xml.full_title(container[
|
50
|
+
xml.journal_metadata("language" => language[0..1]) do
|
51
|
+
xml.full_title(container["title"])
|
52
52
|
end
|
53
53
|
else
|
54
54
|
xml.journal_metadata do
|
55
|
-
xml.full_title(container[
|
55
|
+
xml.full_title(container["title"])
|
56
56
|
end
|
57
57
|
end
|
58
|
-
xml.journal_article(
|
58
|
+
xml.journal_article("publication_type" => "full_text") do
|
59
59
|
insert_crossref_titles(xml)
|
60
60
|
insert_crossref_creators(xml)
|
61
61
|
insert_crossref_publication_date(xml)
|
62
62
|
insert_crossref_abstract(xml)
|
63
63
|
insert_crossref_issn(xml)
|
64
|
-
|
64
|
+
insert_item_number(xml)
|
65
65
|
insert_crossref_access_indicators(xml)
|
66
66
|
insert_doi_data(xml)
|
67
67
|
insert_citation_list(xml)
|
@@ -70,7 +70,7 @@ module Commonmeta
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def insert_posted_content(xml)
|
73
|
-
posted_content = {
|
73
|
+
posted_content = { "type" => "other", "language" => language ? language[0..1] : nil }.compact
|
74
74
|
|
75
75
|
xml.posted_content(posted_content) do
|
76
76
|
insert_group_title(xml)
|
@@ -78,7 +78,7 @@ module Commonmeta
|
|
78
78
|
insert_crossref_titles(xml)
|
79
79
|
insert_posted_date(xml)
|
80
80
|
insert_institution(xml)
|
81
|
-
|
81
|
+
insert_item_number(xml)
|
82
82
|
insert_crossref_abstract(xml)
|
83
83
|
insert_crossref_access_indicators(xml)
|
84
84
|
insert_doi_data(xml)
|
@@ -89,14 +89,14 @@ module Commonmeta
|
|
89
89
|
def insert_group_title(xml)
|
90
90
|
return xml if subjects.blank?
|
91
91
|
|
92
|
-
xml.group_title(subjects.first[
|
92
|
+
xml.group_title(subjects.first["subject"].titleize)
|
93
93
|
end
|
94
94
|
|
95
95
|
def insert_crossref_creators(xml)
|
96
96
|
xml.contributors do
|
97
97
|
Array.wrap(creators).each_with_index do |person, index|
|
98
|
-
xml.person_name(
|
99
|
-
|
98
|
+
xml.person_name("contributor_role" => "author",
|
99
|
+
"sequence" => index.zero? ? "first" : "additional") do
|
100
100
|
insert_crossref_person(xml, person)
|
101
101
|
end
|
102
102
|
end
|
@@ -104,15 +104,15 @@ module Commonmeta
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def insert_crossref_person(xml, person)
|
107
|
-
xml.given_name(person[
|
108
|
-
xml.surname(person[
|
109
|
-
if person.dig(
|
110
|
-
xml.ORCID(person.dig(
|
107
|
+
xml.given_name(person["givenName"]) if person["givenName"].present?
|
108
|
+
xml.surname(person["familyName"]) if person["familyName"].present?
|
109
|
+
if person.dig("id") && URI.parse(person.dig("id")).host == "orcid.org"
|
110
|
+
xml.ORCID(person.dig("id"))
|
111
111
|
end
|
112
|
-
Array.wrap(person[
|
113
|
-
attributes = {
|
114
|
-
|
115
|
-
xml.affiliation(affiliation[
|
112
|
+
Array.wrap(person["affiliation"]).each do |affiliation|
|
113
|
+
attributes = { "affiliationIdentifier" => affiliation["affiliationIdentifier"],
|
114
|
+
"affiliationIdentifierScheme" => affiliation["affiliationIdentifierScheme"], "schemeURI" => affiliation["schemeUri"] }.compact
|
115
|
+
xml.affiliation(affiliation["name"], attributes)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -120,7 +120,7 @@ module Commonmeta
|
|
120
120
|
xml.titles do
|
121
121
|
Array.wrap(titles).each do |title|
|
122
122
|
if title.is_a?(Hash)
|
123
|
-
xml.title(title[
|
123
|
+
xml.title(title["title"])
|
124
124
|
else
|
125
125
|
xml.title(title)
|
126
126
|
end
|
@@ -131,15 +131,15 @@ module Commonmeta
|
|
131
131
|
def insert_citation_list(xml)
|
132
132
|
xml.citation_list do
|
133
133
|
Array.wrap(references).each do |ref|
|
134
|
-
xml.citation(
|
135
|
-
xml.journal_article(ref[
|
136
|
-
xml.author(ref[
|
137
|
-
xml.volume(ref[
|
138
|
-
xml.first_page(ref[
|
139
|
-
xml.cYear(ref[
|
140
|
-
xml.article_title(ref[
|
141
|
-
xml.doi(doi_from_url(ref[
|
142
|
-
xml.unstructured_citation(ref[
|
134
|
+
xml.citation("key" => ref["key"]) do
|
135
|
+
xml.journal_article(ref["journal_title"]) if ref["journal_title"].present?
|
136
|
+
xml.author(ref["author"]) if ref["author"].present?
|
137
|
+
xml.volume(ref["volume"]) if ref["volume"].present?
|
138
|
+
xml.first_page(ref["first_page"]) if ref["first_page"].present?
|
139
|
+
xml.cYear(ref["cYear"]) if ref["cYear"].present?
|
140
|
+
xml.article_title(ref["article_title"]) if ref["article_title"].present?
|
141
|
+
xml.doi(doi_from_url(ref["doi"])) if ref["doi"].present?
|
142
|
+
xml.unstructured_citation(ref["url"]) if ref["url"].present?
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
@@ -163,12 +163,12 @@ module Commonmeta
|
|
163
163
|
def insert_crossref_access_indicators(xml)
|
164
164
|
return xml if license.blank?
|
165
165
|
|
166
|
-
rights_uri = license[
|
166
|
+
rights_uri = license["url"]
|
167
167
|
|
168
|
-
xml.program(
|
169
|
-
|
170
|
-
xml.license_ref(rights_uri,
|
171
|
-
xml.license_ref(rights_uri,
|
168
|
+
xml.program("xmlns" => "http://www.crossref.org/AccessIndicators.xsd",
|
169
|
+
"name" => "AccessIndicators") do
|
170
|
+
xml.license_ref(rights_uri, "applies_to" => "vor")
|
171
|
+
xml.license_ref(rights_uri, "applies_to" => "tdm")
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -204,7 +204,7 @@ module Commonmeta
|
|
204
204
|
xml.subjects do
|
205
205
|
subjects.each do |subject|
|
206
206
|
if subject.is_a?(Hash)
|
207
|
-
xml.subject(subject[
|
207
|
+
xml.subject(subject["subject"])
|
208
208
|
else
|
209
209
|
xml.subject(subject)
|
210
210
|
end
|
@@ -225,11 +225,11 @@ module Commonmeta
|
|
225
225
|
end
|
226
226
|
|
227
227
|
def insert_crossref_publication_date(xml)
|
228
|
-
return xml if date[
|
228
|
+
return xml if date["registered"].blank?
|
229
229
|
|
230
|
-
date_ = get_datetime_from_iso8601(date[
|
230
|
+
date_ = get_datetime_from_iso8601(date["registered"])
|
231
231
|
|
232
|
-
xml.publication_date(
|
232
|
+
xml.publication_date("media_type" => "online") do
|
233
233
|
xml.month(date_.month) if date_.month.present?
|
234
234
|
xml.day(date_.day) if date_.day.present?
|
235
235
|
xml.year(date_.year) if date_.year.present?
|
@@ -237,9 +237,9 @@ module Commonmeta
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def insert_posted_date(xml)
|
240
|
-
return xml if date[
|
240
|
+
return xml if date["published"].blank?
|
241
241
|
|
242
|
-
date_ = get_datetime_from_iso8601(date[
|
242
|
+
date_ = get_datetime_from_iso8601(date["published"])
|
243
243
|
|
244
244
|
xml.posted_date do
|
245
245
|
xml.month(date_.month) if date_.month.present?
|
@@ -252,24 +252,22 @@ module Commonmeta
|
|
252
252
|
return xml if publisher.blank?
|
253
253
|
|
254
254
|
xml.institution do
|
255
|
-
xml.institution_name(publisher[
|
255
|
+
xml.institution_name(publisher["name"])
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
-
def
|
259
|
+
def insert_item_number(xml)
|
260
260
|
return xml if alternate_identifiers.blank?
|
261
261
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
}.compact
|
267
|
-
|
268
|
-
# remove dashes from UUIDs, as item_number can only be 32 characters long
|
269
|
-
alternate_identifier['alternateIdentifier'].gsub!('-', '') if alternate_identifier['alternateIdentifierType'] == 'UUID'
|
262
|
+
alternate_identifiers.each do |alternate_identifier|
|
263
|
+
attributes = {
|
264
|
+
"item_number_type" => alternate_identifier["alternateIdentifierType"] ? alternate_identifier["alternateIdentifierType"].downcase : nil,
|
265
|
+
}.compact
|
270
266
|
|
271
|
-
|
272
|
-
|
267
|
+
# remove dashes from UUIDs, as item_number can only be 32 characters long
|
268
|
+
alternate_identifier["alternateIdentifier"].gsub!("-", "") if alternate_identifier["alternateIdentifierType"] == "UUID"
|
269
|
+
|
270
|
+
xml.item_number(alternate_identifier["alternateIdentifier"], attributes)
|
273
271
|
end
|
274
272
|
end
|
275
273
|
|
@@ -279,9 +277,9 @@ module Commonmeta
|
|
279
277
|
xml.doi_data do
|
280
278
|
xml.doi(doi_from_url(id).downcase)
|
281
279
|
xml.resource(url)
|
282
|
-
xml.collection(
|
280
|
+
xml.collection("property" => "text-mining") do
|
283
281
|
xml.item do
|
284
|
-
xml.resource(url,
|
282
|
+
xml.resource(url, "mime_type" => "text/html")
|
285
283
|
end
|
286
284
|
end
|
287
285
|
end
|
@@ -296,26 +294,26 @@ module Commonmeta
|
|
296
294
|
r = rights
|
297
295
|
else
|
298
296
|
r = {}
|
299
|
-
r[
|
300
|
-
r[
|
297
|
+
r["rights"] = rights
|
298
|
+
r["rightsUri"] = normalize_id(rights)
|
301
299
|
end
|
302
300
|
|
303
301
|
attributes = {
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
302
|
+
"rightsURI" => r["rightsUri"],
|
303
|
+
"rightsIdentifier" => r["rightsIdentifier"],
|
304
|
+
"rightsIdentifierScheme" => r["rightsIdentifierScheme"],
|
305
|
+
"schemeURI" => r["schemeUri"],
|
306
|
+
"xml:lang" => r["lang"],
|
309
307
|
}.compact
|
310
308
|
|
311
|
-
xml.rights(r[
|
309
|
+
xml.rights(r["rights"], attributes)
|
312
310
|
end
|
313
311
|
end
|
314
312
|
|
315
313
|
def insert_crossref_issn(xml)
|
316
|
-
issn = if container.to_h.fetch(
|
317
|
-
|
318
|
-
|
314
|
+
issn = if container.to_h.fetch("identifierType", nil) == "ISSN"
|
315
|
+
container.to_h.fetch("identifier", nil)
|
316
|
+
end
|
319
317
|
|
320
318
|
return xml if issn.blank?
|
321
319
|
|
@@ -329,22 +327,22 @@ module Commonmeta
|
|
329
327
|
d = descriptions.first
|
330
328
|
else
|
331
329
|
d = {}
|
332
|
-
d[
|
330
|
+
d["description"] = descriptions.first
|
333
331
|
end
|
334
332
|
|
335
|
-
xml.abstract(
|
336
|
-
xml.p(d[
|
333
|
+
xml.abstract("xmlns" => "http://www.ncbi.nlm.nih.gov/JATS1") do
|
334
|
+
xml.p(d["description"])
|
337
335
|
end
|
338
336
|
end
|
339
337
|
|
340
338
|
def crossref_root_attributes
|
341
|
-
{ 'xmlns:xsi':
|
342
|
-
'xsi:schemaLocation':
|
343
|
-
xmlns:
|
344
|
-
'xmlns:jats':
|
345
|
-
'xmlns:fr':
|
346
|
-
'xmlns:mml':
|
347
|
-
version:
|
339
|
+
{ 'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance",
|
340
|
+
'xsi:schemaLocation': "http://www.crossref.org/schema/5.3.1 https://www.crossref.org/schemas/crossref5.3.1.xsd",
|
341
|
+
xmlns: "http://www.crossref.org/schema/5.3.1",
|
342
|
+
'xmlns:jats': "http://www.ncbi.nlm.nih.gov/JATS1",
|
343
|
+
'xmlns:fr': "http://www.crossref.org/fundref.xsd",
|
344
|
+
'xmlns:mml': "http://www.w3.org/1998/Math/MathML",
|
345
|
+
version: "5.3.1" }
|
348
346
|
end
|
349
347
|
end
|
350
348
|
end
|
data/lib/commonmeta/version.rb
CHANGED
@@ -218,7 +218,7 @@ describe Commonmeta::Metadata, vcr: true do
|
|
218
218
|
"title")).to eq("The Research Software Alliance (ReSA)")
|
219
219
|
expect(crossref_xml.dig("citation_list", "citation").length).to eq(11)
|
220
220
|
expect(crossref_xml.dig("citation_list", "citation").last).to eq("doi"=>"10.5281/zenodo.3699950", "key"=>"ref11")
|
221
|
-
expect(crossref_xml.dig('
|
221
|
+
expect(crossref_xml.dig('item_number')).to eq("__content__"=>"954f81380ecd409087c5cef1297f1470", "item_number_type"=>"uuid")
|
222
222
|
end
|
223
223
|
|
224
224
|
it "json_feed_item from rogue scholar with doi" do
|