Skip to content

Commit

Permalink
support crossref report type
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 30, 2020
1 parent fc51c74 commit f1f464e
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 22 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.8.4)
bolognese (1.8.5)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down
28 changes: 20 additions & 8 deletions lib/bolognese/readers/crossref_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def read_crossref(string: nil, **options)
end

# model should be one of book, conference, database, dissertation, journal, peer_review, posted_content,
# report-paper, sa_component, standard
# report_paper, sa_component, standard
model = meta.dig("crossref").to_h.keys.last

resource_type = nil
Expand Down Expand Up @@ -82,6 +82,9 @@ def read_crossref(string: nil, **options)
when "database"
bibliographic_metadata = meta.dig("crossref", "database", "dataset").to_h
resource_type = "dataset"
when "report_paper"
bibliographic_metadata = meta.dig("crossref", "report_paper", "report_paper_metadata").to_h
resource_type = "report"
end

resource_type = (resource_type || model).to_s.underscore.camelcase.presence
Expand Down Expand Up @@ -156,7 +159,7 @@ def read_crossref(string: nil, **options)
end

id = normalize_doi(options[:doi] || options[:id] || bibliographic_metadata.dig("doi_data", "doi"))
identifiers = [crossref_alternate_identifiers(bibliographic_metadata)].compact
identifiers = crossref_alternate_identifiers(bibliographic_metadata)

{ "id" => id,
"types" => types,
Expand Down Expand Up @@ -187,14 +190,23 @@ def read_crossref(string: nil, **options)

def crossref_alternate_identifiers(bibliographic_metadata)
if bibliographic_metadata.dig("publisher_item", "item_number").present?
{ "identifier" => parse_attributes(bibliographic_metadata.dig("publisher_item", "item_number")),
"identifierType" => "Publisher ID" }
Array.wrap(bibliographic_metadata.dig("publisher_item", "item_number")).map do |item|
if item.is_a?(String)
{ "identifier" => item,
"identifierType" => "Publisher ID" }
else
{ "identifier" => item.fetch("__content__", nil),
"identifierType" => item.fetch("item_number_type", nil) || "Publisher ID" }
end
end
elsif parse_attributes(bibliographic_metadata.fetch("item_number", nil)).present?
{ "identifier" => parse_attributes(bibliographic_metadata.fetch("item_number", nil)),
"identifierType" => "Publisher ID" }
[{ "identifier" => parse_attributes(bibliographic_metadata.fetch("item_number", nil)),
"identifierType" => "Publisher ID" }]
elsif parse_attributes(bibliographic_metadata.fetch("isbn", nil)).present?
{ "identifier" => parse_attributes(bibliographic_metadata.fetch("isbn", nil), first: true),
"identifierType" => "ISBN" }
[{ "identifier" => parse_attributes(bibliographic_metadata.fetch("isbn", nil), first: true),
"identifierType" => "ISBN" }]
else
[]
end
end

Expand Down
11 changes: 7 additions & 4 deletions lib/bolognese/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module Utils
"EditedBook" => "Book",
"JournalArticle" => "ScholarlyArticle",
"Journal" => nil,
"Report" => nil,
"Report" => "Report",
"BookSeries" => nil,
"ReportSeries" => nil,
"BookTrack" => nil,
Expand Down Expand Up @@ -146,7 +146,7 @@ module Utils
"EditedBook" => "book",
"JournalArticle" => "article",
"Journal" => nil,
"Report" => nil,
"Report" => "techreport",
"BookSeries" => nil,
"ReportSeries" => nil,
"BookTrack" => nil,
Expand Down Expand Up @@ -214,6 +214,7 @@ module Utils
"ImageObject" => "Image",
"Movie" => "Audiovisual",
"PublicationIssue" => "Text",
"Report" => "Text",
"ScholarlyArticle" => "Text",
"Thesis" => "Text",
"Service" => "Service",
Expand Down Expand Up @@ -258,6 +259,7 @@ module Utils
"ImageObject" => "graphic",
"Movie" => "motion_picture",
"PublicationIssue" => nil,
"Report" => "report",
"ScholarlyArticle" => "article-journal",
"Service" => nil,
"Thesis" => "thesis",
Expand All @@ -278,6 +280,7 @@ module Utils
"Event" => nil,
"ImageObject" => "FIGURE",
"Movie" => "MPCT",
"Report" => "RPRT",
"PublicationIssue" => nil,
"ScholarlyArticle" => "JOUR",
"Service" => nil,
Expand All @@ -298,11 +301,11 @@ module Utils
"EditedBook" => "BOOK",
"JournalArticle" => "JOUR",
"Journal" => nil,
"Report" => nil,
"Report" => "RPRT",
"BookSeries" => nil,
"ReportSeries" => nil,
"BookTrack" => nil,
"Standard" => nil,
"Standard" => "STAND",
"BookSection" => "CHAP",
"BookPart" => "CHAP",
"Book" => "BOOK",
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.8.4"
VERSION = "1.8.5"
end

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

29 changes: 24 additions & 5 deletions spec/readers/crossref_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
it "DOI with data citation" do
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.7554/elife.01567")
expect(subject.identifiers).to eq([{"identifier"=>"e01567", "identifierType"=>"Publisher ID"}])
expect(subject.identifiers).to eq([{"identifier"=>"e01567", "identifierType"=>"article_number"}])
expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"JournalArticle", "resourceTypeGeneral"=>"Text", "ris"=>"JOUR", "schemaOrg"=>"ScholarlyArticle")
expect(subject.url).to eq("https://elifesciences.org/articles/01567")
expect(subject.creators.length).to eq(5)
Expand Down Expand Up @@ -82,7 +82,7 @@
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.3389/fpls.2019.00816")
expect(subject.identifiers).to eq([{"identifier"=>"816", "identifierType"=>"Publisher ID"}])
expect(subject.identifiers).to eq([{"identifier"=>"816", "identifierType"=>"article_number"}])
expect(subject.url).to eq("https://www.frontiersin.org/article/10.3389/fpls.2019.00816/full")
expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"JournalArticle", "resourceTypeGeneral"=>"Text", "ris"=>"JOUR", "schemaOrg"=>"ScholarlyArticle")
expect(subject.creators.length).to eq(4)
Expand Down Expand Up @@ -229,7 +229,7 @@
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.1016/j.ejphar.2015.03.018")
expect(subject.identifiers).to eq([{"identifier"=>"S0014299915002332", "identifierType"=>"Publisher ID"}])
expect(subject.identifiers).to eq([{"identifier"=>"S0014299915002332", "identifierType"=>"sequence-number"}])
expect(subject.url).to eq("https://linkinghub.elsevier.com/retrieve/pii/S0014299915002332")
expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"JournalArticle", "resourceTypeGeneral"=>"Text", "ris"=>"JOUR", "schemaOrg"=>"ScholarlyArticle")
expect(subject.creators.length).to eq(10)
Expand Down Expand Up @@ -433,7 +433,7 @@
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.3280/ecag2018-001005")
expect(subject.identifiers).to eq([{"identifier"=>"5", "identifierType"=>"Publisher ID"}])
expect(subject.identifiers).to eq([{"identifier"=>"5", "identifierType"=>"article_number"}])
expect(subject.url).to eq("http://www.francoangeli.it/riviste/Scheda_Riviste.asp?IDArticolo=61645")
expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"JournalArticle", "resourceTypeGeneral"=>"Text", "ris"=>"JOUR", "schemaOrg"=>"ScholarlyArticle")
expect(subject.creators.length).to eq(2)
Expand Down Expand Up @@ -547,7 +547,7 @@
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.1055/s-0039-1690894")
expect(subject.identifiers).to eq([{"identifier"=>"s-0039-1690894", "identifierType"=>"Publisher ID"}])
expect(subject.identifiers).to eq([{"identifier"=>"s-0039-1690894", "identifierType"=>"sequence-number"}])
expect(subject.url).to eq("http://www.thieme-connect.de/DOI/DOI?10.1055/s-0039-1690894")
expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"JournalArticle", "resourceTypeGeneral"=>"Text", "ris"=>"JOUR", "schemaOrg"=>"ScholarlyArticle")
expect(subject.creators.length).to eq(4)
Expand Down Expand Up @@ -643,6 +643,25 @@
expect(subject.agency).to eq("crossref")
end

it "report osti" do
input = "10.2172/972169"
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.url).to eq("http://www.osti.gov/servlets/purl/972169-1QXROM/")
expect(subject.types).to eq("bibtex"=>"techreport", "citeproc"=>"report", "resourceType"=>"Report", "resourceTypeGeneral"=>"Text", "ris"=>"RPRT", "schemaOrg"=>"Report")
expect(subject.creators.count).to eq(4)
expect(subject.creators.first).to eq("familyName"=>"Denholm", "givenName"=>"P.", "name"=>"Denholm, P.", "nameType"=>"Personal")
expect(subject.contributors.count).to eq(0)
expect(subject.titles).to eq([{"title"=>"Role of Energy Storage with Renewable Electricity Generation"}])
expect(subject.id).to eq("https://doi.org/10.2172/972169")
expect(subject.identifiers).to eq( [{"identifier"=>"NREL/TP-6A2-47187", "identifierType"=>"report-number"}, {"identifier"=>"972169", "identifierType"=>"sequence-number"}])
expect(subject.descriptions).to be_empty
expect(subject.dates).to include({"date"=>"2010-01-01", "dateType"=>"Issued"})
expect(subject.publication_year).to eq("2010")
expect(subject.publisher).to eq("Office of Scientific and Technical Information (OSTI)")
expect(subject.agency).to eq("crossref")
end

it "journal issue" do
input = "https://doi.org/10.6002/ect.2015.0371"
subject = Bolognese::Metadata.new(input: input)
Expand Down
6 changes: 3 additions & 3 deletions spec/writers/datacite_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@
input = "10.7554/eLife.01567"
subject = Bolognese::Metadata.new(input: input, from: "crossref")
expect(subject.valid?).to be true
expect(subject.identifiers).to eq( [{"identifier"=>"e01567", "identifierType"=>"Publisher ID"}])
subject.identifiers = [{ "identifierType" => "Publisher ID", "identifier" => "abc" }]
expect(subject.identifiers).to eq([{"identifier"=>"e01567", "identifierType"=>"article_number"}])
subject.identifiers = [{ "identifierType" => "article_number", "identifier" => "abc" }]
datacite = Maremma.from_xml(subject.datacite).fetch("resource", {})
expect(datacite.dig("identifier", "__content__")).to eq("10.7554/elife.01567")
expect(subject.identifiers).to eq([{"identifier"=>"abc", "identifierType"=>"Publisher ID"}])
expect(subject.identifiers).to eq([{"identifier"=>"abc", "identifierType"=>"article_number"}])
end

it "validates against schema" do
Expand Down

0 comments on commit f1f464e

Please sign in to comment.