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(model_metadata) ⇒ Object
- #crossref_license(program_metadata) ⇒ Object
- #crossref_people(bibliographic_metadata, contributor_role) ⇒ Object
- #crossref_references(bibliographic_metadata) ⇒ Object
- #get_crossref(id: nil, **options) ⇒ Object
- #read_crossref(string: nil, **options) ⇒ Object
Instance Method Details
#crossref_alternate_name(bibliographic_metadata) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 170 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
253 254 255 256 257 258 259 260 261 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 253 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
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 178 def crossref_description() abstract = Array.wrap(.dig("abstract")).map do |r| { "type" => "Abstract", "text" => sanitize(parse_attributes(r, content: 'p')) }.compact end description = Array.wrap(.dig("description")).map do |r| if abstract.present? { "text" => sanitize(parse_attributes(r)) }.compact else sanitize(parse_attributes(r)) end end (abstract + description).unwrap end |
#crossref_funding_reference(program_metadata) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 216 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(model_metadata) ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 263 def crossref_is_part_of() if .present? { "type" => "Periodical", "title" => ["full_title"], "issn" => parse_attributes(.fetch("issn", nil), first: true) }.compact else nil end end |
#crossref_license(program_metadata) ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 194 def crossref_license() access_indicator = Array.wrap().find { |m| m["name"] == "AccessIndicators" } if access_indicator.present? Array.wrap(access_indicator["license_ref"]).map do |license| { "id" => normalize_url(parse_attributes(license)) } end.uniq.unwrap else nil end end |
#crossref_people(bibliographic_metadata, contributor_role) ⇒ Object
205 206 207 208 209 210 211 212 213 214 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 205 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
273 274 275 276 277 278 279 280 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 273 def crossref_references() refs = .dig("citation_list", "citation") Array.wrap(refs).select { |a| a["doi"].present? }.map do |c| { "type" => "CreativeWork", "id" => normalize_id(parse_attributes(c["doi"])), "title" => c["article_title"] }.compact end.unwrap end |
#get_crossref(id: nil, **options) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# 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) string = Nokogiri::XML(string, nil, 'UTF-8', &:noblanks).to_s if string.present? { "string" => string } end |
#read_crossref(string: nil, **options) ⇒ Object
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 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 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 77 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? # model should be one of book, conference, database, dissertation, journal, peer_review, posted_content, # report-paper, sa_component, standard model = .dig("crossref").keys.first additional_type = nil = {} = nil journal_issue = {} publisher = nil case model when "book" = .dig("crossref", "book", "book_metadata") = .dig("crossref", "book", "book_series_metadata") = .dig("crossref", "book", "book_set_metadata") = .dig("crossref", "book", "content_item") || {} additional_type = .fetch("component_type", nil) ? "book-" + .fetch("component_type") : "book" publisher = .dig("publisher", "publisher_name") when "conference" = .dig("crossref", "conference", "event_metadata") || {} = .dig("crossref", "conference", "conference_paper") || {} when "journal" = .dig("crossref", "journal", "journal_metadata") || {} = .dig("crossref", "journal", "journal_article") || {} = .dig("crossmark", "custom_metadata", "program") || .dig("program") journal_issue = .dig("crossref", "journal", "journal_issue") || {} journal_article = .dig("crossref", "journal", "journal_article") || {} additional_type = if journal_article.present? "journal_article" elsif journal_issue.present? "journal_issue" else "journal" end when "posted_content" = .dig("crossref", "posted_content") || {} when "sa_component" = .dig("crossref", "sa_component", "component_list", "component") || {} end additional_type = (additional_type || model).underscore.camelize type = CR_TO_SO_TRANSLATIONS[additional_type] || "ScholarlyArticle" doi = .dig("doi_data", "doi").to_s.downcase # Crossref servers run on Eastern Time Time.zone = 'Eastern Time (US & Canada)' date_modified = Time.zone.parse(.fetch("timestamp", "")).utc.iso8601 { "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" => publisher, "provider" => "Crossref", "is_part_of" => crossref_is_part_of(), "references" => crossref_references(), "date_published" => crossref_date_published(), "date_modified" => date_modified, "volume" => journal_issue.dig("journal_volume", "volume"), "issue" => journal_issue.dig("issue"), "first_page" => .dig("pages", "first_page"), "last_page" => .dig("pages", "last_page"), "description" => crossref_description(), "license" => crossref_license(), "version" => nil, "keywords" => nil, "language" => nil, "content_size" => nil, "schema_version" => nil } end |