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

#codemeta

Methods included from Writers::CffWriter

#cff, #write_cff_creators, #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::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::CodemetaReader

#get_codemeta, #read_codemeta

Methods included from Readers::CffReader

#cff_creators, #get_cff, #get_cff_reference, #read_cff

Methods included from Readers::BibtexReader

#read_bibtex

Methods included from Utils

#decode_doi, #encode_doi, #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_schema_org, #get_contributor, #get_date, #get_date_from_date_parts, #get_date_from_parts, #get_date_parts, #get_date_parts_from_parts, #get_dates_from_date, #get_datetime_from_iso8601, #get_datetime_from_time, #get_identifier, #get_identifier_type, #get_iso8601_date, #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, #jsonlint, #map_hash_keys, #name_to_fos, #name_to_spdx, #normalize_cc_url, #normalize_id, #normalize_issn, #normalize_licenses, #normalize_orcid, #normalize_url, #orcid_as_url, #orcid_from_url, #parse_attributes, #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, #validate_orcid, #validate_orcid_scheme, #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, #normalize_doi, #validate_doi, #validate_funder_doi, #validate_prefix

Methods included from CrossrefUtils

#crossref_errors, #crossref_root_attributes, #insert_citation_list, #insert_crossref_abstract, #insert_crossref_access_indicators, #insert_crossref_alternate_identifiers, #insert_crossref_creators, #insert_crossref_issn, #insert_crossref_language, #insert_crossref_license, #insert_crossref_person, #insert_crossref_publication_date, #insert_crossref_subjects, #insert_crossref_titles, #insert_crossref_work, #insert_doi_data, #insert_group_title, #insert_institution, #insert_journal, #insert_posted_content, #insert_posted_date, #write_crossref_xml

Methods included from AuthorUtils

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

Instance Attribute Details

#name_detector ⇒ Object (readonly)

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



99
100
101
# File 'lib/commonmeta/metadata_utils.rb', line 99

def name_detector
  @name_detector
end

#reverse ⇒ Object (readonly)

Returns the value of attribute reverse.



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

def reverse
  @reverse
end

Instance Method Details

#container_title ⇒ Object



90
91
92
93
94
95
96
# File 'lib/commonmeta/metadata_utils.rb', line 90

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

#csl_hsh ⇒ Object



132
133
134
135
136
137
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
# File 'lib/commonmeta/metadata_utils.rb', line 132

def csl_hsh
  page = if container.to_h['firstPage'].present?
           [container['firstPage'], container['lastPage']].compact.join('-')
         end
  author = if Array.wrap(creators).size == 1 && Array.wrap(creators).first.fetch('name',
                                                                                 nil) == ':(unav)'
             nil
           else
             to_csl(creators)
           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,
    'contributor' => to_csl(contributors),
    '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

#graph ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/commonmeta/metadata_utils.rb', line 120

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

#locale ⇒ Object



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

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

#raw ⇒ Object



79
80
81
82
83
84
# File 'lib/commonmeta/metadata_utils.rb', line 79

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

  r
end

#should_passthru ⇒ Object



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

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

#style ⇒ Object



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

def style
  @style ||= 'apa'
end