Skip to content

Commit

Permalink
make rightsIdentifier lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 1, 2020
1 parent 379e153 commit 4053577
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 39 deletions.
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 (1.6.8)
bolognese (1.6.9)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down
8 changes: 4 additions & 4 deletions lib/bolognese/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ def name_to_spdx(name)
{
"rights" => license["name"],
"rightsUri" => license["seeAlso"].first,
"rightsIdentifier" => license["licenseId"],
"rightsIdentifier" => license["licenseId"].downcase,
"rightsIdentifierScheme" => "SPDX",
"schemeUri" => "https://spdx.org/licenses/" }.compact
else
Expand All @@ -1115,21 +1115,21 @@ def name_to_spdx(name)

def hsh_to_spdx(hsh)
spdx = JSON.load(File.read(File.expand_path('../../../resources/spdx/licenses.json', __FILE__))).fetch("licenses")
license = spdx.find { |l| l["licenseId"] == hsh["rightsIdentifier"] || l["seeAlso"].first == normalize_cc_url(hsh["rightsURI"]) || l["name"] == hsh["rights"] || l["seeAlso"].first == normalize_cc_url(hsh["rights"]) }
license = spdx.find { |l| l["licenseId"].casecmp?(hsh["rightsIdentifier"]) || l["seeAlso"].first == normalize_cc_url(hsh["rightsURI"]) || l["name"] == hsh["rights"] || l["seeAlso"].first == normalize_cc_url(hsh["rights"]) }

if license
{
"rights" => license["name"],
"rightsUri" => license["seeAlso"].first,
"rightsIdentifier" => license["licenseId"],
"rightsIdentifier" => license["licenseId"].downcase,
"rightsIdentifierScheme" => "SPDX",
"schemeUri" => "https://spdx.org/licenses/",
"lang" => hsh["lang"] }.compact
else
{
"rights" => hsh["__content__"] || hsh["rights"],
"rightsUri" => hsh["rightsURI"] || hsh["rightsUri"],
"rightsIdentifier" => hsh["rightsIdentifier"],
"rightsIdentifier" => hsh["rightsIdentifier"].present? ? hsh["rightsIdentifier"].downcase : nil,
"rightsIdentifierScheme" => hsh["rightsIdentifierScheme"],
"schemeUri" => hsh["schemeUri"],
"lang" => hsh["lang"] }.compact
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 = "1.6.8"
VERSION = "1.6.9"
end
2 changes: 1 addition & 1 deletion spec/datacite_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml| subject.insert_rights_list(xml) }.to_xml
response = Maremma.from_xml(xml)
expect(response.dig("rightsList", "rights")).to eq("__content__" => "Creative Commons Zero v1.0 Universal",
"rightsIdentifier" => "CC0-1.0",
"rightsIdentifier" => "cc0-1.0",
"rightsIdentifierScheme" => "SPDX",
"rightsURI" => "https://creativecommons.org/publicdomain/zero/1.0/legalcode",
"schemeURI" => "https://spdx.org/licenses/")
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/readers/bibtex_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
expect(subject.titles).to eq([{"title"=>"Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth"}])
expect(subject.descriptions.first["description"]).to start_with("Among various advantages, their small size makes model organisms preferred subjects of investigation.")
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution 3.0 Unported",
"rightsIdentifier"=>"CC-BY-3.0",
"rightsIdentifier"=>"cc-by-3.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/3.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down
8 changes: 4 additions & 4 deletions spec/readers/codemeta_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
expect(subject.publication_year).to eq("2017")
expect(subject.publisher).to eq("DataCite")
expect(subject.rights_list).to eq([{"rights"=>"MIT License",
"rightsIdentifier"=>"MIT",
"rightsIdentifier"=>"mit",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://opensource.org/licenses/MIT",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -78,7 +78,7 @@
expect(subject.publication_year).to eq("2016")
expect(subject.publisher).to eq("https://cran.r-project.org")
expect(subject.rights_list).to eq([{"rights"=>"Apache License 2.0",
"rightsIdentifier"=>"Apache-2.0",
"rightsIdentifier"=>"apache-2.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"http://www.apache.org/licenses/LICENSE-2.0",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -107,7 +107,7 @@
expect(subject.publication_year).to eq("2017")
expect(subject.publisher).to eq("DataCite")
expect(subject.rights_list).to eq([{"rights"=>"MIT License",
"rightsIdentifier"=>"MIT",
"rightsIdentifier"=>"mit",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://opensource.org/licenses/MIT",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand All @@ -129,7 +129,7 @@
expect(subject.publication_year).to eq("2018")
expect(subject.publisher).to eq("DataCite")
expect(subject.rights_list).to eq([{"rights"=>"MIT License",
"rightsIdentifier"=>"MIT",
"rightsIdentifier"=>"mit",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://opensource.org/licenses/MIT",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down
8 changes: 4 additions & 4 deletions spec/readers/crossref_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expect(subject.creators.length).to eq(5)
expect(subject.creators.first).to eq("nameType"=>"Personal", "name"=>"Sankar, Martial", "givenName"=>"Martial", "familyName"=>"Sankar", "affiliation" => [{"name"=>"Department of Plant Molecular Biology, University of Lausanne, Lausanne, Switzerland"}])
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution 3.0 Unported",
"rightsIdentifier"=>"CC-BY-3.0",
"rightsIdentifier"=>"cc-by-3.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/3.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -61,7 +61,7 @@
expect(subject.contributors).to eq("contributorType"=>"Editor", "familyName"=>"Janbon", "givenName"=>"Guilhem", "name"=>"Janbon, Guilhem", "nameType"=>"Personal")
expect(subject.titles).to eq([{"title"=>"Triose Phosphate Isomerase Deficiency Is Caused by Altered Dimerization–Not Catalytic Inactivity–of the Mutant Enzymes"}])
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution 4.0 International",
"rightsIdentifier"=>"CC-BY-4.0",
"rightsIdentifier"=>"cc-by-4.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand All @@ -86,7 +86,7 @@
expect(subject.creators.first).to eq("familyName"=>"Fortes", "givenName"=>"Ana Margarida", "name"=>"Fortes, Ana Margarida", "nameType"=>"Personal")
expect(subject.titles).to eq([{"title"=>"Transcriptional Modulation of Polyamine Metabolism in Fruit Species Under Abiotic and Biotic Stress"}])
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution 4.0 International",
"rightsIdentifier"=>"CC-BY-4.0",
"rightsIdentifier"=>"cc-by-4.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -205,7 +205,7 @@
expect(subject.creators.length).to eq(7)
expect(subject.creators[2]).to eq("nameType"=>"Personal", "nameIdentifiers" => [{"nameIdentifier"=>"https://orcid.org/0000-0003-2043-4925", "nameIdentifierScheme"=>"ORCID", "schemeUri"=>"https://orcid.org"}], "name"=>"Hernandez, Beatriz", "givenName"=>"Beatriz", "familyName"=>"Hernandez", "affiliation" => [{"name"=>"War Related Illness and Injury Study Center (WRIISC) and Mental Illness Research Education and Clinical Center (MIRECC), Department of Veterans Affairs, Palo Alto, CA 94304, USA"}, {"name"=>"Department of Psychiatry and Behavioral Sciences, Stanford University School of Medicine, Stanford, CA 94304, USA"}])
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution 3.0 Unported",
"rightsIdentifier"=>"CC-BY-3.0",
"rightsIdentifier"=>"cc-by-3.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/3.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down
20 changes: 10 additions & 10 deletions spec/readers/datacite_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"Ollomo B, Durand P, Prugnolle F, Douzery EJP, Arnathau C, Nkoghe D, Leroy E, Renaud F (2009) A new malaria agent in African hominids. PLoS Pathogens 5(5): e1000446.",
"identifierType"=>"citation"}])
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Zero v1.0 Universal",
"rightsIdentifier"=>"CC0-1.0",
"rightsIdentifier"=>"cc0-1.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/publicdomain/zero/1.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -125,7 +125,7 @@
{"identifier"=>
"https://schema.datacite.org/meta/kernel-4.2/example/datacite-example-full-v4.2.xml",
"identifierType"=>"URL"}])
expect(subject.rights_list).to eq([{"lang"=>"en-US", "rights"=>"Creative Commons Zero v1.0 Universal", "rightsIdentifier"=>"CC0-1.0", "rightsIdentifierScheme"=>"SPDX", "rightsUri"=>"https://creativecommons.org/publicdomain/zero/1.0/legalcode", "schemeUri"=>"https://spdx.org/licenses/"}])
expect(subject.rights_list).to eq([{"lang"=>"en-US", "rights"=>"Creative Commons Zero v1.0 Universal", "rightsIdentifier"=>"cc0-1.0", "rightsIdentifierScheme"=>"SPDX", "rightsUri"=>"https://creativecommons.org/publicdomain/zero/1.0/legalcode", "schemeUri"=>"https://spdx.org/licenses/"}])
expect(subject.publication_year).to eq("2014")
expect(subject.contributors).to eq([{"name"=>"Starr, Joan", "givenName"=>"Joan", "familyName"=>"Starr", "nameIdentifiers"=>[{"nameIdentifier"=>"https://orcid.org/0000-0002-7285-027X", "schemeUri"=>"https://orcid.org", "nameIdentifierScheme"=>"ORCID"}], "affiliation"=>
[{"affiliationIdentifier"=>"https://ror.org/03yrm5c26",
Expand Down Expand Up @@ -199,7 +199,7 @@
expect(subject.descriptions.first["description"]).to start_with("This tools are used to analyse the data produced by the Crosssover Experiment")
expect(subject.rights_list).to eq([{"rights"=>
"Creative Commons Attribution Non Commercial Share Alike 4.0 International",
"rightsIdentifier"=>"CC-BY-NC-SA-4.0",
"rightsIdentifier"=>"cc-by-nc-sa-4.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"},
Expand Down Expand Up @@ -229,7 +229,7 @@
expect(subject.titles).to eq([{"title"=>"RAIN v1"}])
expect(subject.descriptions.first["description"]).to start_with("<b>RAIN: RNA–protein Association and Interaction Networks")
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution 4.0 International",
"rightsIdentifier"=>"CC-BY-4.0",
"rightsIdentifier"=>"cc-by-4.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -264,7 +264,7 @@
expect(subject.titles).to eq([{"title"=>"Drosophila melanogaster African Wings"}])
expect(subject.descriptions.first["description"]).to start_with("These are raw wing images from <i>Drosophila melanogaster</i>")
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution 4.0 International",
"rightsIdentifier"=>"CC-BY-4.0",
"rightsIdentifier"=>"cc-by-4.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -704,7 +704,7 @@
expect(subject.related_identifiers.last).to eq("relatedIdentifier"=>"10.5272/oldertestpub", "relatedIdentifierType"=>"DOI", "relationType"=>"IsPartOf", "resourceTypeGeneral"=>"Text")
expect(subject.rights_list).to eq([{"lang"=>"eng",
"rights"=>"Creative Commons Attribution No Derivatives 2.0 Generic",
"rightsIdentifier"=>"CC-BY-ND-2.0",
"rightsIdentifier"=>"cc-by-nd-2.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by-nd/2.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -733,7 +733,7 @@
expect(subject.related_identifiers.length).to eq(1)
expect(subject.related_identifiers.last).to eq("relatedIdentifier"=>"10.5272/oldertestpub", "relatedIdentifierType"=>"DOI", "relationType"=>"IsPartOf")
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution No Derivatives 2.0 Generic",
"rightsIdentifier"=>"CC-BY-ND-2.0",
"rightsIdentifier"=>"cc-by-nd-2.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by-nd/2.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -762,7 +762,7 @@
expect(subject.related_identifiers.length).to eq(4)
expect(subject.related_identifiers.last).to eq("relatedIdentifier"=>"19478877", "relatedIdentifierType"=>"PMID", "relationType"=>"IsReferencedBy")
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Zero v1.0 Universal",
"rightsIdentifier"=>"CC0-1.0",
"rightsIdentifier"=>"cc0-1.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/publicdomain/zero/1.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -791,7 +791,7 @@
expect(subject.related_identifiers.length).to eq(1)
expect(subject.related_identifiers.last).to eq("relatedIdentifier"=>"10.5272/oldertestpub", "relatedIdentifierType"=>"DOI", "relationType"=>"IsPartOf")
expect(subject.rights_list).to eq([{"rights"=>"Creative Commons Attribution No Derivatives 2.0 Generic",
"rightsIdentifier"=>"CC-BY-ND-2.0",
"rightsIdentifier"=>"cc-by-nd-2.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by-nd/2.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down Expand Up @@ -848,7 +848,7 @@
expect(subject.related_identifiers.last).to eq("relatedIdentifier"=>"10.5272/oldertestpub", "relatedIdentifierType"=>"DOI", "relationType"=>"IsPartOf", "resourceTypeGeneral"=>"Text")
expect(subject.rights_list).to eq([{"lang"=>"eng",
"rights"=>"Creative Commons Attribution No Derivatives 2.0 Generic",
"rightsIdentifier"=>"CC-BY-ND-2.0",
"rightsIdentifier"=>"cc-by-nd-2.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by-nd/2.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down
10 changes: 5 additions & 5 deletions spec/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -512,25 +512,25 @@
it "name_to_spdx exists" do
name = "Creative Commons Attribution 4.0 International"
response = subject.name_to_spdx(name)
expect(response).to eq({"rights"=>"Creative Commons Attribution 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode", "rightsIdentifier"=>"CC-BY-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/"})
expect(response).to eq({"rights"=>"Creative Commons Attribution 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode", "rightsIdentifier"=>"cc-by-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/"})
end

it "name_to_spdx id" do
name = "CC-BY-4.0"
response = subject.name_to_spdx(name)
expect(response).to eq({"rights"=>"Creative Commons Attribution 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode", "rightsIdentifier"=>"CC-BY-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/"})
expect(response).to eq({"rights"=>"Creative Commons Attribution 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode", "rightsIdentifier"=>"cc-by-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/"})
end

it "hsh_to_spdx id" do
hsh = { "rightsIdentifier" => "CC-BY-4.0" }
hsh = { "rightsIdentifier" => "cc-by-4.0" }
response = subject.hsh_to_spdx(hsh)
expect(response).to eq({"rights"=>"Creative Commons Attribution 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode", "rightsIdentifier"=>"CC-BY-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/"})
expect(response).to eq({"rights"=>"Creative Commons Attribution 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by/4.0/legalcode", "rightsIdentifier"=>"cc-by-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/"})
end

it "hsh_to_spdx url" do
hsh = { "rightsURI" => "http://creativecommons.org/licenses/by-nc/4.0/legalcode" }
response = subject.hsh_to_spdx(hsh)
expect(response).to eq("rights"=>"Creative Commons Attribution Non Commercial 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by-nc/4.0/legalcode", "rightsIdentifier"=>"CC-BY-NC-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/")
expect(response).to eq("rights"=>"Creative Commons Attribution Non Commercial 4.0 International", "rightsUri"=>"https://creativecommons.org/licenses/by-nc/4.0/legalcode", "rightsIdentifier"=>"cc-by-nc-4.0", "rightsIdentifierScheme"=>"SPDX", "schemeUri"=>"https://spdx.org/licenses/")
end

it "hsh_to_spdx not found" do
Expand Down
2 changes: 1 addition & 1 deletion spec/writers/crosscite_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
expect(crosscite.fetch("related_identifiers").first).to eq("relatedIdentifier"=>"2050-084X", "relatedIdentifierType"=>"ISSN", "relationType"=>"IsPartOf", "resourceTypeGeneral"=>"Collection")
expect(crosscite.fetch("related_identifiers").last).to eq("relatedIdentifier"=>"10.1038/ncb2764", "relatedIdentifierType"=>"DOI", "relationType"=>"References")
expect(crosscite.fetch("rights_list")).to eq([{"rights"=>"Creative Commons Attribution 3.0 Unported",
"rightsIdentifier"=>"CC-BY-3.0",
"rightsIdentifier"=>"cc-by-3.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/3.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down
2 changes: 1 addition & 1 deletion spec/writers/datacite_json_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
expect(datacite.fetch("relatedIdentifiers").length).to eq(27)
expect(datacite.fetch("relatedIdentifiers").first).to eq("relatedIdentifier"=>"2050-084X", "relatedIdentifierType"=>"ISSN", "relationType"=>"IsPartOf", "resourceTypeGeneral"=>"Collection")
expect(datacite.fetch("rightsList")).to eq([{"rights"=>"Creative Commons Attribution 3.0 Unported",
"rightsIdentifier"=>"CC-BY-3.0",
"rightsIdentifier"=>"cc-by-3.0",
"rightsIdentifierScheme"=>"SPDX",
"rightsUri"=>"https://creativecommons.org/licenses/by/3.0/legalcode",
"schemeUri"=>"https://spdx.org/licenses/"}])
Expand Down
Loading

0 comments on commit 4053577

Please sign in to comment.