Skip to content

Commit

Permalink
Merge pull request #54 from datacite/refactor_update_codemeta
Browse files Browse the repository at this point in the history
Refactor update codemeta
  • Loading branch information
kjgarza authored Feb 7, 2019
2 parents b30baac + d0c818d commit f6898f5
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 7 deletions.
11 changes: 9 additions & 2 deletions lib/bolognese/readers/codemeta_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def read_codemeta(string: nil, **options)
id = Array.wrap(identifiers).first.to_h.fetch("identifier", nil)
doi = Array.wrap(identifiers).find { |r| r["identifierType"] == "DOI" }.to_h.fetch("identifier", nil)

creators = get_authors(from_schema_org_creators(Array.wrap(meta.fetch("agents", nil))))
has_agents = meta.fetch("agents", nil)
authors = has_agents.nil? ? meta.fetch("authors", nil) : has_agents
creators = get_authors(from_schema_org_creators(Array.wrap(authors)))

contributors = get_authors(from_schema_org_contributors(Array.wrap(meta.fetch("editor", nil))))
dates = []
dates << { "date" => meta.fetch("datePublished"), "dateType" => "Issued" } if meta.fetch("datePublished", nil).present?
Expand All @@ -58,12 +61,16 @@ def read_codemeta(string: nil, **options)
{ "subject" => s }
end

has_title = meta.fetch("title", nil)

titles = has_title.nil? ? [{ "title" => meta.fetch("name", nil) }] : [{ "title" => has_title }]

{ "id" => id,
"types" => types,
"identifiers" => identifiers,
"doi" => doi_from_url(doi),
"url" => normalize_id(meta.fetch("codeRepository", nil)),
"titles" => [{ "title" => meta.fetch("title", nil) }],
"titles" => titles,
"creators" => creators,
"contributors" => contributors,
"publisher" => publisher,
Expand Down
4 changes: 2 additions & 2 deletions lib/bolognese/writers/codemeta_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def codemeta
"@id" => normalize_doi(doi),
"identifier" => to_schema_org_identifiers(identifiers),
"codeRepository" => url,
"title" => parse_attributes(titles, content: "title", first: true),
"agents" => creators,
"name" => parse_attributes(titles, content: "title", first: true),
"authors" => creators,
"description" => parse_attributes(descriptions, content: "description", first: true),
"version" => version_info,
"tags" => subjects.present? ? Array.wrap(subjects).map { |k| parse_attributes(k, content: "subject", first: true) } : nil,
Expand Down
86 changes: 86 additions & 0 deletions spec/fixtures/codemeta_v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"@context": "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld",
"@type": "SoftwareSourceCode",
"authors": [{
"@id": "http://orcid.org/0000-0003-0077-4738",
"@type": "person",
"email": "jones@nceas.ucsb.edu",
"name": "Matt Jones",
"affiliation": "NCEAS",
"mustBeCited": true,
"isMaintainer": true,
"isRightsHolder": true,
"role": {
"namespace": "http://www.ngdc.noaa.gov/metadata/published/xsd/schema/resources/Codelist/gmxCodelists.xml#CI_RoleCode",
"roleCode": [
"originator",
"resourceProvider"
]
}
}, {
"@id": "http://orcid.org/0000-0002-2192-403X",
"@type": "person",
"email": "slaughter@nceas.ucsb.edu",
"name": "Peter Slaughter",
"affiliation": "NCEAS",
"mustBeCited": true,
"isMaintainer": false,
"isRightsHolder": false,
"role": {
"namespace": "http://www.ngdc.noaa.gov/metadata/published/xsd/schema/resources/Codelist/gmxCodelists.xml#CI_RoleCode",
"roleCode": "contributor"
}
}, {
"@type": "organization",
"email": "info@ucop.edu",
"name": "University of California, Santa Barbara",
"role": {
"namespace": "http://www.ngdc.noaa.gov/metadata/published/xsd/schema/resources/Codelist/gmxCodelists.xml#CI_RoleCode",
"roleCode": "copyrightHolder"
}
}],
"depends": {
"@type": "URL",
"@value": "https://github.com/ropensci/datapack"
},
"identifier": "http://dx.doi.org/10.5063/F1M61H5X",
"codeRepository": "https://github.com/DataONEorg/rdataone",
"controlledTem": "software",
"datePublished": "2016-05-27",
"dateModified": "2016-05-27",
"dateCreated": "2016-05-27",
"description": "Provides read and write access to data and metadata from the DataONE network of data repositories.Each DataONE repository implements a consistent repository application programming interface. Users call methods in R to access these remote repository functions, such as methods to query the metadata catalog, get access to metadata for particular data packages, and read the data objects from the data repository.Users can also insert and update data objects on repositories that support these methods.",
"downloadLink": "https://cran.r-project.org/src/contrib/dataone_2.0.0.tar.gz",
"funding": "National Science Foundation grant #012345678",
"isAutomatedBuild": false,
"issueTracker": "https://github.com/DataONEorg/rdataone/issues",
"licenseId": "Apache-2.0",
"publisher": "https://cran.r-project.org",
"tags": [
"data sharing",
"data repository",
"DataONE"
],
"name": "R Interface to the DataONE REST API",
"version": "2.0.0",
"uploadedBy": {
"@id": "http://orcid.org/0000-0003-0077-4738",
"@type": "person",
"email": "mbjones@nceas.ucsb.edu",
"name": "Matt Jones"
},
"programmingLanguage": {
"name": "R",
"version": "> 3.1.1",
"URL": "https://www.r-project.org"
},
"readme": "https://github.com/DataONEorg/rdataone/README.md",
"relatedPublications": "ISBN:0201703726",
"relationship": {
"relationshipType": "isPartOf",
"relatedIdentifier": "urn:uuid:F1A0A7AF-ECF3-4C7D-B675-7C6949963995",
"relatedIdentifierType": "UUID"
},
"softwarePaperCitationIdentifiers": "http://doi.org/0000/0000",
"zippedCode": "https://cran.r-project.org/src/contrib/dataone_2.0.0.tar.gz"
}
2 changes: 1 addition & 1 deletion spec/fixtures/maremma/codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"@context": "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld",
"@type": "SoftwareSourceCode",
"@id": "https://doi.org/10.5438/QEG0-3GM3",
"agents": {
"authors": {
"@id": "http://orcid.org/0000-0003-0077-4738",
"@type": "person",
"name": "Martin Fenner",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions spec/writers/codemeta_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@
expect(json["@id"]).to eq("https://doi.org/10.5063/f1m61h5x")
expect(json["@type"]).to eq("SoftwareSourceCode")
expect(json["identifier"]).to eq("@type"=>"PropertyValue", "propertyID"=>"DOI", "value"=>"https://doi.org/10.5063/f1m61h5x")
expect(json["agents"]).to eq([{"name"=>"Jones, Matthew B.; Slaughter, Peter; Nahf, Rob; Boettiger, Carl ; Jones, Chris; Read, Jordan; Walker, Lauren; Hart, Edmund; Chamberlain, Scott"}])
expect(json["title"]).to eq("dataone: R interface to the DataONE network of data repositories")
expect(json["authors"]).to eq([{"name"=>"Jones, Matthew B.; Slaughter, Peter; Nahf, Rob; Boettiger, Carl ; Jones, Chris; Read, Jordan; Walker, Lauren; Hart, Edmund; Chamberlain, Scott"}])
expect(json["name"]).to eq("dataone: R interface to the DataONE network of data repositories")
expect(json["datePublished"]).to eq("2016")
expect(json["publisher"]).to eq("KNB Data Repository")
end

it "SoftwareSourceCode DataCite check codemeta v2" do
input = "https://doi.org/10.5063/f1m61h5x"
subject = Bolognese::Metadata.new(input: input, from: "datacite")
expect(subject.valid?).to be true
json = JSON.parse(subject.codemeta)
expect(json["agents"]).to be_nil
expect(json["title"]).to be_nil
end
end
end
10 changes: 10 additions & 0 deletions spec/writers/crosscite_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@
expect(crosscite["version"]).to eq("2.0.0")
end

it "rdataone codemeta v2" do
input = fixture_path + 'codemeta_v2.json'
subject = Bolognese::Metadata.new(input: input, from: "codemeta")
crosscite = JSON.parse(subject.crosscite)
expect(crosscite["titles"]).to eq([{"title"=>"R Interface to the DataONE REST API"}])
expect(crosscite["creators"].length).to eq(3)
expect(crosscite["creators"].last).to eq("nameType" => "Organizational", "name"=>"University Of California, Santa Barbara")
expect(crosscite["version"]).to eq("2.0.0")
end

it "datacite database attributes" do
input = "https://doi.org/10.5061/DRYAD.8515"
subject = Bolognese::Metadata.new(input: input, from: "datacite")
Expand Down
22 changes: 22 additions & 0 deletions spec/writers/datacite_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@
expect(datacite.fetch("version")).to eq("2.0.0")
end

it "rdataone and codemeta_v2" do
input = fixture_path + 'codemeta_v2.json'
subject = Bolognese::Metadata.new(input: input, from: "codemeta")
expect(subject.valid?).to be true
datacite = Maremma.from_xml(subject.datacite).fetch("resource", {})
expect(datacite.dig("titles", "title")).to eq("R Interface to the DataONE REST API")
expect(datacite.dig("creators", "creator")).to eq([{"creatorName"=>{"__content__"=>"Jones, Matt", "nameType"=>"Personal"},
"givenName"=>"Matt",
"familyName"=>"Jones",
"nameIdentifier"=>
{"nameIdentifierScheme"=>"ORCID",
"__content__"=>"https://orcid.org/0000-0003-0077-4738"}},
{"creatorName"=>{"__content__"=>"Slaughter, Peter", "nameType"=>"Personal"},
"givenName"=>"Peter",
"familyName"=>"Slaughter",
"nameIdentifier"=>
{"nameIdentifierScheme"=>"ORCID",
"__content__"=>"https://orcid.org/0000-0002-2192-403X"}},
{"creatorName"=>{"__content__"=>"University Of California, Santa Barbara", "nameType"=>"Organizational"}}])
expect(datacite.fetch("version")).to eq("2.0.0")
end

it "maremma" do
input = "https://github.com/datacite/maremma"
subject = Bolognese::Metadata.new(input: input, from: "codemeta")
Expand Down

0 comments on commit f6898f5

Please sign in to comment.