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_name, #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, #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



100
101
102
# File 'lib/bolognese/metadata_utils.rb', line 100

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

#alternate_nameObject



132
133
134
# File 'lib/bolognese/metadata_utils.rb', line 132

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

#authorObject



136
137
138
# File 'lib/bolognese/metadata_utils.rb', line 136

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

#b_urlObject



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

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

#b_versionObject



302
303
304
# File 'lib/bolognese/metadata_utils.rb', line 302

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

#bibtex_typeObject



108
109
110
# File 'lib/bolognese/metadata_utils.rb', line 108

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

#citeproc_typeObject



104
105
106
# File 'lib/bolognese/metadata_utils.rb', line 104

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.



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

def cites=(value)
  @cites = value
end

#compiles=(value) ⇒ Object (writeonly)

Sets the attribute compiles

Parameters:

  • value

    the value to set the attribute compiles to.



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

def compiles=(value)
  @compiles = value
end

#content_sizeObject



224
225
226
# File 'lib/bolognese/metadata_utils.rb', line 224

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

#continues=(value) ⇒ Object (writeonly)

Sets the attribute continues

Parameters:

  • value

    the value to set the attribute continues to.



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

def continues=(value)
  @continues = value
end

#contributorObject

Returns the value of attribute contributor.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def contributor
  @contributor
end

#date_acceptedObject



156
157
158
# File 'lib/bolognese/metadata_utils.rb', line 156

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

#date_availableObject



160
161
162
# File 'lib/bolognese/metadata_utils.rb', line 160

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

#date_collectedObject



168
169
170
# File 'lib/bolognese/metadata_utils.rb', line 168

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

#date_copyrightedObject



164
165
166
# File 'lib/bolognese/metadata_utils.rb', line 164

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

#date_createdObject



152
153
154
# File 'lib/bolognese/metadata_utils.rb', line 152

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

#date_modifiedObject



184
185
186
# File 'lib/bolognese/metadata_utils.rb', line 184

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

#date_publishedObject



180
181
182
# File 'lib/bolognese/metadata_utils.rb', line 180

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

#date_submittedObject



172
173
174
# File 'lib/bolognese/metadata_utils.rb', line 172

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

#date_updatedObject



192
193
194
# File 'lib/bolognese/metadata_utils.rb', line 192

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

#date_validObject



176
177
178
# File 'lib/bolognese/metadata_utils.rb', line 176

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

#descriptionObject



208
209
210
# File 'lib/bolognese/metadata_utils.rb', line 208

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

#docObject (readonly)

Returns the value of attribute doc.



79
80
81
# File 'lib/bolognese/metadata_utils.rb', line 79

def doc
  @doc
end

#documents=(value) ⇒ Object (writeonly)

Sets the attribute documents

Parameters:

  • value

    the value to set the attribute documents to.



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

def documents=(value)
  @documents = value
end

#editorObject



140
141
142
# File 'lib/bolognese/metadata_utils.rb', line 140

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

#first_pageObject



200
201
202
# File 'lib/bolognese/metadata_utils.rb', line 200

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.



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

def format=(value)
  @format = value
end

#fromObject

Returns the value of attribute from.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def from
  @from
end

#fundingObject



232
233
234
# File 'lib/bolognese/metadata_utils.rb', line 232

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.



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

def has_metadata=(value)
  @has_metadata = value
end

#has_partObject



244
245
246
# File 'lib/bolognese/metadata_utils.rb', line 244

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

#identifierObject



120
121
122
# File 'lib/bolognese/metadata_utils.rb', line 120

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

def (value)
  @is_metadata_for = value
end

#is_new_version_ofObject



252
253
254
# File 'lib/bolognese/metadata_utils.rb', line 252

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

#is_original_form_ofObject



260
261
262
# File 'lib/bolognese/metadata_utils.rb', line 260

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

#is_previous_version_ofObject



248
249
250
# File 'lib/bolognese/metadata_utils.rb', line 248

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

#is_referenced_byObject



268
269
270
# File 'lib/bolognese/metadata_utils.rb', line 268

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

#is_reviewed_byObject



284
285
286
# File 'lib/bolognese/metadata_utils.rb', line 284

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.



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

def is_source_of=(value)
  @is_source_of = value
end

#is_supplement_toObject



272
273
274
# File 'lib/bolognese/metadata_utils.rb', line 272

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

#is_supplemented_byObject



276
277
278
# File 'lib/bolognese/metadata_utils.rb', line 276

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

#is_variant_form_ofObject



256
257
258
# File 'lib/bolognese/metadata_utils.rb', line 256

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

#issueObject

Returns the value of attribute issue.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def issue
  @issue
end

#journal=(value) ⇒ Object (writeonly)

Sets the attribute journal

Parameters:

  • value

    the value to set the attribute journal to.



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

def journal=(value)
  @journal = value
end

#keywordsObject



216
217
218
# File 'lib/bolognese/metadata_utils.rb', line 216

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

#languageObject



220
221
222
# File 'lib/bolognese/metadata_utils.rb', line 220

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

#last_pageObject



204
205
206
# File 'lib/bolognese/metadata_utils.rb', line 204

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

#licenseObject



212
213
214
# File 'lib/bolognese/metadata_utils.rb', line 212

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

#localeObject



336
337
338
# File 'lib/bolognese/metadata_utils.rb', line 336

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

#metaObject

Returns the value of attribute meta.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def meta
  @meta
end

#name_detectorObject (readonly)

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



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

def name_detector
  @name_detector
end

#page_endObject (readonly)

Returns the value of attribute page_end.



79
80
81
# File 'lib/bolognese/metadata_utils.rb', line 79

def page_end
  @page_end
end

#page_startObject (readonly)

Returns the value of attribute page_start.



79
80
81
# File 'lib/bolognese/metadata_utils.rb', line 79

def page_start
  @page_start
end

#publisherObject



144
145
146
# File 'lib/bolognese/metadata_utils.rb', line 144

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

#referencesObject



264
265
266
# File 'lib/bolognese/metadata_utils.rb', line 264

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

#regenerateObject

Returns the value of attribute regenerate.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def regenerate
  @regenerate
end

Returns the value of attribute related_identifier.



79
80
81
# File 'lib/bolognese/metadata_utils.rb', line 79

def related_identifier
  @related_identifier
end

#resource_type_generalObject



116
117
118
# File 'lib/bolognese/metadata_utils.rb', line 116

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

#reverseObject (readonly)

Returns the value of attribute reverse.



79
80
81
# File 'lib/bolognese/metadata_utils.rb', line 79

def reverse
  @reverse
end

#reviewsObject



280
281
282
# File 'lib/bolognese/metadata_utils.rb', line 280

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

#ris_typeObject



112
113
114
# File 'lib/bolognese/metadata_utils.rb', line 112

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.



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

def same_as=(value)
  @same_as = value
end

#sandboxObject

Returns the value of attribute sandbox.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def sandbox
  @sandbox
end

#schema_versionObject



228
229
230
# File 'lib/bolognese/metadata_utils.rb', line 228

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

#service_providerObject (readonly)

Returns the value of attribute service_provider.



79
80
81
# File 'lib/bolognese/metadata_utils.rb', line 79

def service_provider
  @service_provider
end

#spatial_coverageObject

Returns the value of attribute spatial_coverage.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def spatial_coverage
  @spatial_coverage
end

#stateObject



124
125
126
# File 'lib/bolognese/metadata_utils.rb', line 124

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

#stringObject

Returns the value of attribute string.



62
63
64
# File 'lib/bolognese/metadata_utils.rb', line 62

def string
  @string
end

#styleObject



332
333
334
# File 'lib/bolognese/metadata_utils.rb', line 332

def style
  @style ||= "apa"
end

#titleObject



128
129
130
# File 'lib/bolognese/metadata_utils.rb', line 128

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

#typeObject



96
97
98
# File 'lib/bolognese/metadata_utils.rb', line 96

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

#volumeObject



196
197
198
# File 'lib/bolognese/metadata_utils.rb', line 196

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

Instance Method Details

#container_titleObject



315
316
317
# File 'lib/bolognese/metadata_utils.rb', line 315

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

#date_registeredObject



188
189
190
# File 'lib/bolognese/metadata_utils.rb', line 188

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

#descriptionsObject



319
320
321
# File 'lib/bolognese/metadata_utils.rb', line 319

def descriptions
  Array.wrap(description)
end

#graphObject



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

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

#is_identical_toObject



236
237
238
# File 'lib/bolognese/metadata_utils.rb', line 236

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

#is_part_ofObject



240
241
242
# File 'lib/bolognese/metadata_utils.rb', line 240

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

#publication_yearObject



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

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

#rawObject

replace DOI in XML if provided in options



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

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


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

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



92
93
94
# File 'lib/bolognese/metadata_utils.rb', line 92

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