Module: Briard::MetadataUtils
- Includes:
- AuthorUtils, CrossrefUtils, DataciteUtils, DoiUtils, Readers::BibtexReader, Readers::CffReader, Readers::CiteprocReader, Readers::CodemetaReader, Readers::CrossciteReader, Readers::CrossrefJsonReader, Readers::CrossrefReader, Readers::DataciteJsonReader, Readers::DataciteReader, Readers::NpmReader, Readers::RisReader, Readers::SchemaOrgReader, SchemaUtils, Utils, Writers::BibtexWriter, Writers::CffWriter, Writers::CitationWriter, Writers::CiteprocWriter, Writers::CodemetaWriter, Writers::CrossciteWriter, Writers::CrossrefWriter, Writers::CsvWriter, Writers::DataciteJsonWriter, Writers::DataciteWriter, Writers::JatsWriter, Writers::RdfXmlWriter, Writers::RisWriter, Writers::SchemaOrgWriter, Writers::TurtleWriter
- Included in:
- Metadata
- Defined in:
- lib/briard/metadata_utils.rb
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 Readers::RisReader
Readers::RisReader::RIS_TO_BIB_TRANSLATIONS, Readers::RisReader::RIS_TO_CP_TRANSLATIONS, Readers::RisReader::RIS_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::BIB_TO_CR_TRANSLATIONS, Utils::BIB_TO_DC_TRANSLATIONS, Utils::CP_TO_DC_TRANSLATIONS, Utils::CR_TO_BIB_TRANSLATIONS, Utils::CR_TO_CP_TRANSLATIONS, Utils::CR_TO_DC_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::NORMALIZED_LICENSES, Utils::RIS_TO_DC_TRANSLATIONS, 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, Utils::UNKNOWN_INFORMATION
Constants included from SchemaUtils
Constants included from AuthorUtils
AuthorUtils::IDENTIFIER_SCHEME_URIS
Instance Attribute Summary collapse
-
#name_detector ⇒ Object
readonly
recognize given name.
-
#reverse ⇒ Object
readonly
Returns the value of attribute reverse.
Instance Method Summary collapse
- #citeproc_hsh ⇒ Object
- #container_title ⇒ Object
- #crosscite_hsh ⇒ Object
- #graph ⇒ Object
- #locale ⇒ Object
-
#raw ⇒ Object
replace DOI in XML if provided in options.
- #should_passthru ⇒ Object
- #style ⇒ Object
Methods included from Writers::TurtleWriter
Methods included from Writers::SchemaOrgWriter
Methods included from Writers::RisWriter
Methods included from Writers::RdfXmlWriter
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
Methods included from Writers::DataciteWriter
Methods included from Writers::CsvWriter
Methods included from Writers::CrossrefWriter
Methods included from Writers::CrossciteWriter
Methods included from Writers::CodemetaWriter
Methods included from Writers::CffWriter
#cff, #write_cff_creators, #write_references
Methods included from Writers::CiteprocWriter
Methods included from Writers::CitationWriter
Methods included from Writers::BibtexWriter
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
Methods included from Readers::NpmReader
Methods included from Readers::DataciteJsonReader
Methods included from Readers::DataciteReader
#get_datacite, #get_titles, #read_datacite, #set_container
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::CrossrefJsonReader
#get_crossref_json, #read_crossref_json
Methods included from Readers::CrossciteReader
Methods included from Readers::CodemetaReader
Methods included from Readers::CffReader
#cff_creators, #cff_references, #get_cff, #read_cff
Methods included from Readers::CiteprocReader
Methods included from Readers::BibtexReader
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_citeproc, #from_datacite_json, #from_schema_org, #from_schema_org_contributors, #from_schema_org_creators, #get_contributor, #get_date, #get_date_from_date_parts, #get_date_from_parts, #get_date_parts, #get_date_parts_from_parts, #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_ids, #normalize_issn, #normalize_licenses, #normalize_orcid, #normalize_url, #orcid_as_url, #orcid_from_url, #parse_attributes, #sanitize, #strip_milliseconds, #to_citeproc, #to_datacite_json, #to_identifier, #to_ris, #to_schema_org, #to_schema_org_container, #to_schema_org_contributors, #to_schema_org_creators, #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
Methods included from DataciteUtils
#datacite_errors, #datacite_xml, #insert_alternate_identifiers, #insert_contributors, #insert_creators, #insert_dates, #insert_descriptions, #insert_formats, #insert_funding_references, #insert_geo_locations, #insert_identifier, #insert_language, #insert_person, #insert_publication_year, #insert_publisher, #insert_related_identifiers, #insert_related_items, #insert_resource_type, #insert_rights_list, #insert_sizes, #insert_subjects, #insert_titles, #insert_version, #insert_work, #root_attributes
Methods included from CrossrefUtils
#crossref_errors, #crossref_root_attributes, #crossref_xml, #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_person, #insert_crossref_publication_date, #insert_crossref_rights_list, #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
Methods included from AuthorUtils
#authors_as_string, #cleanup_author, #get_affiliations, #get_authors, #get_one_author, #is_personal_name?, #name_exists?
Methods included from DoiUtils
#crossref_api_url, #datacite_api_url, #doi_as_url, #doi_from_url, #doi_resolver, #get_doi_ra, #normalize_doi, #validate_doi, #validate_funder_doi, #validate_prefix
Instance Attribute Details
#name_detector ⇒ Object (readonly)
recognize given name. Can be loaded once as ::NameDetector, e.g. in a Rails initializer
114 115 116 |
# File 'lib/briard/metadata_utils.rb', line 114 def name_detector @name_detector end |
#reverse ⇒ Object (readonly)
Returns the value of attribute reverse.
78 79 80 |
# File 'lib/briard/metadata_utils.rb', line 78 def reverse @reverse end |
Instance Method Details
#citeproc_hsh ⇒ Object
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 182 183 184 185 186 187 188 189 |
# File 'lib/briard/metadata_utils.rb', line 147 def citeproc_hsh page = if container.to_h['firstPage'].present? [container['firstPage'], container['lastPage']].compact.join('-') end = if Array.wrap(creators).size == 1 && Array.wrap(creators).first.fetch('name', nil) == ':(unav)' nil else to_citeproc(creators) end type = if types['resourceTypeGeneral'] == 'Software' && version_info.present? 'book' else types['citeproc'] end { 'type' => type, 'id' => normalize_doi(doi), 'categories' => Array.wrap(subjects).map do |k| parse_attributes(k, content: 'subject', first: true) end.presence, 'language' => language, 'author' => , 'contributor' => to_citeproc(contributors), 'issued' => get_date_parts(get_date(dates, 'Issued') || publication_year.to_s), 'submitted' => Array.wrap(dates).find do |d| d['dateType'] == 'Submitted' end.to_h.fetch('__content__', nil), 'abstract' => parse_attributes(descriptions, content: 'description', first: true), 'container-title' => container_title, 'DOI' => doi, 'volume' => container.to_h['volume'], 'issue' => container.to_h['issue'], 'page' => page, 'publisher' => publisher, 'title' => parse_attributes(titles, content: 'title', first: true), 'URL' => url, 'copyright' => Array.wrap(rights_list).map { |l| l['rights'] }.first, 'version' => version_info }.compact.symbolize_keys end |
#container_title ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/briard/metadata_utils.rb', line 105 def container_title if container.present? container['title'] elsif types['citeproc'] == 'article-journal' publisher end end |
#crosscite_hsh ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/briard/metadata_utils.rb', line 191 def crosscite_hsh { 'id' => normalize_doi(doi), 'doi' => doi, 'url' => url, 'types' => types, 'creators' => creators, 'titles' => titles, 'publisher' => publisher, 'container' => container, 'subjects' => subjects, 'contributors' => contributors, 'dates' => dates, 'publication_year' => publication_year, 'language' => language, 'identifiers' => identifiers, 'sizes' => sizes, 'formats' => formats, 'version' => version_info, 'rights_list' => rights_list, 'descriptions' => descriptions, 'geo_locations' => geo_locations, 'funding_references' => funding_references, 'related_identifiers' => , 'related_items' => , 'schema_version' => schema_version, 'provider_id' => provider_id, 'client_id' => client_id, 'agency' => agency, 'state' => state }.compact end |
#graph ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/briard/metadata_utils.rb', line 135 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
228 229 230 |
# File 'lib/briard/metadata_utils.rb', line 228 def locale @locale ||= 'en-US' end |
#raw ⇒ Object
replace DOI in XML if provided in options
91 92 93 94 95 96 97 98 99 |
# File 'lib/briard/metadata_utils.rb', line 91 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_passthru ⇒ Object
101 102 103 |
# File 'lib/briard/metadata_utils.rb', line 101 def should_passthru (from == 'datacite') && regenerate.blank? && raw.present? end |
#style ⇒ Object
224 225 226 |
# File 'lib/briard/metadata_utils.rb', line 224 def style @style ||= 'apa' end |