Class: Bolognese::Metadata

Direct Known Subclasses

Orcid

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, Readers::CrossrefReader::CR_TO_BIB_TRANSLATIONS, Readers::CrossrefReader::CR_TO_SO_TRANSLATIONS

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::CR_TO_CP_TRANSLATIONS, Utils::CR_TO_JATS_TRANSLATIONS, Utils::CR_TO_RIS_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, #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, #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, #resource_type, #root_attributes

Methods included from DateUtils

#get_date_from_parts, #get_date_parts, #get_date_parts_from_parts, #get_datetime_from_iso8601, #get_year_month, #get_year_month_day

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

Constructor Details

#initialize(input: nil, from: nil, style: nil, locale: nil, regenerate: false, **options) ⇒ Metadata

Returns a new instance of Metadata.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/bolognese/metadata.rb', line 83

def initialize(input: nil, from: nil, style: nil, locale: nil, regenerate: false, **options)
  id = normalize_id(input, options)

  if id.present?
    @from = from || find_from_format(id: id)

    # generate name for method to call dynamically
    hsh = @from.present? ? send("get_" + @from, id: id, sandbox: options[:sandbox]) : nil
    string = hsh.to_h.fetch("string", nil)
  elsif File.exist?(input)
    ext = File.extname(input)
    if %w(.bib .ris .xml .json).include?(ext)
      string = IO.read(input)
      @from = from || find_from_format(string: string, ext: ext)
    else
      $stderr.puts "File type #{ext} not supported"
      exit 1
    end
  else
    hsh = { "url" => options[:url],
            "state" => options[:state],
            "date_registered" => options[:date_registered],
            "date_updated" => options[:date_updated],
            "provider_id" => options[:provider_id],
            "client_id" => options[:client_id] }
    string = input
    @from = from || find_from_format(string: string)
  end

  # generate name for method to call dynamically
  @metadata = @from.present? ? send("read_" + @from, string: string, sandbox: options[:sandbox], doi: options[:doi], url: options[:url]) : {}
  @raw = string.present? ? string.strip : nil

  # replace DOI in XML if provided in options
  if @from == "datacite" && options[:doi].present?
    doc = Nokogiri::XML(string, nil, 'UTF-8', &:noblanks)
    node = doc.at_css("identifier")
    node.content = options[:doi].upcase
    @raw = doc.to_xml.strip
  end

  @should_passthru = (@from == "datacite") && !regenerate

  @url = hsh.to_h["url"].presence
  @state = hsh.to_h["state"].presence
  @date_registered = hsh.to_h["date_registered"].presence
  @date_updated = hsh.to_h["date_updated"].presence
  @provider_id = hsh.to_h["provider_id"].presence
  @client_id = hsh.to_h["client_id"].presence

  @style = style || "apa"
  @locale = locale || "en-US"
end

Instance Attribute Details

#additional_typeObject

Returns the value of attribute additional_type.



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

def additional_type
  @additional_type
end

#alternate_nameObject

Returns the value of attribute alternate_name.



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

def alternate_name
  @alternate_name
end

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#bibtex_typeObject

Returns the value of attribute bibtex_type.



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

def bibtex_type
  @bibtex_type
end

#citeproc_typeObject

Returns the value of attribute citeproc_type.



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

def citeproc_type
  @citeproc_type
end

#citesObject

Returns the value of attribute cites.



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

def cites
  @cites
end

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#compilesObject

Returns the value of attribute compiles.



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

def compiles
  @compiles
end

#content_sizeObject

Returns the value of attribute content_size.



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

def content_size
  @content_size
end

#continuesObject

Returns the value of attribute continues.



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

def continues
  @continues
end

#contributorObject

Returns the value of attribute contributor.



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

def contributor
  @contributor
end

#date_acceptedObject

Returns the value of attribute date_accepted.



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

def date_accepted
  @date_accepted
end

#date_availableObject

Returns the value of attribute date_available.



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

def date_available
  @date_available
end

#date_collectedObject

Returns the value of attribute date_collected.



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

def date_collected
  @date_collected
end

#date_copyrightedObject

Returns the value of attribute date_copyrighted.



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

def date_copyrighted
  @date_copyrighted
end

#date_createdObject

Returns the value of attribute date_created.



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

def date_created
  @date_created
end

#date_modifiedObject

Returns the value of attribute date_modified.



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

def date_modified
  @date_modified
end

#date_registeredObject

Returns the value of attribute date_registered.



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

def date_registered
  @date_registered
end

#date_submittedObject

Returns the value of attribute date_submitted.



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

def 
  @date_submitted
end

#date_updatedObject

Returns the value of attribute date_updated.



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

def date_updated
  @date_updated
end

#date_validObject

Returns the value of attribute date_valid.



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

def date_valid
  @date_valid
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#docObject (readonly)

Returns the value of attribute doc.



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

def doc
  @doc
end

#documentsObject

Returns the value of attribute documents.



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

def documents
  @documents
end

#doiObject

Returns the value of attribute doi.



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

def doi
  @doi
end

#editorObject

Returns the value of attribute editor.



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

def editor
  @editor
end

#errorsObject (readonly)

validate against DataCite schema, unless there are already errors in the reader



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

def errors
  @errors
end

#first_pageObject

Returns the value of attribute first_page.



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

def first_page
  @first_page
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#fromObject (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#fundingObject

Returns the value of attribute funding.



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

def funding
  @funding
end

#has_metadataObject

Returns the value of attribute has_metadata.



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

def 
  @has_metadata
end

#has_partObject

Returns the value of attribute has_part.



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

def has_part
  @has_part
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#is_cited_byObject

Returns the value of attribute is_cited_by.



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

def is_cited_by
  @is_cited_by
end

#is_compiled_byObject

Returns the value of attribute is_compiled_by.



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

def is_compiled_by
  @is_compiled_by
end

#is_continued_byObject

Returns the value of attribute is_continued_by.



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

def is_continued_by
  @is_continued_by
end

#is_derived_fromObject

Returns the value of attribute is_derived_from.



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

def is_derived_from
  @is_derived_from
end

#is_documented_byObject

Returns the value of attribute is_documented_by.



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

def is_documented_by
  @is_documented_by
end

#is_metadata_forObject

Returns the value of attribute is_metadata_for.



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

def 
  @is_metadata_for
end

#is_new_version_ofObject

Returns the value of attribute is_new_version_of.



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

def is_new_version_of
  @is_new_version_of
end

#is_original_form_ofObject

Returns the value of attribute is_original_form_of.



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

def is_original_form_of
  @is_original_form_of
end

#is_previous_version_ofObject

Returns the value of attribute is_previous_version_of.



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

def is_previous_version_of
  @is_previous_version_of
end

#is_referenced_byObject

Returns the value of attribute is_referenced_by.



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

def is_referenced_by
  @is_referenced_by
end

#is_reviewed_byObject

Returns the value of attribute is_reviewed_by.



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

def is_reviewed_by
  @is_reviewed_by
end

#is_source_ofObject

Returns the value of attribute is_source_of.



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

def is_source_of
  @is_source_of
end

#is_supplement_toObject

Returns the value of attribute is_supplement_to.



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

def is_supplement_to
  @is_supplement_to
end

#is_supplemented_byObject

Returns the value of attribute is_supplemented_by.



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

def is_supplemented_by
  @is_supplemented_by
end

#is_variant_form_ofObject

Returns the value of attribute is_variant_form_of.



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

def is_variant_form_of
  @is_variant_form_of
end

#issueObject

Returns the value of attribute issue.



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

def issue
  @issue
end

#journalObject

Returns the value of attribute journal.



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

def journal
  @journal
end

#keywordsObject

Returns the value of attribute keywords.



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

def keywords
  @keywords
end

#languageObject

Returns the value of attribute language.



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

def language
  @language
end

#last_pageObject

Returns the value of attribute last_page.



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

def last_page
  @last_page
end

#licenseObject

Returns the value of attribute license.



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

def license
  @license
end

#localeObject

Returns the value of attribute locale.



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

def locale
  @locale
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  @metadata
end

#name_detectorObject (readonly)

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



375
376
377
# File 'lib/bolognese/metadata.rb', line 375

def name_detector
  @name_detector
end

#page_endObject (readonly)

Returns the value of attribute page_end.



79
80
81
# File 'lib/bolognese/metadata.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.rb', line 79

def page_start
  @page_start
end

#providerObject (readonly)

Returns the value of attribute provider.



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

def provider
  @provider
end

#provider_idObject

Returns the value of attribute provider_id.



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

def provider_id
  @provider_id
end

#publisherObject

Returns the value of attribute publisher.



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

def publisher
  @publisher
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#referencesObject

Returns the value of attribute references.



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

def references
  @references
end

Returns the value of attribute related_identifier.



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

def related_identifier
  @related_identifier
end

#reverseObject (readonly)

Returns the value of attribute reverse.



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

def reverse
  @reverse
end

#reviewsObject

Returns the value of attribute reviews.



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

def reviews
  @reviews
end

#ris_typeObject

Returns the value of attribute ris_type.



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

def ris_type
  @ris_type
end

#same_asObject

Returns the value of attribute same_as.



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

def same_as
  @same_as
end

#schema_versionObject

Returns the value of attribute schema_version.



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

def schema_version
  @schema_version
end

#should_passthruObject (readonly)

Returns the value of attribute should_passthru.



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

def should_passthru
  @should_passthru
end

#spatial_coverageObject

Returns the value of attribute spatial_coverage.



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

def spatial_coverage
  @spatial_coverage
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#styleObject

Returns the value of attribute style.



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

def style
  @style
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

#volumeObject

Returns the value of attribute volume.



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

def volume
  @volume
end

Instance Method Details

#container_titleObject



383
384
385
# File 'lib/bolognese/metadata.rb', line 383

def container_title
  Array.wrap(is_part_of).length == 1 ? is_part_of.to_h.fetch("title", nil) : nil
end

#date_publishedObject



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

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

#descriptionsObject



387
388
389
# File 'lib/bolognese/metadata.rb', line 387

def descriptions
  Array.wrap(description)
end

#exists?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/bolognese/metadata.rb', line 137

def exists?
  .fetch("id", nil).present?
end

#graphObject



396
397
398
# File 'lib/bolognese/metadata.rb', line 396

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

#is_identical_toObject



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

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

#is_part_ofObject



316
317
318
# File 'lib/bolognese/metadata.rb', line 316

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

#publication_yearObject



379
380
381
# File 'lib/bolognese/metadata.rb', line 379

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


364
365
366
367
# File 'lib/bolognese/metadata.rb', line 364

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

#resource_type_generalObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/bolognese/metadata.rb', line 141

def valid?
  exists? && errors.nil?
end