Module: Bolognese::MetadataUtils
- Includes:
- AuthorUtils, DataciteUtils, DoiUtils, Readers::BibtexReader, Readers::CiteprocReader, Readers::CodemetaReader, Readers::CrossciteReader, Readers::CrossrefReader, Readers::DataciteJsonReader, Readers::DataciteReader, Readers::RisReader, Readers::SchemaOrgReader, Utils, Writers::BibtexWriter, Writers::CitationWriter, Writers::CiteprocWriter, Writers::CodemetaWriter, Writers::CrossciteWriter, Writers::CrossrefWriter, Writers::DataciteJsonWriter, Writers::DataciteWriter, Writers::JatsWriter, Writers::RdfXmlWriter, Writers::RisWriter, Writers::SchemaOrgWriter, Writers::TurtleWriter
- Included in:
- Metadata
- Defined in:
- lib/bolognese/metadata_utils.rb
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
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#from ⇒ Object
Returns the value of attribute from.
-
#issue ⇒ Object
Returns the value of attribute issue.
- #locale ⇒ Object
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#name_detector ⇒ Object
readonly
recognize given name.
-
#page_end ⇒ Object
readonly
Returns the value of attribute page_end.
-
#page_start ⇒ Object
readonly
Returns the value of attribute page_start.
-
#regenerate ⇒ Object
Returns the value of attribute regenerate.
-
#reverse ⇒ Object
readonly
Returns the value of attribute reverse.
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
-
#string ⇒ Object
Returns the value of attribute string.
- #style ⇒ Object
Instance Method Summary collapse
- #citeproc_hsh ⇒ Object
- #first_page ⇒ Object
- #graph ⇒ Object
- #last_page ⇒ Object
-
#raw ⇒ Object
replace DOI in XML if provided in options.
- #should_passthru ⇒ Object
- #volume ⇒ 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::CrossrefWriter
Methods included from Writers::CrossciteWriter
Methods included from Writers::CodemetaWriter
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::DataciteJsonReader
Methods included from Readers::DataciteReader
#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
Methods included from Readers::CodemetaReader
Methods included from Readers::CiteprocReader
Methods included from Readers::BibtexReader
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_datacite_json, #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_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_datacite_json, #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_dates, #insert_descriptions, #insert_funding_references, #insert_identifier, #insert_person, #insert_publication_year, #insert_publisher, #insert_related_identifiers, #insert_resource_type, #insert_rights_list, #insert_subjects, #insert_titles, #insert_version, #insert_work, #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
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
65 66 67 |
# File 'lib/bolognese/metadata_utils.rb', line 65 def doc @doc end |
#from ⇒ Object
Returns the value of attribute from.
64 65 66 |
# File 'lib/bolognese/metadata_utils.rb', line 64 def from @from end |
#issue ⇒ Object
Returns the value of attribute issue.
64 65 66 |
# File 'lib/bolognese/metadata_utils.rb', line 64 def issue @issue end |
#locale ⇒ Object
144 145 146 |
# File 'lib/bolognese/metadata_utils.rb', line 144 def locale @locale ||= "en-US" end |
#meta ⇒ Object
Returns the value of attribute meta.
64 65 66 |
# File 'lib/bolognese/metadata_utils.rb', line 64 def @meta end |
#name_detector ⇒ Object (readonly)
recognize given name. Can be loaded once as ::NameDetector, e.g. in a Rails initializer
96 97 98 |
# File 'lib/bolognese/metadata_utils.rb', line 96 def name_detector @name_detector end |
#page_end ⇒ Object (readonly)
Returns the value of attribute page_end.
65 66 67 |
# File 'lib/bolognese/metadata_utils.rb', line 65 def page_end @page_end end |
#page_start ⇒ Object (readonly)
Returns the value of attribute page_start.
65 66 67 |
# File 'lib/bolognese/metadata_utils.rb', line 65 def page_start @page_start end |
#regenerate ⇒ Object
Returns the value of attribute regenerate.
64 65 66 |
# File 'lib/bolognese/metadata_utils.rb', line 64 def regenerate @regenerate end |
#reverse ⇒ Object (readonly)
Returns the value of attribute reverse.
65 66 67 |
# File 'lib/bolognese/metadata_utils.rb', line 65 def reverse @reverse end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
64 65 66 |
# File 'lib/bolognese/metadata_utils.rb', line 64 def sandbox @sandbox end |
#string ⇒ Object
Returns the value of attribute string.
64 65 66 |
# File 'lib/bolognese/metadata_utils.rb', line 64 def string @string end |
#style ⇒ Object
140 141 142 |
# File 'lib/bolognese/metadata_utils.rb', line 140 def style @style ||= "apa" end |
Instance Method Details
#citeproc_hsh ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/bolognese/metadata_utils.rb', line 117 def citeproc_hsh { "type" => types["citeproc"], "id" => identifier, "categories" => Array.wrap(subjects).map { |k| parse_attributes(k, content: "subject", first: true) }.presence, "language" => language, "author" => to_citeproc(creator), "contributor" => to_citeproc(contributor), "issued" => get_date(dates, "Issued") ? get_date_parts(get_date(dates, "Issued")) : nil, "submitted" => Array.wrap(dates).find { |d| d["dateType"] == "Submitted" }.to_h.fetch("__content__", nil), "abstract" => parse_attributes(descriptions, content: "description", first: true), "container-title" => periodical && periodical["title"], "DOI" => doi, "issue" => issue, "page" => [first_page, last_page].compact.join("-").presence, "publisher" => publisher, "title" => parse_attributes(titles, content: "title", first: true), "URL" => url, "version" => version, "volume" => volume }.compact.symbolize_keys end |
#first_page ⇒ Object
87 88 89 |
# File 'lib/bolognese/metadata_utils.rb', line 87 def first_page @first_page ||= .fetch("first_page", nil) end |
#graph ⇒ Object
113 114 115 |
# File 'lib/bolognese/metadata_utils.rb', line 113 def graph RDF::Graph.new << JSON::LD::API.toRdf(schema_hsh) end |
#last_page ⇒ Object
91 92 93 |
# File 'lib/bolognese/metadata_utils.rb', line 91 def last_page @last_page ||= .fetch("last_page", nil) end |
#raw ⇒ Object
replace DOI in XML if provided in options
69 70 71 72 73 74 75 76 77 |
# File 'lib/bolognese/metadata_utils.rb', line 69 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
79 80 81 |
# File 'lib/bolognese/metadata_utils.rb', line 79 def should_passthru (from == "datacite") && regenerate.blank? && raw.present? end |
#volume ⇒ Object
83 84 85 |
# File 'lib/bolognese/metadata_utils.rb', line 83 def volume @volume ||= .fetch("volume", nil) end |