Module: Bolognese::Readers::DataciteReader
- Included in:
- Metadata
- Defined in:
- lib/bolognese/readers/datacite_reader.rb
Instance Method Summary collapse
- #datacite_date(dates, date_type) ⇒ Object
- #datacite_funder_contributor(meta) ⇒ Object
- #datacite_funding_reference(meta) ⇒ Object
- #datacite_has_part(meta) ⇒ Object
- #datacite_is_identical_to(meta) ⇒ Object
- #datacite_is_new_version_of(meta) ⇒ Object
- #datacite_is_original_form_of(meta) ⇒ Object
- #datacite_is_part_of(meta) ⇒ Object
- #datacite_is_previous_version_of(meta) ⇒ Object
- #datacite_is_referenced_by(meta) ⇒ Object
- #datacite_is_reviewed_by(meta) ⇒ Object
- #datacite_is_supplement_to(meta) ⇒ Object
- #datacite_is_supplemented_by(meta) ⇒ Object
- #datacite_is_variant_form_of(meta) ⇒ Object
- #datacite_references(meta) ⇒ Object
- #datacite_related_identifier(meta, relation_type: nil) ⇒ Object
- #datacite_reviews(meta) ⇒ Object
- #get_datacite(id: nil) ⇒ Object
- #read_datacite(string: nil) ⇒ Object
Instance Method Details
#datacite_date(dates, date_type) ⇒ Object
102 103 104 105 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 102 def datacite_date(dates, date_type) dd = dates.find { |d| d["dateType"] == date_type } || {} dd.fetch("__content__", nil) end |
#datacite_funder_contributor(meta) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 125 def datacite_funder_contributor() Array.wrap(.dig("contributors", "contributor")).reduce([]) do |sum, f| if f["contributorType"] == "Funder" # handle special case of OpenAIRE metadata id = f.dig("nameIdentifier", "__content__").to_s.start_with?("info:eu-repo/grantAgreement/EC") ? "https://doi.org/10.13039/501100000780" : nil funder = { "type" => "Organization", "id" => id, "name" => f["contributorName"] }.compact if f.dig("nameIdentifier", "nameIdentifierScheme") == "info" sum << { "type" => "Award", "identifier" => f.dig("nameIdentifier", "__content__").split("/").last, "funder" => funder } else sum << funder end else sum end end end |
#datacite_funding_reference(meta) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 107 def datacite_funding_reference() 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["awardNumber"].is_a?(Hash) ? f.dig("awardNumber", "__content__") : f["awardNumber"], "url" => f["awardNumber"].is_a?(Hash) ? f.dig("awardNumber", "awardURI") : nil, "funder" => funder }.compact else funder end end.uniq end |
#datacite_has_part(meta) ⇒ Object
162 163 164 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 162 def datacite_has_part() (, relation_type: "HasPart") end |
#datacite_is_identical_to(meta) ⇒ Object
154 155 156 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 154 def datacite_is_identical_to() (, relation_type: "IsIdenticalTo") end |
#datacite_is_new_version_of(meta) ⇒ Object
170 171 172 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 170 def datacite_is_new_version_of() (, relation_type: "IsNewVersionOf") end |
#datacite_is_original_form_of(meta) ⇒ Object
178 179 180 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 178 def datacite_is_original_form_of() (, relation_type: "IsOriginalFormOf") end |
#datacite_is_part_of(meta) ⇒ Object
158 159 160 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 158 def datacite_is_part_of() (, relation_type: "IsPartOf") end |
#datacite_is_previous_version_of(meta) ⇒ Object
166 167 168 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 166 def datacite_is_previous_version_of() (, relation_type: "IsPreviousVersionOf") end |
#datacite_is_referenced_by(meta) ⇒ Object
186 187 188 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 186 def datacite_is_referenced_by() (, relation_type: "IsCitedBy IsReferencedBy").presence end |
#datacite_is_reviewed_by(meta) ⇒ Object
202 203 204 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 202 def datacite_is_reviewed_by() (, relation_type: "IsReviewedBy").presence end |
#datacite_is_supplement_to(meta) ⇒ Object
190 191 192 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 190 def datacite_is_supplement_to() (, relation_type: "IsSupplementTo") end |
#datacite_is_supplemented_by(meta) ⇒ Object
194 195 196 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 194 def datacite_is_supplemented_by() (, relation_type: "isSupplementedBy") end |
#datacite_is_variant_form_of(meta) ⇒ Object
174 175 176 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 174 def datacite_is_variant_form_of() (, relation_type: "IsVariantFormOf") end |
#datacite_references(meta) ⇒ Object
182 183 184 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 182 def datacite_references() (, relation_type: "References Cites").presence end |
#datacite_related_identifier(meta, relation_type: nil) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 147 def (, relation_type: nil) arr = Array.wrap(.dig("relatedIdentifiers", "relatedIdentifier")).select { |r| %w(DOI URL).include?(r["relatedIdentifierType"]) } arr = arr.select { |r| relation_type.split(" ").include?(r["relationType"]) } if relation_type.present? arr.map { |work| { "type" => "CreativeWork", "id" => normalize_id(work["__content__"]) } }.unwrap end |
#datacite_reviews(meta) ⇒ Object
198 199 200 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 198 def datacite_reviews() (, relation_type: "Reviews").presence end |
#get_datacite(id: nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 4 def get_datacite(id: nil) return nil unless id.present? doi = doi_from_url(id) url = "https://search.datacite.org/api?q=doi:#{doi}&fl=doi,xml,media,minted,updated&wt=json" response = Maremma.get url attributes = response.body.dig("data", "response", "docs").first return nil unless attributes.present? string = attributes.fetch('xml', "PGhzaD48L2hzaD4=\n") string = Base64.decode64(string) if string.present? doc = Nokogiri::XML(string, nil, 'UTF-8', &:noblanks) doc.to_s end end |
#read_datacite(string: nil) ⇒ Object
21 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 |
# File 'lib/bolognese/readers/datacite_reader.rb', line 21 def read_datacite(string: nil) = string.present? ? Maremma.from_xml(string).fetch("resource", {}) : {} id = normalize_doi(.dig("identifier", "__content__")) doi = doi_from_url(id) resource_type_general = .dig("resourceType", "resourceTypeGeneral") type = Bolognese::Utils::DC_TO_SO_TRANSLATIONS[resource_type_general.to_s.dasherize] || "CreativeWork" title = Array.wrap(.dig("titles", "title")).map do |r| if r.is_a?(String) sanitize(r) else { "title_type" => r["titleType"], "lang" => r["xml:lang"], "text" => sanitize(r["__content__"]) }.compact end end.unwrap alternate_name = Array.wrap(.dig("alternateIdentifiers", "alternateIdentifier")).map do |r| { "type" => r["alternateIdentifierType"], "name" => r["__content__"] }.compact end.unwrap description = Array.wrap(.dig("descriptions", "description")).map do |r| { "type" => r["descriptionType"], "text" => sanitize(r["__content__"]) }.compact end.unwrap license = Array.wrap(.dig("rightsList", "rights")).map do |r| { "id" => normalize_url(r["rightsURI"]), "name" => r["__content__"] }.compact end.unwrap keywords = Array.wrap(.dig("subjects", "subject")).map do |k| if k.nil? nil elsif k.is_a?(String) sanitize(k) else { "subject_scheme" => k["subjectScheme"], "scheme_uri" => k["schemeURI"], "text" => sanitize(k["__content__"]) }.compact end end.compact dates = Array.wrap(.dig("dates", "date")) funding = begin f = datacite_funder_contributor() + datacite_funding_reference() f.length > 1 ? f : f.first end { "id" => id, "type" => type, "additional_type" => .fetch("resourceType", {}).fetch("__content__", nil) || .fetch("resourceType", {}).fetch("resourceTypeGeneral", nil), "citeproc_type" => Bolognese::Utils::DC_TO_CP_TRANSLATIONS[resource_type_general.to_s.dasherize] || "other", "bibtex_type" => Bolognese::Utils::SO_TO_BIB_TRANSLATIONS[type] || "misc", "ris_type" => Bolognese::Utils::DC_TO_RIS_TRANSLATIONS[resource_type_general.to_s.dasherize] || "GEN", "resource_type_general" => resource_type_general, "doi" => doi, "url" => nil, "title" => title, "alternate_name" => alternate_name, "author" => (.dig("creators", "creator")), "editor" => (Array.wrap(.dig("contributors", "contributor")).select { |r| r["contributorType"] == "Editor" }), "publisher" => .fetch("publisher", nil), "provider" => "DataCite", "funding" => funding, "is_identical_to" => datacite_is_identical_to(), "is_part_of" => datacite_is_part_of(), "has_part" => datacite_has_part(), "references" => datacite_references(), "is_referenced_by" => datacite_is_referenced_by(), "is_supplement_to" => datacite_is_supplement_to(), "is_supplemented_by" => datacite_is_supplemented_by(), "date_created" => datacite_date(dates, "Created"), "date_accepted" => datacite_date(dates, "Accepted"), "date_available" => datacite_date(dates, "Available"), "date_copyrighted" => datacite_date(dates, "Copyrightes"), "date_collected" => datacite_date(dates, "Collected"), "date_submitted" => datacite_date(dates, "Submitted"), "date_valid" => datacite_date(dates, "Valid"), "date_published" => datacite_date(dates, "Issued") || .fetch("publicationYear", nil), "date_modified" => datacite_date(dates, "Updated"), "description" => description, "license" => license, "version" => .fetch("version", nil), "keywords" => keywords, "language" => .fetch("language", nil), "content_size" => .fetch("size", nil), "schema_version" => .fetch("xmlns", nil) } end |