Module: Bolognese::MetadataUtils

Constant Summary

Constants included from Readers::SchemaOrgReader

Readers::SchemaOrgReader::SO_TO_DC_RELATION_TYPES

Constants included from Readers::RisReader

Readers::RisReader::RIS_TO_BIB_TRANSLATIONS, Readers::RisReader::RIS_TO_CP_TRANSLATIONS, Readers::RisReader::RIS_TO_SO_TRANSLATIONS

Constants included from Readers::CrossrefReader

Readers::CrossrefReader::CONTACT_EMAIL

Constants included from Readers::CiteprocReader

Readers::CiteprocReader::CP_TO_RIS_TRANSLATIONS, Readers::CiteprocReader::CP_TO_SO_TRANSLATIONS

Constants included from Readers::BibtexReader

Readers::BibtexReader::BIB_TO_CP_TRANSLATIONS, Readers::BibtexReader::BIB_TO_RIS_TRANSLATIONS, Readers::BibtexReader::BIB_TO_SO_TRANSLATIONS

Constants included from Utils

Utils::BIB_TO_CR_TRANSLATIONS, Utils::CR_TO_BIB_TRANSLATIONS, Utils::CR_TO_CP_TRANSLATIONS, Utils::CR_TO_JATS_TRANSLATIONS, Utils::CR_TO_RIS_TRANSLATIONS, Utils::CR_TO_SO_TRANSLATIONS, Utils::DC_TO_CP_TRANSLATIONS, Utils::DC_TO_RIS_TRANSLATIONS, Utils::DC_TO_SO_TRANSLATIONS, Utils::LICENSE_NAMES, Utils::SO_TO_BIB_TRANSLATIONS, Utils::SO_TO_CP_TRANSLATIONS, Utils::SO_TO_DC_TRANSLATIONS, Utils::SO_TO_JATS_TRANSLATIONS, Utils::SO_TO_RIS_TRANSLATIONS

Constants included from AuthorUtils

AuthorUtils::IDENTIFIER_SCHEME_URIS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Writers::TurtleWriter

#turtle

Methods included from Writers::SchemaOrgWriter

#schema_hsh, #schema_org

Methods included from Writers::RisWriter

#ris

Methods included from Writers::RdfXmlWriter

#rdf_xml

Methods included from Writers::JatsWriter

#date, #insert_authors, #insert_citation, #insert_citation_title, #insert_contributor, #insert_editors, #insert_fpage, #insert_issue, #insert_lpage, #insert_pub_id, #insert_publication_date, #insert_publisher_name, #insert_source, #insert_version, #insert_volume, #is_article?, #is_chapter?, #is_data?, #jats, #publication_type

Methods included from Writers::DataciteJsonWriter

#datacite_json

Methods included from Writers::DataciteWriter

#datacite

Methods included from Writers::CrossrefWriter

#crossref

Methods included from Writers::CrossciteWriter

#crosscite

Methods included from Writers::CodemetaWriter

#codemeta

Methods included from Writers::CiteprocWriter

#citeproc

Methods included from Writers::CitationWriter

#citation

Methods included from Writers::BibtexWriter

#bibtex

Methods included from Readers::SchemaOrgReader

#get_schema_org, #read_schema_org, #schema_org_has_part, #schema_org_is_identical_to, #schema_org_is_new_version_of, #schema_org_is_part_of, #schema_org_is_previous_version_of, #schema_org_is_referenced_by, #schema_org_is_supplement_to, #schema_org_is_supplemented_by, #schema_org_references, #schema_org_related_identifier, #schema_org_reverse_related_identifier

Methods included from Readers::RisReader

#read_ris, #ris_meta

Methods included from Readers::DataciteJsonReader

#read_datacite_json

Methods included from Readers::DataciteReader

#datacite_date, #datacite_funder_contributor, #datacite_funding_reference, #datacite_has_part, #datacite_is_identical_to, #datacite_is_new_version_of, #datacite_is_original_form_of, #datacite_is_part_of, #datacite_is_previous_version_of, #datacite_is_referenced_by, #datacite_is_reviewed_by, #datacite_is_supplement_to, #datacite_is_supplemented_by, #datacite_is_variant_form_of, #datacite_references, #datacite_related_identifier, #datacite_reviews, #get_datacite, #read_datacite

Methods included from Readers::CrossrefReader

#crossref_alternate_identifier, #crossref_date_published, #crossref_description, #crossref_funding_reference, #crossref_is_part_of, #crossref_license, #crossref_people, #crossref_references, #get_crossref, #read_crossref

Methods included from Readers::CrossciteReader

#read_crosscite

Methods included from Readers::CodemetaReader

#get_codemeta, #read_codemeta

Methods included from Readers::CiteprocReader

#read_citeproc

Methods included from Readers::BibtexReader

#read_bibtex

Methods included from Utils

#find_from_format, #find_from_format_by_ext, #find_from_format_by_id, #find_from_format_by_string, #from_citeproc, #from_schema_org, #get_date_from_date_parts, #get_date_from_parts, #get_date_parts, #get_date_parts_from_parts, #get_datetime_from_iso8601, #get_year_month, #get_year_month_day, #github_as_codemeta_url, #github_as_owner_url, #github_as_release_url, #github_as_repo_url, #github_from_url, #github_owner_from_url, #github_release_from_url, #github_repo_from_url, #jsonlint, #map_hash_keys, #normalize_id, #normalize_ids, #normalize_licenses, #normalize_orcid, #normalize_url, #orcid_as_url, #orcid_from_url, #parse_attributes, #sanitize, #to_citeproc, #to_ris, #to_schema_org, #to_schema_org_container, #to_schema_org_identifier, #validate_orcid, #validate_orcid_scheme, #validate_url

Methods included from DataciteUtils

#datacite_errors, #datacite_xml, #insert_alternate_identifiers, #insert_contributors, #insert_creators, #insert_date, #insert_dates, #insert_descriptions, #insert_funding_reference, #insert_funding_references, #insert_identifier, #insert_person, #insert_publication_year, #insert_publisher, #insert_related_identifiers, #insert_resource_type, #insert_rights_list, #insert_subjects, #insert_title, #insert_titles, #insert_version, #insert_work, #rel_identifier, #res_type, #root_attributes

Methods included from AuthorUtils

#authors_as_string, #cleanup_author, #get_authors, #get_name_identifiers, #get_one_author, #is_personal_name?, #name_exists?

Methods included from DoiUtils

#doi_as_url, #doi_from_url, #doi_resolver, #doi_search, #get_doi_ra, #normalize_doi, #validate_doi, #validate_prefix

Instance Attribute Details

#additional_typeObject



102
103
104
# File 'lib/bolognese/metadata_utils.rb', line 102

def additional_type
  @additional_type ||= meta.fetch("additional_type", nil)
end

#alternate_identifierObject



126
127
128
# File 'lib/bolognese/metadata_utils.rb', line 126

def alternate_identifier
  @alternate_identifier ||= meta.fetch("alternate_identifier", nil)
end

#authorObject



142
143
144
# File 'lib/bolognese/metadata_utils.rb', line 142

def author
  @author ||= meta.fetch("author", nil)
end

#b_urlObject



308
309
310
# File 'lib/bolognese/metadata_utils.rb', line 308

def b_url
  @b_url ||= meta.fetch("b_url", nil)
end

#b_versionObject



312
313
314
# File 'lib/bolognese/metadata_utils.rb', line 312

def b_version
  @b_version ||= meta.fetch("b_version", nil)
end

#bibtex_typeObject



110
111
112
# File 'lib/bolognese/metadata_utils.rb', line 110

def bibtex_type
  @bibtex_type ||= meta.fetch("bibtex_type", nil)
end

#citeproc_typeObject



106
107
108
# File 'lib/bolognese/metadata_utils.rb', line 106

def citeproc_type
  @citeproc_type ||= meta.fetch("citeproc_type", nil)
end

#cites=(value) ⇒ Object (writeonly)

Sets the attribute cites

Parameters:

  • value

    the value to set the attribute cites to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def cites=(value)
  @cites = value
end

#compiles=(value) ⇒ Object (writeonly)

Sets the attribute compiles

Parameters:

  • value

    the value to set the attribute compiles to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def compiles=(value)
  @compiles = value
end

#content_formatObject



234
235
236
# File 'lib/bolognese/metadata_utils.rb', line 234

def content_format
  @content_format ||= meta.fetch("content_format", nil)
end

#content_sizeObject



230
231
232
# File 'lib/bolognese/metadata_utils.rb', line 230

def content_size
  @content_size ||= meta.fetch("content_size", nil)
end

#content_urlObject



130
131
132
# File 'lib/bolognese/metadata_utils.rb', line 130

def content_url
  @content_url ||= meta.fetch("content_url", nil)
end

#continues=(value) ⇒ Object (writeonly)

Sets the attribute continues

Parameters:

  • value

    the value to set the attribute continues to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def continues=(value)
  @continues = value
end

#contributorObject

Returns the value of attribute contributor.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def contributor
  @contributor
end

#date_acceptedObject



162
163
164
# File 'lib/bolognese/metadata_utils.rb', line 162

def date_accepted
  @date_accepted ||= meta.fetch("date_accepted", nil)
end

#date_availableObject



166
167
168
# File 'lib/bolognese/metadata_utils.rb', line 166

def date_available
  @date_available ||= meta.fetch("date_available", nil)
end

#date_collectedObject



174
175
176
# File 'lib/bolognese/metadata_utils.rb', line 174

def date_collected
  @date_collected ||= meta.fetch("date_collected", nil)
end

#date_copyrightedObject



170
171
172
# File 'lib/bolognese/metadata_utils.rb', line 170

def date_copyrighted
  @date_copyrighted ||= meta.fetch("date_copyrighted", nil)
end

#date_createdObject



158
159
160
# File 'lib/bolognese/metadata_utils.rb', line 158

def date_created
  @date_created ||= meta.fetch("date_created", nil)
end

#date_modifiedObject



190
191
192
# File 'lib/bolognese/metadata_utils.rb', line 190

def date_modified
  @date_modified ||= meta.fetch("date_modified", nil)
end

#date_publishedObject



186
187
188
# File 'lib/bolognese/metadata_utils.rb', line 186

def date_published
  @date_published ||= meta.fetch("date_published", nil)
end

#date_submittedObject



178
179
180
# File 'lib/bolognese/metadata_utils.rb', line 178

def 
  @date_submitted ||= meta.fetch("date_submitted", nil)
end

#date_updatedObject



198
199
200
# File 'lib/bolognese/metadata_utils.rb', line 198

def date_updated
  @date_updated ||= meta.fetch("date_updated", nil)
end

#date_validObject



182
183
184
# File 'lib/bolognese/metadata_utils.rb', line 182

def date_valid
  @date_valid ||= meta.fetch("date_valid", nil)
end

#descriptionObject



214
215
216
# File 'lib/bolognese/metadata_utils.rb', line 214

def description
  @description ||= meta.fetch("description", nil)
end

#docObject (readonly)

Returns the value of attribute doc.



81
82
83
# File 'lib/bolognese/metadata_utils.rb', line 81

def doc
  @doc
end

#documents=(value) ⇒ Object (writeonly)

Sets the attribute documents

Parameters:

  • value

    the value to set the attribute documents to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def documents=(value)
  @documents = value
end

#editorObject



146
147
148
# File 'lib/bolognese/metadata_utils.rb', line 146

def editor
  @editor ||= meta.fetch("editor", nil)
end

#first_pageObject



206
207
208
# File 'lib/bolognese/metadata_utils.rb', line 206

def first_page
  @first_page ||= meta.fetch("first_page", nil)
end

#format=(value) ⇒ Object (writeonly)

Sets the attribute format

Parameters:

  • value

    the value to set the attribute format to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def format=(value)
  @format = value
end

#fromObject

Returns the value of attribute from.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def from
  @from
end

#fundingObject



242
243
244
# File 'lib/bolognese/metadata_utils.rb', line 242

def funding
  @funding ||= meta.fetch("funding", nil)
end

#has_metadata=(value) ⇒ Object (writeonly)

Sets the attribute has_metadata

Parameters:

  • value

    the value to set the attribute has_metadata to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def has_metadata=(value)
  @has_metadata = value
end

#has_partObject



254
255
256
# File 'lib/bolognese/metadata_utils.rb', line 254

def has_part
  meta.fetch("has_part", nil)
end

#identifierObject



122
123
124
# File 'lib/bolognese/metadata_utils.rb', line 122

def identifier
  @identifier ||= meta.fetch("id", nil)
end

#is_cited_by=(value) ⇒ Object (writeonly)

Sets the attribute is_cited_by

Parameters:

  • value

    the value to set the attribute is_cited_by to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def is_cited_by=(value)
  @is_cited_by = value
end

#is_compiled_by=(value) ⇒ Object (writeonly)

Sets the attribute is_compiled_by

Parameters:

  • value

    the value to set the attribute is_compiled_by to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def is_compiled_by=(value)
  @is_compiled_by = value
end

#is_continued_by=(value) ⇒ Object (writeonly)

Sets the attribute is_continued_by

Parameters:

  • value

    the value to set the attribute is_continued_by to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def is_continued_by=(value)
  @is_continued_by = value
end

#is_derived_from=(value) ⇒ Object (writeonly)

Sets the attribute is_derived_from

Parameters:

  • value

    the value to set the attribute is_derived_from to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def is_derived_from=(value)
  @is_derived_from = value
end

#is_documented_by=(value) ⇒ Object (writeonly)

Sets the attribute is_documented_by

Parameters:

  • value

    the value to set the attribute is_documented_by to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def is_documented_by=(value)
  @is_documented_by = value
end

#is_metadata_for=(value) ⇒ Object (writeonly)

Sets the attribute is_metadata_for

Parameters:

  • value

    the value to set the attribute is_metadata_for to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def (value)
  @is_metadata_for = value
end

#is_new_version_ofObject



262
263
264
# File 'lib/bolognese/metadata_utils.rb', line 262

def is_new_version_of
  meta.fetch("is_new_version_of", nil)
end

#is_original_form_ofObject



270
271
272
# File 'lib/bolognese/metadata_utils.rb', line 270

def is_original_form_of
  meta.fetch("is_original_form_of", nil)
end

#is_previous_version_ofObject



258
259
260
# File 'lib/bolognese/metadata_utils.rb', line 258

def is_previous_version_of
  meta.fetch("is_previous_of", nil)
end

#is_referenced_byObject



278
279
280
# File 'lib/bolognese/metadata_utils.rb', line 278

def is_referenced_by
  meta.fetch("is_referenced_by", nil)
end

#is_reviewed_byObject



294
295
296
# File 'lib/bolognese/metadata_utils.rb', line 294

def is_reviewed_by
  meta.fetch("is_reviewed_by", nil)
end

#is_source_of=(value) ⇒ Object (writeonly)

Sets the attribute is_source_of

Parameters:

  • value

    the value to set the attribute is_source_of to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def is_source_of=(value)
  @is_source_of = value
end

#is_supplement_toObject



282
283
284
# File 'lib/bolognese/metadata_utils.rb', line 282

def is_supplement_to
  meta.fetch("is_supplement_to", nil)
end

#is_supplemented_byObject



286
287
288
# File 'lib/bolognese/metadata_utils.rb', line 286

def is_supplemented_by
  meta.fetch("is_supplemented_by", nil)
end

#is_variant_form_ofObject



266
267
268
# File 'lib/bolognese/metadata_utils.rb', line 266

def is_variant_form_of
  meta.fetch("is_variant_form_of", nil)
end

#issueObject

Returns the value of attribute issue.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def issue
  @issue
end

#journal=(value) ⇒ Object (writeonly)

Sets the attribute journal

Parameters:

  • value

    the value to set the attribute journal to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def journal=(value)
  @journal = value
end

#keywordsObject



222
223
224
# File 'lib/bolognese/metadata_utils.rb', line 222

def keywords
  @keywords ||= meta.fetch("keywords", nil)
end

#languageObject



226
227
228
# File 'lib/bolognese/metadata_utils.rb', line 226

def language
  @language ||= meta.fetch("language", nil)
end

#last_pageObject



210
211
212
# File 'lib/bolognese/metadata_utils.rb', line 210

def last_page
  @last_page ||= meta.fetch("last_page", nil)
end

#licenseObject



218
219
220
# File 'lib/bolognese/metadata_utils.rb', line 218

def license
  @license ||= meta.fetch("license", nil)
end

#localeObject



346
347
348
# File 'lib/bolognese/metadata_utils.rb', line 346

def locale
  @locale ||= "en-US"
end

#metaObject

Returns the value of attribute meta.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def meta
  @meta
end

#name_detectorObject (readonly)

recognize given name. Can be loaded once as ::NameDetector, e.g. in a Rails initializer



317
318
319
# File 'lib/bolognese/metadata_utils.rb', line 317

def name_detector
  @name_detector
end

#page_endObject (readonly)

Returns the value of attribute page_end.



81
82
83
# File 'lib/bolognese/metadata_utils.rb', line 81

def page_end
  @page_end
end

#page_startObject (readonly)

Returns the value of attribute page_start.



81
82
83
# File 'lib/bolognese/metadata_utils.rb', line 81

def page_start
  @page_start
end

#publisherObject



150
151
152
# File 'lib/bolognese/metadata_utils.rb', line 150

def publisher
  @publisher ||= meta.fetch("publisher", nil)
end

#referencesObject



274
275
276
# File 'lib/bolognese/metadata_utils.rb', line 274

def references
  meta.fetch("references", nil)
end

#regenerateObject

Returns the value of attribute regenerate.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def regenerate
  @regenerate
end

Returns the value of attribute related_identifier.



81
82
83
# File 'lib/bolognese/metadata_utils.rb', line 81

def related_identifier
  @related_identifier
end

#resource_type_generalObject



118
119
120
# File 'lib/bolognese/metadata_utils.rb', line 118

def resource_type_general
  @resource_type_general ||= meta.fetch("resource_type_general", nil)
end

#reverseObject (readonly)

Returns the value of attribute reverse.



81
82
83
# File 'lib/bolognese/metadata_utils.rb', line 81

def reverse
  @reverse
end

#reviewsObject



290
291
292
# File 'lib/bolognese/metadata_utils.rb', line 290

def reviews
  meta.fetch("reviews", nil)
end

#ris_typeObject



114
115
116
# File 'lib/bolognese/metadata_utils.rb', line 114

def ris_type
  @ris_type ||= meta.fetch("ris_type", nil)
end

#same_as=(value) ⇒ Object (writeonly)

Sets the attribute same_as

Parameters:

  • value

    the value to set the attribute same_as to.



67
68
69
# File 'lib/bolognese/metadata_utils.rb', line 67

def same_as=(value)
  @same_as = value
end

#sandboxObject

Returns the value of attribute sandbox.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def sandbox
  @sandbox
end

#schema_versionObject



238
239
240
# File 'lib/bolognese/metadata_utils.rb', line 238

def schema_version
  @schema_version ||= meta.fetch("schema_version", nil)
end

#service_providerObject (readonly)

Returns the value of attribute service_provider.



81
82
83
# File 'lib/bolognese/metadata_utils.rb', line 81

def service_provider
  @service_provider
end

#spatial_coverageObject

Returns the value of attribute spatial_coverage.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def spatial_coverage
  @spatial_coverage
end

#stateObject



134
135
136
# File 'lib/bolognese/metadata_utils.rb', line 134

def state
  @state ||= meta.fetch("state", nil)
end

#stringObject

Returns the value of attribute string.



64
65
66
# File 'lib/bolognese/metadata_utils.rb', line 64

def string
  @string
end

#styleObject



342
343
344
# File 'lib/bolognese/metadata_utils.rb', line 342

def style
  @style ||= "apa"
end

#titleObject



138
139
140
# File 'lib/bolognese/metadata_utils.rb', line 138

def title
  @title ||= meta.fetch("title", nil)
end

#typeObject



98
99
100
# File 'lib/bolognese/metadata_utils.rb', line 98

def type
  @type ||= meta.fetch("type", nil)
end

#volumeObject



202
203
204
# File 'lib/bolognese/metadata_utils.rb', line 202

def volume
  @volume ||= meta.fetch("volume", nil)
end

Instance Method Details

#container_titleObject



325
326
327
# File 'lib/bolognese/metadata_utils.rb', line 325

def container_title
  meta.fetch("container_title", nil) || Array.wrap(is_part_of).first.to_h.fetch("title", nil)
end

#date_registeredObject



194
195
196
# File 'lib/bolognese/metadata_utils.rb', line 194

def date_registered
  @date_registered ||= meta.fetch("date_registered", nil)
end

#descriptionsObject



329
330
331
# File 'lib/bolognese/metadata_utils.rb', line 329

def descriptions
  Array.wrap(description)
end

#graphObject



338
339
340
# File 'lib/bolognese/metadata_utils.rb', line 338

def graph
  RDF::Graph.new << JSON::LD::API.toRdf(schema_hsh)
end

#is_identical_toObject



246
247
248
# File 'lib/bolognese/metadata_utils.rb', line 246

def is_identical_to
  meta.fetch("is_identical_to", nil)
end

#is_part_ofObject



250
251
252
# File 'lib/bolognese/metadata_utils.rb', line 250

def is_part_of
  meta.fetch("is_part_of", nil)
end

#publication_yearObject



321
322
323
# File 'lib/bolognese/metadata_utils.rb', line 321

def publication_year
  date_published.present? ? date_published[0..3].to_i.presence : nil
end

#rawObject

replace DOI in XML if provided in options



84
85
86
87
88
89
90
91
92
# File 'lib/bolognese/metadata_utils.rb', line 84

def raw
  r = string.present? ? string.strip : nil
  return r unless (from == "datacite" && r.present?)

  doc = Nokogiri::XML(string, nil, 'UTF-8', &:noblanks)
  node = doc.at_css("identifier")
  node.content = doi.to_s.upcase if node.present? && doi.present?
  doc.to_xml.strip
end


298
299
300
301
# File 'lib/bolognese/metadata_utils.rb', line 298

def related_identifier_hsh(relation_type)
  Array.wrap(send(relation_type)).select { |r| r["id"] || r["issn"] }
    .map { |r| r.merge("relationType" => relation_type.camelize) }
end

#should_passthruObject



94
95
96
# File 'lib/bolognese/metadata_utils.rb', line 94

def should_passthru
  (from == "datacite") && regenerate.blank? && raw.present?
end