Module: Commonmeta::MetadataUtils

Constant Summary

Constants included from Readers::SchemaOrgReader

Readers::SchemaOrgReader::SO_TO_DC_RELATION_TYPES, Readers::SchemaOrgReader::SO_TO_DC_REVERSE_RELATION_TYPES

Constants included from Utils

Utils::BIB_TO_CM_TRANSLATIONS, Utils::CM_TO_BIB_TRANSLATIONS, Utils::CM_TO_CR_TRANSLATIONS, Utils::CM_TO_CSL_TRANSLATIONS, Utils::CM_TO_DC_TRANSLATIONS, Utils::CM_TO_JATS_TRANSLATIONS, Utils::CM_TO_RIS_TRANSLATIONS, Utils::CM_TO_SO_TRANSLATIONS, Utils::CR_TO_CM_TRANSLATIONS, Utils::CSL_TO_CM_TRANSLATIONS, Utils::DC_TO_CM_TRANSLATIONS, Utils::NORMALIZED_LICENSES, Utils::RIS_TO_CM_TRANSLATIONS, Utils::SO_TO_CM_TRANSLATIONS, Utils::UNKNOWN_INFORMATION

Constants included from SchemaUtils

SchemaUtils::COMMONMETA

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::DataciteWriter

#datacite, #datacite_contributor, #datacite_reference

Methods included from Writers::CsvWriter

#csv

Methods included from Writers::CslWriter

#csl

Methods included from Writers::CrossrefXmlWriter

#crossref_xml

Methods included from Writers::CommonmetaWriter

#commonmeta

Methods included from Writers::CodemetaWriter

#codemeta

Methods included from Writers::CffWriter

#cff, #write_cff_contributors, #write_cff_reference

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_reference, #schema_org_references

Methods included from Readers::RisReader

#read_ris, #ris_meta

Methods included from Readers::NpmReader

#get_npm, #read_npm

Methods included from Readers::JsonFeedReader

#get_doi_prefix_by_blog_slug, #get_doi_prefix_by_json_feed_item_id, #get_files, #get_funding_references, #get_json_feed_blog_slug, #get_json_feed_by_blog, #get_json_feed_item, #get_json_feed_unregistered, #get_json_feed_updated, #get_references, #get_related_identifiers, #read_json_feed_item

Methods included from Readers::DataciteReader

#format_contributor, #get_datacite, #get_datacite_reference, #read_datacite

Methods included from Readers::CslReader

#read_csl

Methods included from Readers::CrossrefXmlReader

#crossref_alternate_identifiers, #crossref_date_published, #crossref_description, #crossref_funding_reference, #crossref_license, #crossref_people, #crossref_references, #get_crossref_xml, #read_crossref_xml

Methods included from Readers::CrossrefReader

#get_crossref, #get_reference, #read_crossref

Methods included from Readers::CommonmetaReader

#read_commonmeta

Methods included from Readers::CodemetaReader

#get_codemeta, #read_codemeta

Methods included from Readers::CffReader

#cff_contributors, #get_cff, #get_cff_reference, #read_cff

Methods included from Readers::BibtexReader

#read_bibtex

Methods included from Utils

#decode_container_id, #decode_doi, #encode_container_id, #encode_doi, #encode_doi_for_id, #find_from_format, #find_from_format_by_ext, #find_from_format_by_filename, #find_from_format_by_id, #find_from_format_by_string, #from_csl, #from_datacite, #from_json_feed, #from_schema_org, #generate_ghost_token, #get_contributor, #get_date, #get_date_from_date_parts, #get_date_from_parts, #get_date_from_unix_timestamp, #get_date_parts, #get_date_parts_from_parts, #get_dates_from_date, #get_datetime_from_iso8601, #get_datetime_from_time, #get_datetime_from_unix_timestamp, #get_identifier, #get_identifier_type, #get_iso8601_date, #get_link, #get_series_information, #get_year_month, #get_year_month_day, #github_as_cff_url, #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, #hsh_to_fos, #hsh_to_spdx, #json_feed_by_blog_url, #json_feed_item_by_id_url, #json_feed_unregistered_url, #json_feed_updated_url, #jsonlint, #map_hash_keys, #name_to_fos, #name_to_spdx, #normalize_cc_url, #normalize_id, #normalize_isni, #normalize_issn, #normalize_licenses, #normalize_name_identifier, #normalize_orcid, #normalize_ror, #normalize_url, #orcid_as_url, #orcid_from_url, #parse_attributes, #rogue_scholar_api_url, #sanitize, #spdx_to_hsh, #strip_milliseconds, #to_csl, #to_datacite, #to_identifier, #to_ris, #to_schema_org, #to_schema_org_citation, #to_schema_org_container, #to_schema_org_funder, #to_schema_org_identifiers, #to_schema_org_relation, #to_schema_org_spatial_coverage, #update_ghost_post_via_api, #validate_email, #validate_isni, #validate_orcid, #validate_orcid_scheme, #validate_ror, #validate_url

Methods included from SchemaUtils

#json_schema_errors

Methods included from DoiUtils

#crossref_api_url, #datacite_api_url, #doi_as_url, #doi_from_url, #doi_resolver, #get_crossref_member, #get_doi_ra, #is_rogue_scholar_doi?, #normalize_doi, #validate_doi, #validate_funder_doi, #validate_prefix

Methods included from CrossrefUtils

#crossref_errors, #crossref_root_attributes, #insert_archive_locations, #insert_citation_list, #insert_crossref_abstract, #insert_crossref_access_indicators, #insert_crossref_anonymous, #insert_crossref_contributors, #insert_crossref_issn, #insert_crossref_language, #insert_crossref_license, #insert_crossref_person, #insert_crossref_publication_date, #insert_crossref_relations, #insert_crossref_subjects, #insert_crossref_titles, #insert_crossref_work, #insert_doi_data, #insert_funding_references, #insert_group_title, #insert_institution, #insert_item_number, #insert_journal, #insert_posted_content, #insert_posted_date, #write_crossref_xml

Methods included from AuthorUtils

#author_name_identifiers, #authors_as_string, #cleanup_author, #datacite_contributor_roles, #get_affiliations, #get_authors, #get_one_author, #is_personal_name?, #name_exists?

Instance Attribute Details

#name_detectorObject (readonly)

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



105
106
107
# File 'lib/commonmeta/metadata_utils.rb', line 105

def name_detector
  @name_detector
end

#reverseObject (readonly)

Returns the value of attribute reverse.



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

def reverse
  @reverse
end

Instance Method Details

#container_titleObject



96
97
98
99
100
101
102
# File 'lib/commonmeta/metadata_utils.rb', line 96

def container_title
  if container.present?
    container['title']
  elsif type == 'Article'
    publisher['name']
  end
end

#csl_hshObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/commonmeta/metadata_utils.rb', line 138

def csl_hsh
  authors = Array.wrap(contributors).select { |c| c['contributorRoles'] == ['Author'] }
  
  page = if container.to_h['firstPage'].present?
           [container['firstPage'], container['lastPage']].compact.join('-')
         end
  author = if Array.wrap(authors).size == 1 && Array.wrap(authors).first.fetch('name',
                                                                                 nil) == ':(unav)'
             nil
           else
             to_csl(authors)
           end

  type_ = if type == 'Software' && version.present?
            'book'
          else
            CM_TO_CSL_TRANSLATIONS.fetch(type, 'document')
          end

  categories = Array.wrap(subjects).map do |k|
    parse_attributes(k, content: 'subject', first: true)
  end.presence

  {
    'type' => type_,
    'id' => id,
    'categories' => categories,
    'language' => language,
    'author' => author,
    'issued' => get_date_parts(date['published']),
    'submitted' => date['submitted'] ? get_date_parts(date['submitted']) : nil,
    'abstract' => parse_attributes(descriptions, content: 'description', first: true),
    'container-title' => container_title,
    'DOI' => doi_from_url(id),
    'volume' => container.to_h['volume'],
    'issue' => container.to_h['issue'],
    'page' => page,
    'publisher' => publisher['name'],
    'title' => parse_attributes(titles, content: 'title', first: true),
    'URL' => url,
    'copyright' => license.to_h['id'],
    'version' => version
  }.compact.symbolize_keys
end

#graphObject



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/commonmeta/metadata_utils.rb', line 126

def graph
  # preload schema_org context
  JSON::LD::Context.add_preloaded(
    'http://schema.org/',
    JSON::LD::Context.new.parse('resources/schema_org/jsonldcontext.json')
  )

  RDF::Graph.new << JSON::LD::API.toRdf(schema_hsh)
rescue NameError
  nil
end

#localeObject



187
188
189
# File 'lib/commonmeta/metadata_utils.rb', line 187

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

#rawObject



85
86
87
88
89
90
# File 'lib/commonmeta/metadata_utils.rb', line 85

def raw
  r = string.present? ? string.strip : nil
  return r unless from == 'crossref_xml' && r.present?

  r
end

#should_passthruObject



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

def should_passthru
  (from == 'crossref_xml') && regenerate.blank? && raw.present?
end

#styleObject



183
184
185
# File 'lib/commonmeta/metadata_utils.rb', line 183

def style
  @style ||= 'apa'
end