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, #get_datacite, #read_datacite, #set_periodical

Methods included from Readers::CrossrefReader

#crossref_alternate_identifiers, #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_identifier, #to_ris, #to_schema_org, #to_schema_org_container, #to_schema_org_funder, #to_schema_org_identifier, #to_schema_org_relation, #to_schema_org_spatial_coverage, #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, #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



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

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

#alternate_identifiersObject



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

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

#b_formatObject



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

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

#b_urlObject



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

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

#b_versionObject



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

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

#bibtex_typeObject



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

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

#citeproc_typeObject



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

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

#content_urlObject



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

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

#contributorObject

Returns the value of attribute contributor.



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

def contributor
  @contributor
end

#creatorObject



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

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

#date_modifiedObject



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

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

#date_publishedObject



154
155
156
# File 'lib/bolognese/metadata_utils.rb', line 154

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

#date_updatedObject



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

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

#datesObject



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

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

#descriptionObject



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

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

#docObject (readonly)

Returns the value of attribute doc.



73
74
75
# File 'lib/bolognese/metadata_utils.rb', line 73

def doc
  @doc
end

#editorObject



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

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

#first_pageObject



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

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.



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

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

#funding_referencesObject



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

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

#geo_locationObject



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

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

#identifierObject



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

def identifier
  @identifier ||= meta.fetch("id", 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.



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

def journal=(value)
  @journal = value
end

#keywordsObject



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

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

#languageObject



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

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

#last_pageObject



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

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

#localeObject



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

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



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

def name_detector
  @name_detector
end

#page_endObject (readonly)

Returns the value of attribute page_end.



73
74
75
# File 'lib/bolognese/metadata_utils.rb', line 73

def page_end
  @page_end
end

#page_startObject (readonly)

Returns the value of attribute page_start.



73
74
75
# File 'lib/bolognese/metadata_utils.rb', line 73

def page_start
  @page_start
end

#periodicalObject



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

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

#publisherObject



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

def publisher
  @publisher ||= meta.fetch("publisher", 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.



73
74
75
# File 'lib/bolognese/metadata_utils.rb', line 73

def related_identifier
  @related_identifier
end


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

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

#resource_type_generalObject



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

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

#reverseObject (readonly)

Returns the value of attribute reverse.



73
74
75
# File 'lib/bolognese/metadata_utils.rb', line 73

def reverse
  @reverse
end

#rightsObject



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

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

#ris_typeObject



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

def ris_type
  @ris_type ||= meta.fetch("ris_type", nil)
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



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

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

#service_providerObject (readonly)

Returns the value of attribute service_provider.



73
74
75
# File 'lib/bolognese/metadata_utils.rb', line 73

def service_provider
  @service_provider
end

#sizeObject



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

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

#stateObject



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

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



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

def style
  @style ||= "apa"
end

#titleObject



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

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

#typeObject



90
91
92
# File 'lib/bolognese/metadata_utils.rb', line 90

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

#volumeObject



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

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

Instance Method Details

#citeproc_hshObject



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/bolognese/metadata_utils.rb', line 260

def citeproc_hsh
  {
    "type" => citeproc_type,
    "id" => identifier,
    "categories" => Array.wrap(keywords).map { |k| parse_attributes(k, content: "text", first: true) }.presence,
    "language" => language,
    "author" => to_citeproc(creator),
    "editor" => to_citeproc(editor),
    "issued" => date_published ? get_date_parts(date_published) : nil,
    "submitted" => Array.wrap(dates).find { |d| d["type"] == "Submitted" }.to_h.fetch("__content__", nil),
    "abstract" => parse_attributes(description, content: "text", first: true),
    "container-title" => periodical && periodical["title"],
    "DOI" => doi,
    "issue" => issue,
    "page" => [first_page, last_page].compact.join("-").presence,
    "publisher" => publisher,
    "title" => parse_attributes(title, content: "text", first: true),
    "URL" => b_url,
    "version" => b_version,
    "volume" => volume
  }.compact.symbolize_keys
end

#descriptionsObject



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

def descriptions
  Array.wrap(description)
end

#graphObject



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

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

#publication_yearObject



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

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

#rawObject

replace DOI in XML if provided in options



76
77
78
79
80
81
82
83
84
# File 'lib/bolognese/metadata_utils.rb', line 76

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

#should_passthruObject



86
87
88
# File 'lib/bolognese/metadata_utils.rb', line 86

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