Module: Bolognese::Readers::CrossrefReader
- Included in:
- MetadataUtils
- Defined in:
- lib/bolognese/readers/crossref_reader.rb
Constant Summary collapse
- CONTACT_EMAIL =
CrossRef types from api.crossref.org/types
"[email protected]"
Instance Method Summary collapse
- #crossref_alternate_identifier(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_identifier(bibliographic_metadata) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 119 def crossref_alternate_identifier() 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
202 203 204 205 206 207 208 209 210 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 202 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 127 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
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 165 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
212 213 214 215 216 217 218 219 220 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 212 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
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 143 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
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 154 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
222 223 224 225 226 227 228 229 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 222 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
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 10 def get_crossref(id: nil, **) return { "string" => nil, "state" => "not_found" } 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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 |
# File 'lib/bolognese/readers/crossref_reader.rb', line 22 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 # model should be one of book, conference, database, dissertation, journal, peer_review, posted_content, # report-paper, sa_component, standard model = .dig("crossref").to_h.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").to_h additional_type = .fetch("component_type", nil) ? "book-" + .fetch("component_type") : "book" publisher = .dig("publisher", "publisher_name") when "conference" = .dig("crossref", "conference", "event_metadata") || |