lib/briard/readers/cff_reader.rb in briard-2.2 vs lib/briard/readers/cff_reader.rb in briard-2.2.1
- old
+ new
@@ -47,21 +47,23 @@
sum += name_to_fos(subject)
sum
end
- titles = meta.fetch("title", nil).present? ? [{ "title" => meta.fetch("title", nil) }] : []
+ titles = meta.fetch("title", nil).present? ? [{ "title" => meta.fetch("title", nil) }] : []
+ related_identifiers = Array.wrap(cff_references(meta.fetch("references", nil)))
rights_list = meta.fetch("license", nil).present? ? [hsh_to_spdx("rightsIdentifier" => meta.fetch("license"))] : nil
{ "id" => id,
"types" => types,
"identifiers" => identifiers,
"doi" => doi_from_url(id),
"url" => url,
"titles" => titles,
"creators" => creators,
"publisher" => publisher,
+ "related_identifiers" => related_identifiers,
"dates" => dates,
"publication_year" => publication_year,
"descriptions" => meta.fetch("abstract", nil).present? ? [{ "description" => sanitize(meta.fetch("abstract")), "descriptionType" => "Abstract" }] : nil,
"rights_list" => rights_list,
"version_info" => meta.fetch("version", nil),
@@ -71,11 +73,11 @@
end
def cff_creators(creators)
Array.wrap(creators).map do |a|
name_identifiers = normalize_orcid(parse_attributes(a["orcid"])).present? ? [{ "nameIdentifier" => normalize_orcid(parse_attributes(a["orcid"])), "nameIdentifierScheme" => "ORCID", "schemeUri"=>"https://orcid.org" }] : nil
- if a["given-names"].present? || name_identifiers.present?
+ if a["given-names"].present? || a["family-names"].present? || name_identifiers.present?
given_name = parse_attributes(a["given-names"])
family_name = parse_attributes(a["family-names"])
affiliation = Array.wrap(a["affiliation"]).map do |a|
if a.is_a?(Hash)
a
@@ -99,9 +101,23 @@
else
{ "nameType" => "Organizational",
"name" => a["name"] || a["__content__"] }
end
end
+ end
+
+ def cff_references(references)
+ Array.wrap(references).map do |r|
+ identifier = Array.wrap(r["identifiers"]).find { |i| i["type"] == "doi" }
+
+ if identifier.present?
+ { "relatedIdentifier" => normalize_id(parse_attributes(identifier["value"])),
+ "relationType" => "References",
+ "relatedIdentifierType" => "DOI" }.compact
+ else
+ nil
+ end
+ end.compact.unwrap
end
end
end
end