Module: Bolognese::Readers::CrossrefReader
- Included in:
- Metadata
- Defined in:
- lib/bolognese/readers/crossref_reader.rb
Constant Summary collapse
- CR_TO_SO_TRANSLATIONS =
CrossRef types from api.crossref.org/types
{ "Proceedings" => nil, "ReferenceBook" => "Book", "JournalIssue" => "PublicationIssue", "ProceedingsArticle" => nil, "Other" => "CreativeWork", "Dissertation" => "Thesis", "Dataset" => "Dataset", "EditedBook" => "Book", "JournalArticle" => "ScholarlyArticle", "Journal" => nil, "Report" => nil, "BookSeries" => nil, "ReportSeries" => nil, "BookTrack" => nil, "Standard" => nil, "BookSection" => nil, "BookPart" => nil, "Book" => "Book", "BookChapter" => "Chapter", "StandardSeries" => nil, "Monograph" => "Book", "Component" => "CreativeWork", "ReferenceEntry" => nil, "JournalVolume" => "PublicationVolume", "BookSet" => nil, "PostedContent" => "ScholarlyArticle" }
- CR_TO_BIB_TRANSLATIONS =
{ "Proceedings" => "proceedings", "ReferenceBook" => "book", "JournalIssue" => nil, "ProceedingsArticle" => nil, "Other" => nil, "Dissertation" => "phdthesis", "Dataset" => nil, "EditedBook" => "book", "JournalArticle" => "article", "Journal" => nil, "Report" => nil, "BookSeries" => nil, "ReportSeries" => nil, "BookTrack" => nil, "Standard" => nil, "BookSection" => "inbook", "BookPart" => nil, "Book" => "book", "BookChapter" => "inbook", "StandardSeries" => nil, "Monograph" => "book", "Component" => nil, "ReferenceEntry" => nil, "JournalVolume" => nil, "BookSet" => nil, "PostedContent" => "article" }
- CONTACT_EMAIL =
"[email protected]"
Instance Method Summary collapse
- #crossref_alternate_name(bibliographic_metadata) ⇒ Object
-
#crossref_date_published(bibliographic_metadata) ⇒ Object
def datacite_funding_reference(meta) Array.wrap(meta.dig(“fundingReferences”, “fundingReference”)).map do |f| funder_id = parse_attributes(f) funder = { “type” => “Organization”, “id” => normalize_id(funder_id), “name” => f }.compact if f.present? || f.present? { “type” => “Award”, “name” => f.fetch(“awardTitle”, nil), “identifier” => f.dig(“awardNumber”, “__content__”), “url” => f.dig(“awardNumber”, “awardURI”), “funder” => funder } else funder end end.uniq end.
- #crossref_description(bibliographic_metadata) ⇒ Object
- #crossref_funding_reference(program_metadata) ⇒ Object
- #crossref_is_part_of(journal_metadata) ⇒ Object
- #crossref_license(program_metadata) ⇒ Object
- #crossref_people(bibliographic_metadata, contributor_role) ⇒ Object
- #crossref_references(bibliographic_metadata) ⇒ Object
- #get_crossref(id: nil) ⇒ Object
- #read_crossref(string: nil) ⇒ Object
Instance Method Details
#crossref_alternate_name(bibliographic_metadata) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 134 def crossref_alternate_name() if .fetch("publisher_item", nil).present? parse_attributes(.dig("publisher_item", "item_number")) else parse_attributes(.fetch("item_number", nil)) end end |
#crossref_date_published(bibliographic_metadata) ⇒ Object
def datacite_funding_reference(meta)
Array.wrap(.dig("fundingReferences", "fundingReference")).map do |f|
funder_id = parse_attributes(f["funderIdentifier"])
funder = { "type" => "Organization",
"id" => normalize_id(funder_id),
"name" => f["funderName"] }.compact
if f["awardNumber"].present? || f["awardTitle"].present?
{ "type" => "Award",
"name" => f.fetch("awardTitle", nil),
"identifier" => f.dig("awardNumber", "__content__"),
"url" => f.dig("awardNumber", "awardURI"),
"funder" => funder }
else
funder
end
end.uniq
end
208 209 210 211 212 213 214 215 216 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 208 def crossref_date_published() pub_date = Array.wrap(.fetch("publication_date", nil)).presence || Array.wrap(.fetch("acceptance_date", nil)) if pub_date.present? get_date_from_parts(pub_date.first["year"], pub_date.first["month"], pub_date.first["day"]) else nil end end |
#crossref_description(bibliographic_metadata) ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 142 def crossref_description() des = .fetch("abstract", {}).values.first if des.is_a?(Hash) sanitize(des.fetch("__content__", nil)) elsif des.is_a?(String) sanitize(des) end end |
#crossref_funding_reference(program_metadata) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 171 def crossref_funding_reference() fundref = Array.wrap().find { |a| a["name"] == "fundref" } || {} Array.wrap(fundref.fetch("assertion", [])).select { |a| a["name"] == "fundgroup" }.map do |f| f = Array.wrap(f.fetch("assertion", nil)).first funder = { "type" => "Organization", "id" => normalize_id(f.dig("assertion", "__content__")), "name" => f.dig("__content__").strip }.compact if f["awardNumber"].present? || f["awardTitle"].present? { "type" => "Award", "name" => f.fetch("awardTitle", nil), "identifier" => f.dig("awardNumber", "__content__"), "url" => f.dig("awardNumber", "awardURI"), "funder" => funder } else funder end end.unwrap end |
#crossref_is_part_of(journal_metadata) ⇒ Object
218 219 220 221 222 223 224 225 226 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 218 def crossref_is_part_of() if .present? { "type" => "Periodical", "title" => ["full_title"], "issn" => parse_attributes(.fetch("issn", nil)) }.compact else nil end end |
#crossref_license(program_metadata) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 151 def crossref_license() access_indicator = Array.wrap().find { |m| m["name"] == "AccessIndicators" } if access_indicator.present? { "id" => normalize_url(parse_attributes(access_indicator["license_ref"])) } else nil end end |
#crossref_people(bibliographic_metadata, contributor_role) ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 160 def crossref_people(, contributor_role) person = .dig("contributors", "person_name") Array.wrap(person).select { |a| a["contributor_role"] == contributor_role }.map do |a| { "type" => "Person", "id" => parse_attributes(a["ORCID"]), "name" => [a["given_name"], a["surname"]].join(" "), "givenName" => a["given_name"], "familyName" => a["surname"] }.compact end.unwrap end |
#crossref_references(bibliographic_metadata) ⇒ Object
228 229 230 231 232 233 234 235 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 228 def crossref_references() refs = .dig("citation_list", "citation") Array.wrap(refs).select { |a| a["doi"].present? }.map do |c| { "type" => "CreativeWork", "id" => normalize_id(c["doi"]), "title" => c["article_title"] }.compact end.unwrap end |
#get_crossref(id: nil) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 65 def get_crossref(id: nil) return nil unless id.present? doi = doi_from_url(id) url = "http://www.crossref.org/openurl/?id=doi:#{doi}&noredirect=true&pid=#{CONTACT_EMAIL}&format=unixref" response = Maremma.get(url, accept: "text/xml", raw: true) string = response.body.fetch("data", nil) Nokogiri::XML(string, nil, 'UTF-8', &:noblanks).to_s if string.present? end |
#read_crossref(string: nil) ⇒ Object
75 76 77 78 79 80 81 82 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 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 75 def read_crossref(string: nil) if string.present? m = Maremma.from_xml(string).dig("doi_records", "doi_record") || {} = m.dig("crossref", "error").nil? ? m : {} else = {} end return unless ["crossref"].present? = .dig("crossref", "journal", "journal_metadata").presence || {} = .dig("crossref", "journal", "journal_article").presence || .dig("crossref", "conference", "conference_paper").presence || .dig("crossref", .fetch("crossref", {}).keys.last).presence || {} = .dig("program") || .dig("crossmark", "custom_metadata", "program") || {} journal_issue = .dig("crossref", "journal", "journal_issue").presence || {} additional_type = if .dig("crossref", "journal").present? .dig("crossref", "journal").keys.last.camelize else .dig("crossref").keys.last.camelize end type = CR_TO_SO_TRANSLATIONS[additional_type] || "ScholarlyArticle" doi = .dig("doi_data", "doi") { "id" => normalize_doi(doi), "type" => type, "additional_type" => additional_type, "citeproc_type" => Bolognese::Utils::CR_TO_CP_TRANSLATIONS[additional_type] || "article-journal", "bibtex_type" => CR_TO_BIB_TRANSLATIONS[additional_type] || "misc", "ris_type" => Bolognese::Utils::CR_TO_RIS_TRANSLATIONS[additional_type] || "JOUR", "resource_type_general" => Bolognese::Utils::SO_TO_DC_TRANSLATIONS[type], "doi" => doi, "url" => .dig("doi_data", "resource"), "title" => parse_attributes(.dig("titles", "title")), "alternate_name" => crossref_alternate_name(), "author" => crossref_people(, "author"), "editor" => crossref_people(, "editor"), "funding" => crossref_funding_reference(), "publisher" => nil, "provider" => "Crossref", "is_part_of" => crossref_is_part_of(), "references" => crossref_references(), "date_published" => crossref_date_published(), "date_modified" => Time.parse(.fetch("timestamp", "")).utc.iso8601, "volume" => journal_issue.dig("journal_volume", "volume"), "issue" => journal_issue.dig("issue"), "pagination" => [.dig("pages", "first_page"), .dig("pages", "last_page")].compact.join("-").presence, "description" => crossref_description(), "license" => crossref_license(), "version" => nil, "keywords" => nil, "language" => nil, "content_size" => nil, "schema_version" => nil } end |