bolognese 1.6.2 → 1.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +18 -13
  3. data/bolognese.gemspec +4 -4
  4. data/lib/bolognese/datacite_utils.rb +9 -3
  5. data/lib/bolognese/metadata.rb +6 -8
  6. data/lib/bolognese/metadata_utils.rb +10 -3
  7. data/lib/bolognese/readers/bibtex_reader.rb +2 -1
  8. data/lib/bolognese/readers/citeproc_reader.rb +2 -2
  9. data/lib/bolognese/readers/codemeta_reader.rb +3 -3
  10. data/lib/bolognese/readers/crossref_reader.rb +2 -2
  11. data/lib/bolognese/readers/datacite_reader.rb +3 -3
  12. data/lib/bolognese/readers/npm_reader.rb +1 -1
  13. data/lib/bolognese/readers/schema_org_reader.rb +4 -5
  14. data/lib/bolognese/utils.rb +89 -9
  15. data/lib/bolognese/version.rb +1 -1
  16. data/lib/bolognese/writers/bibtex_writer.rb +2 -1
  17. data/lib/bolognese/writers/codemeta_writer.rb +3 -2
  18. data/lib/bolognese/writers/jats_writer.rb +2 -2
  19. data/lib/bolognese/writers/schema_org_writer.rb +1 -1
  20. data/resources/spdx/licenses.json +5297 -0
  21. data/spec/datacite_utils_spec.rb +5 -1
  22. data/spec/fixtures/datacite-example-affiliation.xml +1 -1
  23. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/normalize_cc_url/not_found.yml +44 -0
  24. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/normalize_cc_url/with_trailing_slash.yml +44 -0
  25. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/normalize_cc_url/with_trailing_slash_and_to_https.yml +44 -0
  26. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/normalize_url/to_https.yml +44 -0
  27. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/normalize_url/with_trailing_slash_and_to_https.yml +44 -0
  28. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/spdx/hsh_to_spdx_id.yml +44 -0
  29. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/spdx/hsh_to_spdx_not_found.yml +44 -0
  30. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/spdx/hsh_to_spdx_url.yml +44 -0
  31. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/spdx/name_to_spdx_exists.yml +44 -0
  32. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/spdx/name_to_spdx_id.yml +44 -0
  33. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/spdx/name_to_spdx_not_found.yml +44 -0
  34. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/url_to_https/http.yml +44 -0
  35. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/url_to_https/uri.yml +44 -0
  36. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/url_to_https/with_trailing_slash.yml +44 -0
  37. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/write_metadata_as_citation/software_w/version.yml +52 -0
  38. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/write_metadata_as_schema_org/Funding.yml +58 -10
  39. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/write_metadata_as_schema_org/Funding_OpenAIRE.yml +65 -28
  40. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/write_metadata_as_schema_org/Schema_org_JSON_Cyark.yml +98 -0
  41. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/write_metadata_as_schema_org/Schema_org_JSON_IsSupplementTo.yml +58 -10
  42. data/spec/readers/bibtex_reader_spec.rb +5 -1
  43. data/spec/readers/codemeta_reader_spec.rb +21 -1
  44. data/spec/readers/crossref_reader_spec.rb +21 -5
  45. data/spec/readers/datacite_json_reader_spec.rb +1 -1
  46. data/spec/readers/datacite_reader_spec.rb +51 -11
  47. data/spec/readers/npm_reader_spec.rb +3 -3
  48. data/spec/readers/schema_org_reader_spec.rb +2 -2
  49. data/spec/utils_spec.rb +58 -0
  50. data/spec/writers/bibtex_writer_spec.rb +6 -0
  51. data/spec/writers/citation_writer_spec.rb +8 -0
  52. data/spec/writers/citeproc_writer_spec.rb +12 -2
  53. data/spec/writers/crosscite_writer_spec.rb +5 -1
  54. data/spec/writers/datacite_json_writer_spec.rb +5 -1
  55. data/spec/writers/datacite_writer_spec.rb +22 -7
  56. data/spec/writers/schema_org_writer_spec.rb +29 -3
  57. metadata +31 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49f153c7bf6a7dd69a2cf35844b9fe303574ebeb6f515a00581cea60955dc6d6
4
- data.tar.gz: ebc11d65b789fb08e97dafa25c2e9e0b2ddfb6085011478498f2e619ebdd605c
3
+ metadata.gz: 6d9b80d36b9f15e7887ad094ed6bd8dede0ae1bf9eec3e90c5628ed536f746e7
4
+ data.tar.gz: 4d746ae8b815cf873840cc7e1c62475038ef649977c2a07c356059672ab1f43f
5
5
  SHA512:
6
- metadata.gz: d30e6e90b55e93bf4febdef8cf5fe3aa17e1821e2ee317f521957cdee0e811f8f94ed07f929b974ea967a8e5e4b7f0c8e7c08f47bc9bee681e72702f263ac80e
7
- data.tar.gz: e30113a9e7ceddb8772a8e26310c7bc9ecdb349c93a33596c4d2ff0167c12650631e7dee7860c32a2e4dd8323453ed6acd7315c292060aef5a03954fbca61682
6
+ metadata.gz: efb671e6feb5a1f6e9f849607b686b38505cd7f814f3bce86da05dc143150e9b52838598f4736e1676ac1147c9b028ec24e2c868ec31add03dc35ac557875727
7
+ data.tar.gz: 540cbb6605586c66fe18212115b1c108961a7fc2a02f4df750e49a852bfd9ac221150eab3c805eb40109a3d70e0747c88a4406daa5aa3f87fc2431b2d87e978d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bolognese (1.6.2)
4
+ bolognese (1.6.7)
5
5
  activesupport (>= 4.2.5)
6
6
  benchmark_methods (~> 0.7)
7
7
  bibtex-ruby (>= 5.1.0)
@@ -14,7 +14,7 @@ PATH
14
14
  faraday (= 0.17.0)
15
15
  gender_detector (~> 0.1.2)
16
16
  iso8601 (~> 0.9.1)
17
- json-ld (~> 2.2, >= 2.2.1)
17
+ json-ld (~> 3.1, >= 3.1.4)
18
18
  jsonlint (~> 0.3.0)
19
19
  loofah (~> 2.0, >= 2.0.3)
20
20
  maremma (>= 4.3, < 5)
@@ -25,12 +25,12 @@ PATH
25
25
  postrank-uri (~> 1.0, >= 1.0.18)
26
26
  rdf-rdfxml (~> 3.1)
27
27
  rdf-turtle (~> 3.1)
28
- thor (~> 0.19)
28
+ thor (~> 1.0, >= 1.0.1)
29
29
 
30
30
  GEM
31
31
  remote: https://rubygems.org/
32
32
  specs:
33
- activesupport (6.0.3.1)
33
+ activesupport (6.0.3.2)
34
34
  concurrent-ruby (~> 1.0, >= 1.0.2)
35
35
  i18n (>= 0.7, < 2)
36
36
  minitest (~> 5.1)
@@ -56,7 +56,7 @@ GEM
56
56
  namae (~> 1.0)
57
57
  csl-styles (1.0.1.10)
58
58
  csl (~> 1.0)
59
- diff-lcs (1.3)
59
+ diff-lcs (1.4.2)
60
60
  docile (1.3.2)
61
61
  ebnf (1.2.0)
62
62
  rdf (~> 3.1)
@@ -79,18 +79,23 @@ GEM
79
79
  concurrent-ruby (~> 1.0)
80
80
  hashdiff (1.0.1)
81
81
  htmlentities (4.3.4)
82
- i18n (1.8.2)
82
+ i18n (1.8.3)
83
83
  concurrent-ruby (~> 1.0)
84
84
  iso8601 (0.9.1)
85
- json-ld (2.2.1)
86
- multi_json (~> 1.12)
87
- rdf (>= 2.2.8, < 4.0)
85
+ json-canonicalization (0.2.0)
86
+ json-ld (3.1.4)
87
+ htmlentities (~> 4.3)
88
+ json-canonicalization (~> 0.2)
89
+ link_header (~> 0.0, >= 0.0.8)
90
+ multi_json (~> 1.14)
91
+ rack (~> 2.0)
92
+ rdf (~> 3.1)
88
93
  jsonlint (0.3.0)
89
94
  oj (~> 3)
90
95
  optimist (~> 3)
91
96
  latex-decode (0.3.1)
92
97
  link_header (0.0.8)
93
- loofah (2.5.0)
98
+ loofah (2.6.0)
94
99
  crass (~> 1.0.2)
95
100
  nokogiri (>= 1.5.9)
96
101
  maremma (4.7)
@@ -119,11 +124,11 @@ GEM
119
124
  nokogiri (>= 1.8.0)
120
125
  public_suffix (>= 2.0.0, < 2.1)
121
126
  public_suffix (2.0.5)
122
- rack (2.2.2)
127
+ rack (2.2.3)
123
128
  rack-test (0.8.3)
124
129
  rack (>= 1.0, < 3)
125
130
  rake (12.3.3)
126
- rdf (3.1.2)
131
+ rdf (3.1.3)
127
132
  hamster (~> 3.0)
128
133
  link_header (~> 0.0, >= 0.0.8)
129
134
  rdf-aggregate-repo (3.1.0)
@@ -171,7 +176,7 @@ GEM
171
176
  sxp (1.1.0)
172
177
  rdf (~> 3.1)
173
178
  temple (0.8.2)
174
- thor (0.20.3)
179
+ thor (1.0.1)
175
180
  thread_safe (0.3.6)
176
181
  tilt (2.0.10)
177
182
  tzinfo (1.2.7)
@@ -15,15 +15,15 @@ Gem::Specification.new do |s|
15
15
  s.license = 'MIT'
16
16
  s.required_ruby_version = '~> 2.3'
17
17
 
18
- # Declary dependencies here, rather than in the Gemfile
18
+ # Declare dependencies here, rather than in the Gemfile
19
19
  s.add_dependency 'maremma', '>= 4.3', '< 5'
20
- s.add_dependency 'faraday', '0.17.0'
20
+ s.add_dependency 'faraday', "0.17.0"
21
21
  s.add_dependency 'nokogiri', '~> 1.10.4'
22
22
  s.add_dependency 'loofah', '~> 2.0', '>= 2.0.3'
23
23
  s.add_dependency 'builder', '~> 3.2', '>= 3.2.2'
24
24
  s.add_dependency 'activesupport', '>= 4.2.5'
25
25
  s.add_dependency 'bibtex-ruby', '>= 5.1.0'
26
- s.add_dependency 'thor', '~> 0.19'
26
+ s.add_dependency 'thor', '~> 1.0', '>= 1.0.1'
27
27
  s.add_dependency 'colorize', '~> 0.8.1'
28
28
  s.add_dependency 'namae', '~> 1.0'
29
29
  s.add_dependency 'edtf', '~> 3.0', '>= 3.0.4'
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.add_dependency 'csl-styles', '~> 1.0', '>= 1.0.1.8'
32
32
  s.add_dependency 'iso8601', '~> 0.9.1'
33
33
  s.add_dependency 'postrank-uri', '~> 1.0', '>= 1.0.18'
34
- s.add_dependency 'json-ld', '~> 2.2', '>= 2.2.1'
34
+ s.add_dependency 'json-ld', '~> 3.1', '>= 3.1.4'
35
35
  s.add_dependency 'jsonlint', '~> 0.3.0'
36
36
  s.add_dependency 'oj', '~> 3.10'
37
37
  s.add_dependency "oj_mimic_json", "~> 1.0", ">= 1.0.1"
@@ -172,9 +172,9 @@ module Bolognese
172
172
  end
173
173
 
174
174
  def insert_version(xml)
175
- return xml unless version.present?
175
+ return xml unless version_info.present?
176
176
 
177
- xml.version(version)
177
+ xml.version(version_info)
178
178
  end
179
179
 
180
180
 
@@ -232,7 +232,13 @@ module Bolognese
232
232
  r["rightsUri"] = normalize_id(rights)
233
233
  end
234
234
 
235
- attributes = { 'rightsURI' => r["rightsUri"], 'xml:lang' => r["lang"] }.compact
235
+ attributes = {
236
+ "rightsURI" => r["rightsUri"],
237
+ "rightsIdentifier" => r["rightsIdentifier"],
238
+ "rightsIdentifierScheme" => r["rightsIdentifierScheme"],
239
+ "schemeURI" => r["schemeUri"],
240
+ "xml:lang" => r["lang"]
241
+ }.compact
236
242
 
237
243
  xml.rights(r["rights"], attributes)
238
244
  end
@@ -9,7 +9,7 @@ module Bolognese
9
9
  attr_accessor :string, :from, :sandbox, :meta, :regenerate, :issue, :show_errors
10
10
  attr_reader :doc, :page_start, :page_end
11
11
  attr_writer :id, :provider_id, :client_id, :doi, :identifiers, :creators, :contributors, :titles, :publisher,
12
- :rights_list, :dates, :publication_year, :volume, :url, :version,
12
+ :rights_list, :dates, :publication_year, :volume, :url, :version_info,
13
13
  :subjects, :contributor, :descriptions, :language, :sizes,
14
14
  :formats, :schema_version, :meta, :container, :agency,
15
15
  :format, :funding_references, :state, :geo_locations,
@@ -106,7 +106,7 @@ module Bolognese
106
106
  :publication_year,
107
107
  :descriptions,
108
108
  :rights_list,
109
- :version,
109
+ :version_info,
110
110
  :subjects,
111
111
  :language,
112
112
  :geo_locations,
@@ -117,7 +117,8 @@ module Bolognese
117
117
 
118
118
  @regenerate = options[:regenerate] || read_options.present?
119
119
  # generate name for method to call dynamically
120
- @meta = @from.present? ? send("read_" + @from, { string: string, sandbox: options[:sandbox], doi: options[:doi], id: id, ra: ra }.merge(read_options)) : {}
120
+ opts = { string: string, sandbox: options[:sandbox], doi: options[:doi], id: id, ra: ra }.merge(read_options)
121
+ @meta = @from.present? ? send("read_" + @from, **opts) : {}
121
122
  end
122
123
 
123
124
  def id
@@ -189,13 +190,10 @@ module Bolognese
189
190
  @url ||= meta.fetch("url", nil)
190
191
  end
191
192
 
192
- def version
193
- @version ||= meta.fetch("version", nil)
193
+ def version_info
194
+ @version_info ||= meta.fetch("version_info", nil) || meta.fetch("version", nil)
194
195
  end
195
196
 
196
- # for backwards compatibility
197
- alias_attribute :version_info, :version
198
-
199
197
  def publication_year
200
198
  @publication_year ||= meta.fetch("publication_year", nil)
201
199
  end
@@ -140,8 +140,14 @@ module Bolognese
140
140
  author = to_citeproc(creators)
141
141
  end
142
142
 
143
+ if types["resourceTypeGeneral"] == "Software" && version_info.present?
144
+ type = "book"
145
+ else
146
+ type = types["citeproc"]
147
+ end
148
+
143
149
  {
144
- "type" => types["citeproc"],
150
+ "type" => type,
145
151
  "id" => normalize_doi(doi),
146
152
  "categories" => Array.wrap(subjects).map { |k| parse_attributes(k, content: "subject", first: true) }.presence,
147
153
  "language" => language,
@@ -158,7 +164,8 @@ module Bolognese
158
164
  "publisher" => publisher,
159
165
  "title" => parse_attributes(titles, content: "title", first: true),
160
166
  "URL" => url,
161
- "version" => version
167
+ "copyright" => Array.wrap(rights_list).map { |l| l["rights"] }.first,
168
+ "version" => version_info
162
169
  }.compact.symbolize_keys
163
170
  end
164
171
 
@@ -180,7 +187,7 @@ module Bolognese
180
187
  "identifiers" => identifiers,
181
188
  "sizes" => sizes,
182
189
  "formats" => formats,
183
- "version" => version,
190
+ "version" => version_info,
184
191
  "rights_list" => rights_list,
185
192
  "descriptions" => descriptions,
186
193
  "geo_locations" => geo_locations,
@@ -76,6 +76,7 @@ module Bolognese
76
76
  "dateType" => "Issued" }]
77
77
  end
78
78
  publication_year = meta.try(:date).present? ? meta.date.to_s[0..3] : nil
79
+ rights_list = meta.try(:copyright).present? ? [hsh_to_spdx("rightsURI" => meta[:copyright])] : []
79
80
 
80
81
  { "id" => normalize_doi(doi),
81
82
  "types" => types,
@@ -90,7 +91,7 @@ module Bolognese
90
91
  "dates" => dates,
91
92
  "publication_year" => publication_year,
92
93
  "descriptions" => meta.try(:abstract).present? ? [{ "description" => meta.try(:abstract) && sanitize(meta.abstract.to_s).presence, "descriptionType" => "Abstract" }] : [],
93
- "rights_list" => meta.try(:copyright).present? ? [{ "rightsUri" => meta.try(:copyright).to_s.presence }.compact] : [],
94
+ "rights_list" => rights_list,
94
95
  "state" => state
95
96
  }.merge(read_options)
96
97
  end
@@ -60,7 +60,7 @@ module Bolognese
60
60
  end
61
61
  publication_year = get_date_from_date_parts(meta.fetch("issued", nil)).to_s[0..3]
62
62
  rights_list = if meta.fetch("copyright", nil)
63
- [{ "rightsUri" => normalize_url(meta.fetch("copyright")) }.compact]
63
+ [hsh_to_spdx("rightsURI" => meta.fetch("copyright"))]
64
64
  end
65
65
  related_identifiers = if meta.fetch("container-title", nil).present? && meta.fetch("ISSN", nil).present?
66
66
  [{ "type" => "Periodical",
@@ -121,7 +121,7 @@ module Bolognese
121
121
  "publication_year" => publication_year,
122
122
  "descriptions" => meta.fetch("abstract", nil).present? ? [{ "description" => sanitize(meta.fetch("abstract")), "descriptionType" => "Abstract" }] : [],
123
123
  "rights_list" => rights_list,
124
- "version" => meta.fetch("version", nil),
124
+ "version_info" => meta.fetch("version", nil),
125
125
  "subjects" => subjects,
126
126
  "state" => state
127
127
  }.merge(read_options)
@@ -64,8 +64,8 @@ module Bolognese
64
64
  end
65
65
 
66
66
  has_title = meta.fetch("title", nil)
67
-
68
67
  titles = has_title.nil? ? [{ "title" => meta.fetch("name", nil) }] : [{ "title" => has_title }]
68
+ rights_list = meta.fetch("licenseId", nil).present? ? [hsh_to_spdx("rightsIdentifier" => meta.fetch("licenseId"))] : nil
69
69
 
70
70
  { "id" => id,
71
71
  "types" => types,
@@ -80,8 +80,8 @@ module Bolognese
80
80
  "dates" => dates,
81
81
  "publication_year" => publication_year,
82
82
  "descriptions" => meta.fetch("description", nil).present? ? [{ "description" => sanitize(meta.fetch("description")), "descriptionType" => "Abstract" }] : nil,
83
- "rights_list" => [{ "rightsUri" => meta.fetch("license", nil) }.compact],
84
- "version" => meta.fetch("version", nil),
83
+ "rights_list" => rights_list,
84
+ "version_info" => meta.fetch("version", nil),
85
85
  "subjects" => subjects,
86
86
  "state" => state
87
87
  }.merge(read_options)
@@ -172,7 +172,7 @@ module Bolognese
172
172
  "publication_year" => publication_year,
173
173
  "descriptions" => crossref_description(bibliographic_metadata),
174
174
  "rights_list" => crossref_license(program_metadata),
175
- "version" => nil,
175
+ "version_info" => nil,
176
176
  "subjects" => nil,
177
177
  "language" => nil,
178
178
  "sizes" => nil,
@@ -211,7 +211,7 @@ module Bolognese
211
211
  access_indicator = Array.wrap(program_metadata).find { |m| m["name"] == "AccessIndicators" }
212
212
  if access_indicator.present?
213
213
  Array.wrap(access_indicator["license_ref"]).map do |license|
214
- { "rightsUri" => normalize_url(parse_attributes(license)) }
214
+ hsh_to_spdx("rightsURI" => parse_attributes(license))
215
215
  end.uniq
216
216
  else
217
217
  []
@@ -117,9 +117,9 @@ module Bolognese
117
117
  if r.blank?
118
118
  nil
119
119
  elsif r.is_a?(String)
120
- { "rights" => r }
120
+ name_to_spdx(r)
121
121
  elsif r.is_a?(Hash)
122
- { "rights" => r["__content__"], "rightsUri" => normalize_url(r["rightsURI"]), "lang" => r["lang"] }.compact
122
+ hsh_to_spdx(r)
123
123
  end
124
124
  end.compact
125
125
 
@@ -235,7 +235,7 @@ module Bolognese
235
235
  "publication_year" => parse_attributes(meta.fetch("publicationYear", nil), first: true).to_s.strip.presence,
236
236
  "descriptions" => descriptions,
237
237
  "rights_list" => Array.wrap(rights_list),
238
- "version" => meta.fetch("version", nil).to_s.presence,
238
+ "version_info" => meta.fetch("version", nil).to_s.presence,
239
239
  "subjects" => subjects,
240
240
  "language" => parse_attributes(meta.fetch("language", nil), first: true).to_s.strip.presence,
241
241
  "geo_locations" => geo_locations,
@@ -105,7 +105,7 @@ module Bolognese
105
105
  #"publication_year" => publication_year,
106
106
  "descriptions" => meta.fetch("description", nil).present? ? [{ "description" => sanitize(meta.fetch("description")), "descriptionType" => "Abstract" }] : [],
107
107
  "rights_list" => rights_list,
108
- "version" => meta.fetch("version", nil),
108
+ "version_info" => meta.fetch("version", nil),
109
109
  "subjects" => subjects
110
110
  #"state" => state
111
111
  }.merge(read_options)
@@ -107,10 +107,9 @@ module Bolognese
107
107
  Array.wrap(schema_org_is_supplement_to(meta)) +
108
108
  Array.wrap(schema_org_is_supplemented_by(meta))
109
109
 
110
- rights_list = [{
111
- "rightsUri" => parse_attributes(meta.fetch("license", nil), content: "id", first: true),
112
- "rights" => parse_attributes(meta.fetch("license", nil), content: "name", first: true)
113
- }]
110
+ rights_list = Array.wrap(meta.fetch("license", nil)).compact.map do |rl|
111
+ hsh_to_spdx("__content__" => rl["name"], "rightsURI" => rl["id"])
112
+ end
114
113
 
115
114
  funding_references = Array.wrap(meta.fetch("funder", nil)).compact.map do |fr|
116
115
  if fr["@id"].present?
@@ -178,7 +177,7 @@ module Bolognese
178
177
  "dates" => dates,
179
178
  "descriptions" => meta.fetch("description", nil).present? ? [{ "description" => sanitize(meta.fetch("description")), "descriptionType" => "Abstract" }] : nil,
180
179
  "rights_list" => rights_list,
181
- "version" => meta.fetch("version", nil).to_s.presence,
180
+ "version_info" => meta.fetch("version", nil).to_s.presence,
182
181
  "subjects" => subjects,
183
182
  "state" => state,
184
183
  "schema_version" => meta.fetch("schemaVersion", nil).to_s.presence,
@@ -2,13 +2,44 @@
2
2
 
3
3
  module Bolognese
4
4
  module Utils
5
- LICENSE_NAMES = {
6
- "http://creativecommons.org/publicdomain/zero/1.0/" => "Public Domain (CC0 1.0)",
7
- "http://creativecommons.org/licenses/by/3.0/" => "Creative Commons Attribution 3.0 (CC-BY 3.0)",
8
- "http://creativecommons.org/licenses/by/4.0/" => "Creative Commons Attribution 4.0 (CC-BY 4.0)",
9
- "http://creativecommons.org/licenses/by-nc/4.0/" => "Creative Commons Attribution Noncommercial 4.0 (CC-BY-NC 4.0)",
10
- "http://creativecommons.org/licenses/by-sa/4.0/" => "Creative Commons Attribution Share Alike 4.0 (CC-BY-SA 4.0)",
11
- "http://creativecommons.org/licenses/by-nc-nd/4.0/" => "Creative Commons Attribution Noncommercial No Derivatives 4.0 (CC-BY-NC-ND 4.0)"
5
+ NORMALIZED_LICENSES = {
6
+ "https://creativecommons.org/licenses/by/1.0" => "https://creativecommons.org/licenses/by/1.0/legalcode",
7
+ "https://creativecommons.org/licenses/by/2.0" => "https://creativecommons.org/licenses/by/2.0/legalcode",
8
+ "https://creativecommons.org/licenses/by/2.5" => "https://creativecommons.org/licenses/by/2.5/legalcode",
9
+ "https://creativecommons.org/licenses/by/3.0" => "https://creativecommons.org/licenses/by/3.0/legalcode",
10
+ "https://creativecommons.org/licenses/by/4.0" => "https://creativecommons.org/licenses/by/4.0/legalcode",
11
+ "https://creativecommons.org/licenses/by-nc/1.0" => "https://creativecommons.org/licenses/by-nc/1.0/legalcode",
12
+ "https://creativecommons.org/licenses/by-nc/2.0" => "https://creativecommons.org/licenses/by-nc/2.0/legalcode",
13
+ "https://creativecommons.org/licenses/by-nc/2.5" => "https://creativecommons.org/licenses/by-nc/2.5/legalcode",
14
+ "https://creativecommons.org/licenses/by-nc/3.0" => "https://creativecommons.org/licenses/by-nc/3.0/legalcode",
15
+ "https://creativecommons.org/licenses/by-nc/4.0" => "https://creativecommons.org/licenses/by-nc/4.0/legalcode",
16
+ "https://creativecommons.org/licenses/by-nd-nc/1.0" => "https://creativecommons.org/licenses/by-nd-nc/1.0/legalcode",
17
+ "https://creativecommons.org/licenses/by-nd-nc/2.0" => "https://creativecommons.org/licenses/by-nd-nc/2.0/legalcode",
18
+ "https://creativecommons.org/licenses/by-nd-nc/2.5" => "https://creativecommons.org/licenses/by-nd-nc/2.5/legalcode",
19
+ "https://creativecommons.org/licenses/by-nd-nc/3.0" => "https://creativecommons.org/licenses/by-nd-nc/3.0/legalcode",
20
+ "https://creativecommons.org/licenses/by-nd-nc/4.0" => "https://creativecommons.org/licenses/by-nd-nc/4.0/legalcode",
21
+ "https://creativecommons.org/licenses/by-nc-sa/1.0" => "https://creativecommons.org/licenses/by-nc-sa/1.0/legalcode",
22
+ "https://creativecommons.org/licenses/by-nc-sa/2.0" => "https://creativecommons.org/licenses/by-nc-sa/2.0/legalcode",
23
+ "https://creativecommons.org/licenses/by-nc-sa/2.5" => "https://creativecommons.org/licenses/by-nc-sa/2.5/legalcode",
24
+ "https://creativecommons.org/licenses/by-nc-sa/3.0" => "https://creativecommons.org/licenses/by-nc-sa/3.0/legalcode",
25
+ "https://creativecommons.org/licenses/by-nc-sa/4.0" => "https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode",
26
+ "https://creativecommons.org/licenses/by-nd/1.0" => "https://creativecommons.org/licenses/by-nd/1.0/legalcode",
27
+ "https://creativecommons.org/licenses/by-nd/2.0" => "https://creativecommons.org/licenses/by-nd/2.0/legalcode",
28
+ "https://creativecommons.org/licenses/by-nd/2.5" => "https://creativecommons.org/licenses/by-nd/2.5/legalcode",
29
+ "https://creativecommons.org/licenses/by-nd/3.0" => "https://creativecommons.org/licenses/by-nd/3.0/legalcode",
30
+ "https://creativecommons.org/licenses/by-nd/4.0" => "https://creativecommons.org/licenses/by-nd/2.0/legalcode",
31
+ "https://creativecommons.org/licenses/by-sa/1.0" => "https://creativecommons.org/licenses/by-sa/1.0/legalcode",
32
+ "https://creativecommons.org/licenses/by-sa/2.0" => "https://creativecommons.org/licenses/by-sa/2.0/legalcode",
33
+ "https://creativecommons.org/licenses/by-sa/2.5" => "https://creativecommons.org/licenses/by-sa/2.5/legalcode",
34
+ "https://creativecommons.org/licenses/by-sa/3.0" => "https://creativecommons.org/licenses/by-sa/3.0/legalcode",
35
+ "https://creativecommons.org/licenses/by-sa/4.0" => "https://creativecommons.org/licenses/by-sa/4.0/legalcode",
36
+ "https://creativecommons.org/licenses/by-nc-nd/1.0" => "https://creativecommons.org/licenses/by-nc-nd/1.0/legalcode",
37
+ "https://creativecommons.org/licenses/by-nc-nd/2.0" => "https://creativecommons.org/licenses/by-nc-nd/2.0/legalcode",
38
+ "https://creativecommons.org/licenses/by-nc-nd/2.5" => "https://creativecommons.org/licenses/by-nc-nd/2.5/legalcode",
39
+ "https://creativecommons.org/licenses/by-nc-nd/3.0" => "https://creativecommons.org/licenses/by-nc-nd/3.0/legalcode",
40
+ "https://creativecommons.org/licenses/by-nc-nd/4.0" => "https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode",
41
+ "https://creativecommons.org/licenses/publicdomain" => "https://creativecommons.org/licenses/publicdomain/",
42
+ "https://creativecommons.org/publicdomain/zero/1.0" => "https://creativecommons.org/publicdomain/zero/1.0/legalcode",
12
43
  }
13
44
 
14
45
  DC_TO_SO_TRANSLATIONS = {
@@ -475,7 +506,7 @@ module Bolognese
475
506
  nil
476
507
  end
477
508
 
478
- def normalize_url(id)
509
+ def normalize_url(id, options={})
479
510
  return nil unless id.present?
480
511
 
481
512
  # handle info URIs
@@ -485,13 +516,23 @@ module Bolognese
485
516
  uri = Addressable::URI.parse(id)
486
517
 
487
518
  return nil unless uri && uri.host && %w(http https ftp).include?(uri.scheme)
519
+
520
+ # optionally turn into https URL
521
+ uri.scheme = "https" if options[:https]
488
522
 
489
523
  # clean up URL
490
- PostRank::URI.clean(id)
524
+ uri.path = PostRank::URI.clean(uri.path)
525
+
526
+ uri.to_s
491
527
  rescue Addressable::URI::InvalidURIError
492
528
  nil
493
529
  end
494
530
 
531
+ def normalize_cc_url(id)
532
+ id = normalize_url(id, https: true)
533
+ NORMALIZED_LICENSES.fetch(id, id)
534
+ end
535
+
495
536
  def normalize_orcid(orcid)
496
537
  orcid = validate_orcid(orcid)
497
538
  return nil unless orcid.present?
@@ -1056,6 +1097,45 @@ module Bolognese
1056
1097
  error_array
1057
1098
  end
1058
1099
 
1100
+ def name_to_spdx(name)
1101
+ spdx = JSON.load(File.read(File.expand_path('../../../resources/spdx/licenses.json', __FILE__))).fetch("licenses")
1102
+ license = spdx.find { |l| l["name"] == name || l["licenseId"] == name || l["seeAlso"].first == normalize_cc_url(name) }
1103
+
1104
+ if license
1105
+ {
1106
+ "rights" => license["name"],
1107
+ "rightsUri" => license["seeAlso"].first,
1108
+ "rightsIdentifier" => license["licenseId"],
1109
+ "rightsIdentifierScheme" => "SPDX",
1110
+ "schemeUri" => "https://spdx.org/licenses/" }.compact
1111
+ else
1112
+ { "rights" => name }
1113
+ end
1114
+ end
1115
+
1116
+ def hsh_to_spdx(hsh)
1117
+ spdx = JSON.load(File.read(File.expand_path('../../../resources/spdx/licenses.json', __FILE__))).fetch("licenses")
1118
+ license = spdx.find { |l| l["licenseId"] == hsh["rightsIdentifier"] || l["seeAlso"].first == normalize_cc_url(hsh["rightsURI"]) || l["name"] == hsh["rights"] || l["seeAlso"].first == normalize_cc_url(hsh["rights"]) }
1119
+
1120
+ if license
1121
+ {
1122
+ "rights" => license["name"],
1123
+ "rightsUri" => license["seeAlso"].first,
1124
+ "rightsIdentifier" => license["licenseId"],
1125
+ "rightsIdentifierScheme" => "SPDX",
1126
+ "schemeUri" => "https://spdx.org/licenses/",
1127
+ "lang" => hsh["lang"] }.compact
1128
+ else
1129
+ {
1130
+ "rights" => hsh["__content__"],
1131
+ "rightsUri" => hsh["rightsURI"],
1132
+ "rightsIdentifier" => hsh["rightsIdentifier"],
1133
+ "rightsIdentifierScheme" => hsh["rightsIdentifierScheme"],
1134
+ "schemeUri" => hsh["schemeUri"],
1135
+ "lang" => hsh["lang"] }.compact
1136
+ end
1137
+ end
1138
+
1059
1139
  def name_to_fos(name)
1060
1140
  # first find subject in Fields of Science (OECD)
1061
1141
  fos = JSON.load(File.read(File.expand_path('../../../resources/oecd/fos-mappings.json', __FILE__))).fetch("fosFields")