Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f03a674
remove numberType normalization; fixes datacite/product-backlog#787
bklaing2 Apr 28, 2026
ecfedc0
return raw DOI instead of `nil` if Crossref Funder ID is not valid; f…
bklaing2 Apr 28, 2026
7247468
return raw id instead of `nil` if ROR is not valid; fixes datacite/pr…
bklaing2 Apr 28, 2026
c409986
return raw DOI instead of `nil` if DOI is not valid; fixes datacite/p…
bklaing2 Apr 29, 2026
e86458c
return raw DOI instead of `nil` if DOI is not valid; fixes datacite/p…
bklaing2 Apr 29, 2026
f505bc5
return raw id instead of `nil` if ORCID is not valid; fixes datacite/…
bklaing2 Apr 29, 2026
fe32c68
do not manually assign `schemeUri` to ROR; fixes datacite/product-bac…
bklaing2 Apr 29, 2026
423ff9f
do not skip invalid dates, use the raw value; fixes datacite/product-…
bklaing2 Apr 29, 2026
1addbf6
do not add "Issued" date based on `publicationYear`; fixes datacite/p…
bklaing2 Apr 29, 2026
d75eeed
do not remove spaces around hyphen in name; fixes datacite/product-ba…
bklaing2 Apr 29, 2026
e6ea5ea
do not add joining comma in name; fixes datacite/product-backlog#788
bklaing2 Apr 29, 2026
e4b1af1
remove additional subject FOS mapping; fixes datacite/product-backlog…
bklaing2 May 7, 2026
6bce1d6
remove `Namae` normalization; fixes datacite/product-backlog#794
bklaing2 May 11, 2026
93adeaf
do not replace `name` with `givenName, familyName`; fixes datacite/pr…
bklaing2 May 11, 2026
73068a5
rename `name/hsh_to_fos` to `name/hsh_to_subject`
bklaing2 May 13, 2026
5567a19
JATS writer falls back to `publicationYear` when there is no `issued`…
bklaing2 May 13, 2026
010f16a
Merge branch 'metadata-normalization-changes' into remove-author-norm…
bklaing2 May 13, 2026
bd201ac
Merge pull request #233 from datacite/remove-author-normalizations
bklaing2 May 13, 2026
73693e1
Add tests for normalizations that have been removed from datacite reader
codycooperross May 14, 2026
bed5403
Fix expected FOS mapping
codycooperross May 14, 2026
b0f736b
test for unset affiliation scheme
bklaing2 May 14, 2026
ea44a4a
Merge pull request #234 from datacite/normalization-test
bklaing2 May 15, 2026
4973ca3
bump version
bklaing2 May 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bolognese (2.6.1)
bolognese (2.7.0)
activesupport (~> 8.1, >= 8.1.2)
bibtex-ruby (~> 6.2)
builder (~> 3.3)
Expand Down
41 changes: 1 addition & 40 deletions lib/bolognese/author_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def get_one_author(author)
given_name = parse_attributes(author.fetch("givenName", nil))
family_name = parse_attributes(author.fetch("familyName", nil))
name = cleanup_author(name)
name = [family_name, given_name].join(", ") if family_name.present? && given_name.present?
contributor_type = parse_attributes(author.fetch("contributorType", nil))

name_type = parse_attributes(author.fetch("creatorName", nil), content: "nameType", first: true) || parse_attributes(author.fetch("contributorName", nil), content: "nameType", first: true)
Expand All @@ -46,55 +45,18 @@ def get_one_author(author)
end
end.presence

author = { "nameType" => name_type,
{ "nameType" => name_type,
"name" => name,
"givenName" => given_name,
"familyName" => family_name,
"nameIdentifiers" => name_identifiers,
"affiliation" => get_affiliations(author.fetch("affiliation", nil)),
"contributorType" => contributor_type }.compact

return author if family_name.present?

if is_personal_name?(author)
Namae.options[:include_particle_in_family] = true
names = Namae.parse(name)
parsed_name = names.first

if parsed_name.present?
given_name = parsed_name.given
family_name = parsed_name.family
name = [family_name, given_name].join(", ")
else
given_name = nil
family_name = nil
end

{ "nameType" => "Personal",
"name" => name,
"givenName" => given_name,
"familyName" => family_name,
"nameIdentifiers" => Array.wrap(name_identifiers),
"affiliation" => Array.wrap(author.fetch("affiliation", nil)),
"contributorType" => contributor_type }.compact
else
{ "nameType" => name_type,
"name" => name,
"nameIdentifiers" => Array.wrap(name_identifiers),
"affiliation" => Array.wrap(author.fetch("affiliation", nil)),
"contributorType" => contributor_type }.compact
end
end

def cleanup_author(author)
return nil unless author.present?

# detect pattern "Smith J.", but not "Smith, John K."
author = author.gsub(/[[:space:]]([A-Z]\.)?(-?[A-Z]\.)$/, ', \1\2') unless author.include?(",")

# remove spaces around hyphens
author = author.gsub(" - ", "-")

# titleize strings
# remove non-standard space characters
author.gsub(/[[:space:]]/, ' ')
Expand Down Expand Up @@ -155,7 +117,6 @@ def get_affiliations(affiliations)
# when `normalize_id` method could not normalize, it returns nil, hence we have following condition
if affiliation_identifier.nil?
if a["affiliationIdentifierScheme"] == "ROR"
scheme_uri = "https://ror.org"
affiliation_identifier = normalize_ror(a["affiliationIdentifier"])
else
affiliation_identifier = a["affiliationIdentifier"]
Expand Down
7 changes: 4 additions & 3 deletions lib/bolognese/doi_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def validate_doi(doi)
end

def validate_funder_doi(doi)
doi = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.13039\/)?([1-9]\d+)\z/.match(doi)).last
match = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.13039\/)?([1-9]\d+)\z/.match(doi)).last
return doi unless match

# remove non-printing whitespace and downcase
if doi.present?
doi.delete("\u200B").downcase
if match.present?
doi = match.delete("\u200B").downcase
"https://doi.org/10.13039/#{doi}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/readers/citeproc_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def read_citeproc(string: nil, **options)

state = id.present? || read_options.present? ? "findable" : "not_found"
subjects = Array.wrap(meta.fetch("categories", nil)).reduce([]) do |sum, subject|
sum += name_to_fos(subject)
sum += name_to_subject(subject)

sum
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/readers/codemeta_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def read_codemeta(string: nil, **options)
"ris" => Bolognese::Utils::SO_TO_RIS_TRANSLATIONS[schema_org] || "GEN"
}.compact
subjects = Array.wrap(meta.fetch("tags", nil)).reduce([]) do |sum, subject|
sum += name_to_fos(subject)
sum += name_to_subject(subject)

sum
end
Expand Down
25 changes: 11 additions & 14 deletions lib/bolognese/readers/datacite_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,22 @@ def read_datacite(string: nil, **options)

subjects = Array.wrap(meta.dig("subjects", "subject")).reduce([]) do |sum, subject|
if subject.is_a?(String)
sum += name_to_fos(subject)
sum += name_to_subject(subject)
elsif subject.is_a?(Hash)
sum += hsh_to_fos(subject)
sum += hsh_to_subject(subject)
end

sum
end.uniq

dates = Array.wrap(meta.dig("dates", "date")).map do |r|
if r.is_a?(Hash) && date = sanitize(r["__content__"]).presence
if Date.edtf(date).present? || Bolognese::Utils::UNKNOWN_INFORMATION.key?(date)
{ "date" => date,
"dateType" => parse_attributes(r, content: "dateType"),
"dateInformation" => parse_attributes(r, content: "dateInformation")
}.compact
end
{ "date" => date,
"dateType" => parse_attributes(r, content: "dateType"),
"dateInformation" => parse_attributes(r, content: "dateInformation")
}.compact
end
end.compact
dates << { "date" => meta.fetch("publicationYear", nil), "dateType" => "Issued" } if meta.fetch("publicationYear", nil).present? && get_date(dates, "Issued").blank?
sizes = Array.wrap(meta.dig("sizes", "size")).map do |k|
if k.blank?
nil
Expand Down Expand Up @@ -179,8 +176,7 @@ def read_datacite(string: nil, **options)
if funder_identifier_type == "Crossref Funder ID"
funder_identifier = validate_funder_doi(funder_identifier)
elsif funder_identifier_type == "ROR"
funder_identifier = normalize_ror(funder_identifier)
scheme_uri = "https://ror.org"
funder_identifier = normalize_ror(funder_identifier)
else
funder_identifier = normalize_id(funder_identifier) ? normalize_id(funder_identifier) : funder_identifier
end
Expand All @@ -196,7 +192,8 @@ def read_datacite(string: nil, **options)
end
related_identifiers = Array.wrap(meta.dig("relatedIdentifiers", "relatedIdentifier")).map do |ri|
if ri["relatedIdentifierType"] == "DOI"
rid = validate_doi(ri["__content__"].to_s.downcase)
doi = ri["__content__"].to_s.downcase
rid = validate_doi(doi) || doi
else
rid = ri["__content__"]
end
Expand All @@ -219,7 +216,8 @@ def read_datacite(string: nil, **options)
relatedItemIdentifier = nil
if rii
if rii["relatedItemIdentifierType"] == "DOI"
rid = validate_doi(rii["__content__"].to_s.downcase)
doi = rii["__content__"].to_s.downcase
rid = validate_doi(doi) || doi
else
rid = rii["__content__"]
end
Expand All @@ -236,7 +234,6 @@ def read_datacite(string: nil, **options)
number = ri["number"]
if number.is_a?(String)
number = number
numberType = nil
else
number = ri.dig("number", "__content__")
numberType = ri.dig("number", "numberType")
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/readers/ris_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def read_ris(string: nil, **options)
end
state = meta.fetch("DO", nil).present? || read_options.present? ? "findable" : "not_found"
subjects = Array.wrap(meta.fetch("KW", nil)).reduce([]) do |sum, subject|
sum += name_to_fos(subject)
sum += name_to_subject(subject)

sum
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/readers/schema_org_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def read_schema_org(string: nil, **options)
subjects = meta.fetch("keywords", nil)
subjects = subjects.to_s.split(", ") if subjects.is_a?(String)
subjects = Array.wrap(subjects).reduce([]) do |sum, subject|
sum += name_to_fos(subject)
sum += name_to_subject(subject)
sum
end

Expand Down
117 changes: 16 additions & 101 deletions lib/bolognese/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -699,19 +699,19 @@ def normalize_cc_url(id)
end

def normalize_orcid(orcid)
orcid = validate_orcid(orcid)
return nil unless orcid.present?
validated = validate_orcid(orcid)
return orcid unless validated.present?

# turn ORCID ID into URL
"https://orcid.org/" + Addressable::URI.encode(orcid)
"https://orcid.org/" + Addressable::URI.encode(validated)
end

def normalize_ror(ror)
ror = validate_ror(ror)
return nil unless ror.present?
validated = validate_ror(ror)
return ror unless validated.present?

# turn ROR into URL
"https://ror.org/" + Addressable::URI.encode(ror)
"https://ror.org/" + Addressable::URI.encode(validated)
end

def normalize_ids(ids: nil, relation_type: nil)
Expand Down Expand Up @@ -1331,103 +1331,18 @@ def hsh_to_spdx(hsh)
end
end

def name_to_fos(name)
# first find subject in Fields of Science (OECD)
fos = resource_json(:fos).fetch("fosFields")

subject = fos.find { |l| l["fosLabel"] == name || "FOS: " + l["fosLabel"] == name }

if subject
return [{
"subject" => sanitize(name) },
{
"subject" => "FOS: " + subject["fosLabel"],
"subjectScheme" => "Fields of Science and Technology (FOS)",
"schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf"
}]
end

# if not found, look in Fields of Research (Australian and New Zealand Standard Research Classification)
# and map to Fields of Science. Add an extra entry for the latter
fores = resource_json(:for)
for_fields = fores.fetch("forFields")
for_disciplines = fores.fetch("forDisciplines")

subject = for_fields.find { |l| l["forLabel"] == name } ||
for_disciplines.find { |l| l["forLabel"] == name }

if subject
[{
"subject" => sanitize(name) },
{
"subject" => "FOS: " + subject["fosLabel"],
"subjectScheme" => "Fields of Science and Technology (FOS)",
"schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf"
}]
else
[{ "subject" => sanitize(name) }]
end
def name_to_subject(name)
[{ "subject" => sanitize(name) }]
end

def hsh_to_fos(hsh)
# first find subject in Fields of Science (OECD)
fos = resource_json(:fos).fetch("fosFields")
subject = fos.find { |l| l["fosLabel"] == hsh["__content__"] || "FOS: " + l["fosLabel"] == hsh["__content__"] || l["fosLabel"] == hsh["subject"]}

if subject
return [{
"subject" => sanitize(hsh["__content__"] || hsh["subject"]),
"subjectScheme" => hsh["subjectScheme"],
"schemeUri" => hsh["schemeURI"] || hsh["schemeUri"],
"valueUri" => hsh["valueURI"] || hsh["valueUri"],
"classificationCode" => hsh["classificationCode"],
"lang" => hsh["lang"] }.compact,
{
"subject" => "FOS: " + subject["fosLabel"],
"subjectScheme" => "Fields of Science and Technology (FOS)",
"schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf" }.compact]
end

# if not found, look in Fields of Research (Australian and New Zealand Standard Research Classification)
# and map to Fields of Science. Add an extra entry for the latter
fores = resource_json(:for)
for_fields = fores.fetch("forFields")
for_disciplines = fores.fetch("forDisciplines")

# try to extract forId
if hsh["subjectScheme"] == "FOR"
for_id = hsh["__content__"].to_s.split(" ").first || hsh["subject"].to_s.split(" ").first
for_id = for_id.rjust(6, "0")

subject = for_fields.find { |l| l["forId"] == for_id } ||
for_disciplines.find { |l| l["forId"] == for_id[0..3] }
else
subject = for_fields.find { |l| l["forLabel"] == hsh["__content__"] || l["forLabel"] == hsh["subject"] } ||
for_disciplines.find { |l| l["forLabel"] == hsh["__content__"] || l["forLabel"] == hsh["subject"] }
end

if subject
[{
"subject" => sanitize(hsh["__content__"] || hsh["subject"]),
"subjectScheme" => hsh["subjectScheme"],
"classificationCode" => hsh["classificationCode"],
"schemeUri" => hsh["schemeURI"] || hsh["schemeUri"],
"valueUri" => hsh["valueURI"] || hsh["valueUri"],
"lang" => hsh["lang"] }.compact,
{
"subject" => "FOS: " + subject["fosLabel"],
"subjectScheme" => "Fields of Science and Technology (FOS)",
"schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf"
}]
else
[{
"subject" => sanitize(hsh["__content__"] || hsh["subject"]),
"subjectScheme" => hsh["subjectScheme"],
"classificationCode" => hsh["classificationCode"],
"schemeUri" => hsh["schemeURI"] || hsh["schemeUri"],
"valueUri" => hsh["valueURI"] || hsh["valueUri"],
"lang" => hsh["lang"] }.compact]
end
def hsh_to_subject(hsh)
[{
"subject" => sanitize(hsh["__content__"] || hsh["subject"]),
"subjectScheme" => hsh["subjectScheme"],
"classificationCode" => hsh["classificationCode"],
"schemeUri" => hsh["schemeURI"] || hsh["schemeUri"],
"valueUri" => hsh["valueURI"] || hsh["valueUri"],
"lang" => hsh["lang"] }.compact]
end

def dfg_ids_to_fos(dfg_ids)
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bolognese
VERSION = "2.6.1"
VERSION = "2.7.0"
end
5 changes: 3 additions & 2 deletions lib/bolognese/writers/jats_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def insert_publisher_name(xml)
end

def insert_publication_date(xml)
year, month, day = get_date_parts(get_date(dates, "Issued")).to_h.fetch("date-parts", []).first
date = get_date(dates, "Issued") || publication_year
year, month, day = get_date_parts(date).to_h.fetch("date-parts", []).first

xml.year(year, "iso-8601-date" => get_date(dates, "Issued"))
xml.year(year, "iso-8601-date" => date)
xml.month(month.to_s.rjust(2, '0')) if month.present?
xml.day(day.to_s.rjust(2, '0')) if day.present?
end
Expand Down
Loading
Loading