bolognese 0.9.95 → 0.9.96

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b547ee2da8a99773f7e3e3ae870c07de56eb6319ea6636260d903c8af20d44f6
4
- data.tar.gz: ad9fcfcb5d4f89e6fc33b8a65bf6aceb0b6ac2255a455893c693e911815a6085
3
+ metadata.gz: 287cf1f78523ddfcae6883ae9fb97e722481978f2c6d2eceb7fe8b2e5d21fd4f
4
+ data.tar.gz: 9b21f0508c2f690614312b95623fc1c79185df7af0fcbd7ed32bf99e41213da0
5
5
  SHA512:
6
- metadata.gz: fb50d4f15b0b9af2998cb0e2e68ced3c1b8dd4bfdcfcc5ad6d5796c9fc45c5abb6cb1950d11c1728536a24ae69377fcab9c55e108789b4baf09c977e70ac9c45
7
- data.tar.gz: 84940b910aecadbadfdbe95ce3d86d6b4294ca5bdb17323bfb7be7f29021bdeacda52e049b64ebf4339bdd070ca45781c62e20b183496bc911f7903e47cc9a5b
6
+ metadata.gz: 1d340dcd70c9f0a9235ebfc56474a1e711a2a818c516d82f46b901b51b6915b2d014bbe8c53c29563b441b3b2865b63e48a0de13f32963b9f1d4148e61c0b688
7
+ data.tar.gz: 924501ab8bf513ff19106696ecf530bc3b151a6f1e3ff1e72b22cc2b03a5c6535789eff8b12fde01ba297dc3686e568758874eca222dce01afc5a1ddb24a2bac
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bolognese (0.9.95)
4
+ bolognese (0.9.96)
5
5
  activesupport (>= 4.2.5, < 6)
6
6
  benchmark_methods (~> 0.7)
7
7
  bibtex-ruby (~> 4.1)
@@ -48,7 +48,7 @@ GEM
48
48
  rdf (>= 2.2, < 4.0)
49
49
  sxp (~> 1.0)
50
50
  excon (0.62.0)
51
- faraday (0.14.0)
51
+ faraday (0.15.0)
52
52
  multipart-post (>= 1.2, < 3)
53
53
  faraday-encoding (0.0.4)
54
54
  faraday
@@ -102,7 +102,7 @@ GEM
102
102
  nokogiri (>= 1.6.1, < 1.9)
103
103
  public_suffix (>= 2.0.0, < 2.1)
104
104
  public_suffix (2.0.5)
105
- rack (2.0.4)
105
+ rack (2.0.5)
106
106
  rack-test (0.8.3)
107
107
  rack (>= 1.0, < 3)
108
108
  rake (12.3.1)
@@ -160,7 +160,7 @@ GEM
160
160
  thread_safe (~> 0.1)
161
161
  unicode_utils (1.4.0)
162
162
  vcr (3.0.3)
163
- webmock (3.3.0)
163
+ webmock (3.4.1)
164
164
  addressable (>= 2.3.6)
165
165
  crack (>= 0.3.2)
166
166
  hashdiff
@@ -3,24 +3,24 @@ module Bolognese
3
3
  def validate_doi(doi)
4
4
  doi = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(doi)).last
5
5
  # remove non-printing whitespace and downcase
6
- doi = doi.delete("\u200B").downcase if doi.present?
6
+ doi.delete("\u200B").downcase if doi.present?
7
7
  end
8
8
 
9
9
  def validate_prefix(doi)
10
10
  Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}).*\z/.match(doi)).last
11
11
  end
12
12
 
13
- def doi_resolver(doi, options={})
13
+ def doi_resolver(doi, options = {})
14
14
  sandbox = Array(/handle.test.datacite.org/.match(doi)).last
15
15
  sandbox.present? || options[:sandbox] ? "https://handle.test.datacite.org/" : "https://doi.org/"
16
16
  end
17
17
 
18
- def doi_search(doi, options={})
18
+ def doi_search(doi, options = {})
19
19
  sandbox = Array(/handle.test.datacite.org/.match(doi)).last
20
20
  sandbox.present? || options[:sandbox] ? "https://search.test.datacite.org/api" : "https://search.datacite.org/api"
21
21
  end
22
22
 
23
- def normalize_doi(doi, options={})
23
+ def normalize_doi(doi, options = {})
24
24
  doi_str = validate_doi(doi)
25
25
  return nil unless doi_str.present?
26
26
 
@@ -1,84 +1,10 @@
1
- require_relative 'doi_utils'
2
- require_relative 'author_utils'
3
- require_relative 'datacite_utils'
4
- require_relative 'utils'
5
-
6
- require_relative 'readers/bibtex_reader'
7
- require_relative 'readers/citeproc_reader'
8
- require_relative 'readers/codemeta_reader'
9
- require_relative 'readers/crosscite_reader'
10
- require_relative 'readers/crossref_reader'
11
- require_relative 'readers/datacite_json_reader'
12
- require_relative 'readers/datacite_reader'
13
- require_relative 'readers/ris_reader'
14
- require_relative 'readers/schema_org_reader'
15
-
16
- require_relative 'writers/bibtex_writer'
17
- require_relative 'writers/citation_writer'
18
- require_relative 'writers/citeproc_writer'
19
- require_relative 'writers/codemeta_writer'
20
- require_relative 'writers/crosscite_writer'
21
- require_relative 'writers/crossref_writer'
22
- require_relative 'writers/datacite_writer'
23
- require_relative 'writers/datacite_json_writer'
24
- require_relative 'writers/jats_writer'
25
- require_relative 'writers/rdf_xml_writer'
26
- require_relative 'writers/ris_writer'
27
- require_relative 'writers/schema_org_writer'
28
- require_relative 'writers/turtle_writer'
1
+ require_relative 'metadata_utils'
29
2
 
30
3
  module Bolognese
31
4
  class Metadata
32
- # include BenchmarkMethods
33
- include Bolognese::DoiUtils
34
- include Bolognese::AuthorUtils
35
- include Bolognese::DataciteUtils
36
- include Bolognese::Utils
37
-
38
- include Bolognese::Readers::BibtexReader
39
- include Bolognese::Readers::CiteprocReader
40
- include Bolognese::Readers::CodemetaReader
41
- include Bolognese::Readers::CrossciteReader
42
- include Bolognese::Readers::CrossrefReader
43
- include Bolognese::Readers::DataciteReader
44
- include Bolognese::Readers::DataciteJsonReader
45
- include Bolognese::Readers::RisReader
46
- include Bolognese::Readers::SchemaOrgReader
47
-
48
- include Bolognese::Writers::BibtexWriter
49
- include Bolognese::Writers::CitationWriter
50
- include Bolognese::Writers::CiteprocWriter
51
- include Bolognese::Writers::CodemetaWriter
52
- include Bolognese::Writers::CrossciteWriter
53
- include Bolognese::Writers::CrossrefWriter
54
- include Bolognese::Writers::DataciteWriter
55
- include Bolognese::Writers::DataciteJsonWriter
56
- include Bolognese::Writers::JatsWriter
57
- include Bolognese::Writers::RdfXmlWriter
58
- include Bolognese::Writers::RisWriter
59
- include Bolognese::Writers::SchemaOrgWriter
60
- include Bolognese::Writers::TurtleWriter
61
-
62
- attr_accessor :id, :identifier, :doi, :author, :creator, :title, :publisher, :contributor, :license,
63
- :date_accepted, :date_available, :date_copyrighted, :date_collected,
64
- :date_submitted, :date_valid, :date_created, :date_modified,
65
- :date_registered, :date_updated, :provider_id, :client_id, :journal,
66
- :volume, :issue, :first_page, :last_page, :b_url, :b_version, :keywords, :editor,
67
- :description, :alternate_name, :language, :content_size, :spatial_coverage,
68
- :schema_version, :additional_type, :has_part, :same_as,
69
- :is_previous_version_of, :is_new_version_of, :is_cited_by, :cites,
70
- :is_supplement_to, :is_supplemented_by, :is_continued_by, :continues,
71
- :has_metadata, :is_metadata_for, :is_referenced_by, :references,
72
- :is_documented_by, :documents, :is_compiled_by, :compiles,
73
- :is_variant_form_of, :is_original_form_of, :is_reviewed_by, :reviews,
74
- :is_derived_from, :is_source_of, :format, :funding, :type, :bibtex_type,
75
- :citeproc_type, :ris_type, :style, :locale, :state
5
+ include Bolognese::MetadataUtils
76
6
 
77
- attr_reader :id, :from, :raw, :metadata, :doc, :service_provider,
78
- :page_start, :page_end, :should_passthru, :errors,
79
- :related_identifier, :reverse, :name_detector
80
-
81
- def initialize(input: nil, from: nil, style: nil, locale: nil, regenerate: false, **options)
7
+ def initialize(input: nil, from: nil, **options)
82
8
  id = normalize_id(input, options)
83
9
 
84
10
  if id.present?
@@ -109,310 +35,23 @@ module Bolognese
109
35
 
110
36
  # make sure input is encoded as utf8
111
37
  string = string.force_encoding("UTF-8") if string.present?
38
+ @string = string
112
39
 
113
- # generate name for method to call dynamically
114
- @metadata = @from.present? ? send("read_" + @from, string: string, id: id, sandbox: options[:sandbox], doi: options[:doi], b_url: options[:b_url]) : {}
115
- @raw = string.present? ? string.strip : nil
116
-
117
- # input specific metadata elements required for DataCite
118
- @doi = options[:doi].presence
119
- @author = options[:author].presence
120
- @title = options[:title].presence
121
- @publisher = options[:publisher].presence
122
- @resource_type_general = options[:resource_type_general].presence
123
-
124
- # input specific metadata elements recommended for DataCite
125
- @additional_type = options[:additional_type].presence
126
- @description = options[:description].presence
127
- @license = options[:license].presence
128
- @date_published = options[:date_published].presence
129
-
130
- # replace DOI in XML if provided in options
131
- if @from == "datacite" && options[:doi].present? && string.present?
132
- doc = Nokogiri::XML(string, nil, 'UTF-8', &:noblanks)
133
- node = doc.at_css("identifier")
134
- node.content = options[:doi].upcase
135
- @raw = doc.to_xml.strip
136
- end
40
+ # input options for citation formatting
41
+ @style = options[:style]
42
+ @locale = options[:locale]
137
43
 
138
- @should_passthru = (@from == "datacite") && !regenerate
44
+ @regenerate = options[:regenerate]
45
+ @sandbox = options[:sandbox]
139
46
 
140
- @b_url = hsh.to_h["b_url"].presence
47
+ # options that come from the datacite database
48
+ @b_doi = normalize_doi(options[:doi] || input, options)
49
+ @b_url = hsh.to_h["b_url"].presence || options[:b_url].presence
141
50
  @state = hsh.to_h["state"].presence
142
51
  @date_registered = hsh.to_h["date_registered"].presence
143
52
  @date_updated = hsh.to_h["date_updated"].presence
144
53
  @provider_id = hsh.to_h["provider_id"].presence
145
54
  @client_id = hsh.to_h["client_id"].presence
146
-
147
- @style = style || "apa"
148
- @locale = locale || "en-US"
149
- end
150
-
151
- def exists?
152
- metadata.fetch("state", "not_found") != "not_found"
153
- end
154
-
155
- def valid?
156
- exists? && errors.nil?
157
- end
158
-
159
- # validate against DataCite schema, unless there are already errors in the reader
160
- def errors
161
- xml = should_passthru ? raw : datacite_xml
162
- metadata.fetch("errors", nil) || datacite_errors(xml: xml,
163
- schema_version: schema_version)
164
- end
165
-
166
- def id
167
- @id ||= metadata.fetch("id", nil)
168
- end
169
-
170
- def type
171
- @type ||= metadata.fetch("type", nil)
172
- end
173
-
174
- def additional_type
175
- @additional_type ||= metadata.fetch("additional_type", nil)
176
- end
177
-
178
- def citeproc_type
179
- @citeproc_type ||= metadata.fetch("citeproc_type", nil)
180
- end
181
-
182
- def bibtex_type
183
- @bibtex_type ||= metadata.fetch("bibtex_type", nil)
184
- end
185
-
186
- def ris_type
187
- @ris_type ||= metadata.fetch("ris_type", nil)
188
- end
189
-
190
- def resource_type_general
191
- @resource_type_general ||= metadata.fetch("resource_type_general", nil)
192
- end
193
-
194
- def doi
195
- @doi ||= @id.present? ? doi_from_url(@id) : metadata.fetch("doi", nil)
196
- end
197
-
198
- def b_url
199
- @b_url ||= metadata.fetch("b_url", nil)
200
- end
201
-
202
- def identifier
203
- @identifier ||= metadata.fetch("id", nil)
204
- end
205
-
206
- def state
207
- @state ||= metadata.fetch("state", nil)
208
- end
209
-
210
- def title
211
- @title ||= metadata.fetch("title", nil)
212
- end
213
-
214
- def alternate_name
215
- @alternate_name ||= metadata.fetch("alternate_name", nil)
216
- end
217
-
218
- def author
219
- @author ||= metadata.fetch("author", nil)
220
- end
221
-
222
- def editor
223
- @editor ||= metadata.fetch("editor", nil)
224
- end
225
-
226
- def publisher
227
- @publisher ||= metadata.fetch("publisher", nil)
228
- end
229
-
230
- def service_provider
231
- @service_provider ||= metadata.fetch("service_provider", nil)
232
- end
233
-
234
- def date_created
235
- @date_created ||= metadata.fetch("date_created", nil)
236
- end
237
-
238
- def date_accepted
239
- @date_accepted ||= metadata.fetch("date_accepted", nil)
240
- end
241
-
242
- def date_available
243
- @date_available ||= metadata.fetch("date_available", nil)
244
- end
245
-
246
- def date_copyrighted
247
- @date_copyrighted ||= metadata.fetch("date_copyrighted", nil)
248
- end
249
-
250
- def date_collected
251
- @date_collected ||= metadata.fetch("date_collected", nil)
252
- end
253
-
254
- def date_submitted
255
- @date_submitted ||= metadata.fetch("date_submitted", nil)
256
- end
257
-
258
- def date_valid
259
- @date_valid ||= metadata.fetch("date_valid", nil)
260
- end
261
-
262
- def date_published
263
- @date_published ||= metadata.fetch("date_published", nil)
264
- end
265
-
266
- def date_modified
267
- @date_modified ||= metadata.fetch("date_modified", nil)
268
- end
269
-
270
- def date_registered
271
- @date_registered ||= metadata.fetch("date_registered", nil)
272
- end
273
-
274
- def date_updated
275
- @date_updated ||= metadata.fetch("date_updated", nil)
276
- end
277
-
278
- def volume
279
- @volume ||= metadata.fetch("volume", nil)
280
- end
281
-
282
- def first_page
283
- @first_page ||= metadata.fetch("first_page", nil)
284
- end
285
-
286
- def last_page
287
- @last_page ||= metadata.fetch("last_page", nil)
288
- end
289
-
290
- def description
291
- @description ||= metadata.fetch("description", nil)
292
- end
293
-
294
- def license
295
- @license ||= metadata.fetch("license", nil)
296
- end
297
-
298
- def b_version
299
- @b_version ||= metadata.fetch("b_version", nil)
300
- end
301
-
302
- def keywords
303
- @keywords ||= metadata.fetch("keywords", nil)
304
- end
305
-
306
- def language
307
- @language ||= metadata.fetch("language", nil)
308
- end
309
-
310
- def content_size
311
- @content_size ||= metadata.fetch("content_size", nil)
312
- end
313
-
314
- def schema_version
315
- @schema_version ||= metadata.fetch("schema_version", nil)
316
- end
317
-
318
- def funding
319
- @funding ||= metadata.fetch("funding", nil)
320
- end
321
-
322
- def provider_id
323
- @provider_id ||= metadata.fetch("provider_id", nil)
324
- end
325
-
326
- def client_id
327
- @client_id ||= metadata.fetch("client_id", nil)
328
- end
329
-
330
- def is_identical_to
331
- metadata.fetch("is_identical_to", nil)
332
- end
333
-
334
- def is_part_of
335
- metadata.fetch("is_part_of", nil)
336
- end
337
-
338
- def has_part
339
- metadata.fetch("has_part", nil)
340
- end
341
-
342
- def is_previous_version_of
343
- metadata.fetch("is_previous_of", nil)
344
- end
345
-
346
- def is_new_version_of
347
- metadata.fetch("is_new_version_of", nil)
348
- end
349
-
350
- def is_variant_form_of
351
- metadata.fetch("is_variant_form_of", nil)
352
- end
353
-
354
- def is_original_form_of
355
- metadata.fetch("is_original_form_of", nil)
356
- end
357
-
358
- def references
359
- metadata.fetch("references", nil)
360
- end
361
-
362
- def is_referenced_by
363
- metadata.fetch("is_referenced_by", nil)
364
- end
365
-
366
- def is_supplement_to
367
- metadata.fetch("is_supplement_to", nil)
368
- end
369
-
370
- def is_supplemented_by
371
- metadata.fetch("is_supplemented_by", nil)
372
- end
373
-
374
- def reviews
375
- metadata.fetch("reviews", nil)
376
- end
377
-
378
- def is_reviewed_by
379
- metadata.fetch("is_reviewed_by", nil)
380
- end
381
-
382
- def related_identifier_hsh(relation_type)
383
- Array.wrap(send(relation_type)).select { |r| r["id"] || r["issn"] }
384
- .map { |r| r.merge("relationType" => relation_type.camelize) }
385
- end
386
-
387
- def related_identifier
388
- relation_types = %w(is_part_of has_part references is_referenced_by is_supplement_to is_supplemented_by)
389
- relation_types.reduce([]) { |sum, r| sum += related_identifier_hsh(r) }
390
- end
391
-
392
- # recognize given name. Can be loaded once as ::NameDetector, e.g. in a Rails initializer
393
- def name_detector
394
- @name_detector ||= defined?(::NameDetector) ? ::NameDetector : nil
395
- end
396
-
397
- def publication_year
398
- date_published.present? ? date_published[0..3].to_i.presence : nil
399
- end
400
-
401
- def container_title
402
- Array.wrap(is_part_of).first.to_h.fetch("title", nil)
403
- end
404
-
405
- def descriptions
406
- Array.wrap(description)
407
- end
408
-
409
- def reverse
410
- { "citation" => Array.wrap(is_referenced_by).map { |r| { "@id" => r["id"] }}.unwrap,
411
- "isBasedOn" => Array.wrap(is_supplement_to).map { |r| { "@id" => r["id"] }}.unwrap }.compact
412
- end
413
-
414
- def graph
415
- RDF::Graph.new << JSON::LD::API.toRdf(schema_hsh)
416
55
  end
417
56
  end
418
- end
57
+ end