Skip to content

Commit

Permalink
include article_id if no pages present. crosscite/content-negotiation#96
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 13, 2020
1 parent de62bd1 commit b122b37
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 14 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.12)
bolognese (1.8.13)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down
3 changes: 1 addition & 2 deletions lib/bolognese/readers/crossref_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def read_crossref(string: nil, **options)
journal_article = meta.dig("crossref", "journal", "journal_article") || {}
bibliographic_metadata = journal_article.presence || journal_issue.presence || journal_metadata
program_metadata = bibliographic_metadata.dig("crossmark", "custom_metadata", "program") || bibliographic_metadata.dig("program")

resource_type = if journal_article.present?
"journal_article"
elsif journal_issue.present?
Expand Down Expand Up @@ -150,7 +149,7 @@ def read_crossref(string: nil, **options)
"title" => parse_attributes(journal_metadata.to_h["full_title"]),
"volume" => parse_attributes(journal_issue.dig("journal_volume", "volume")),
"issue" => parse_attributes(journal_issue.dig("issue")),
"firstPage" => bibliographic_metadata.dig("pages", "first_page"),
"firstPage" => bibliographic_metadata.dig("pages", "first_page") || parse_attributes(journal_article.to_h.dig("publisher_item", "item_number"), first: true),
"lastPage" => bibliographic_metadata.dig("pages", "last_page") }.compact
elsif book_series_metadata.to_h.fetch("series_metadata", nil).present?
issn = normalize_issn(book_series_metadata.dig("series_metadata", "issn"))
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.12"
VERSION = "1.8.13"
end
2 changes: 1 addition & 1 deletion lib/bolognese/writers/bibtex_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module BibtexWriter
def bibtex
return nil unless valid?

pages = container.to_h["firstPage"].present? ? [container["firstPage"], container["lastPage"]].join("-") : nil
pages = container.to_h["firstPage"].present? ? [container["firstPage"], container["lastPage"]].compact.join("-") : nil

bib = {
bibtex_type: types["bibtex"].presence || "misc",
Expand Down

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions spec/readers/crossref_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
expect(subject.dates).to eq([{"date"=>"2014-02-11", "dateType"=>"Issued"}, {"date"=>"2018-08-23T13:41:49Z", "dateType"=>"Updated"}])
expect(subject.publication_year).to eq("2014")
expect(subject.publisher).to eq("eLife Sciences Publications, Ltd")
expect(subject.container).to eq("identifier"=>"2050-084X", "identifierType"=>"ISSN", "title"=>"eLife", "type"=>"Journal", "volume"=>"3")
expect(subject.container).to eq("firstPage" => "e01567", "identifier"=>"2050-084X", "identifierType"=>"ISSN", "title"=>"eLife", "type"=>"Journal", "volume"=>"3")
expect(subject.related_identifiers.length).to eq(27)
expect(subject.related_identifiers.first).to eq("relatedIdentifier"=>"2050-084X", "relatedIdentifierType"=>"ISSN", "relationType"=>"IsPartOf", "resourceTypeGeneral"=>"Collection")
expect(subject.related_identifiers.last).to eq("relatedIdentifier"=>"10.1038/ncb2764", "relatedIdentifierType"=>"DOI", "relationType"=>"References")
Expand Down Expand Up @@ -100,7 +100,7 @@
expect(subject.related_identifiers.length).to eq(70)
expect(subject.related_identifiers.first).to eq("relatedIdentifier"=>"1664-462X", "relatedIdentifierType"=>"ISSN", "relationType"=>"IsPartOf", "resourceTypeGeneral"=>"Collection")
expect(subject.related_identifiers.last).to eq("relatedIdentifier"=>"10.17660/actahortic.2004.632.41", "relatedIdentifierType"=>"DOI", "relationType"=>"References")
expect(subject.container).to eq("identifier"=>"1664-462X", "identifierType"=>"ISSN", "title"=>"Frontiers in Plant Science", "type"=>"Journal", "volume"=>"10")
expect(subject.container).to eq("firstPage" => "816", "identifier"=>"1664-462X", "identifierType"=>"ISSN", "title"=>"Frontiers in Plant Science", "type"=>"Journal", "volume"=>"10")
expect(subject.agency).to eq("crossref")
end

Expand Down Expand Up @@ -718,6 +718,24 @@
expect(subject.date_registered).to eq("2012-10-31T16:15:44Z")
end

it "article id as page number" do
input = "https://doi.org/10.1103/physrevlett.120.117701"
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.1103/physrevlett.120.117701")
expect(subject.url).to eq("https://link.aps.org/doi/10.1103/PhysRevLett.120.117701")
expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"JournalArticle", "resourceTypeGeneral"=>"Text", "ris"=>"JOUR", "schemaOrg"=>"ScholarlyArticle")
expect(subject.creators.length).to eq(5)
expect(subject.creators.first).to eq("familyName"=>"Marrazzo", "givenName"=>"Antimo", "name"=>"Marrazzo, Antimo", "nameType"=>"Personal")
expect(subject.titles).to eq([{"title"=>"Prediction of a Large-Gap and Switchable Kane-Mele Quantum Spin Hall Insulator"}])
expect(subject.dates).to include({"date"=>"2018-03-13", "dateType"=>"Issued"})
expect(subject.publication_year).to eq("2018")
expect(subject.publisher).to eq("American Physical Society (APS)")
expect(subject.container).to eq("firstPage" => "117701", "identifier"=>"1079-7114", "identifierType"=>"ISSN", "issue"=>"11", "title"=>"Physical Review Letters", "type"=>"Journal", "volume"=>"120")
expect(subject.agency).to eq("crossref")
expect(subject.date_registered).to eq("2018-03-13T15:18:48Z")
end

it "posted content copernicus" do
input = "https://doi.org/10.5194/CP-2020-95"
subject = Bolognese::Metadata.new(input: input)
Expand Down
2 changes: 1 addition & 1 deletion spec/writers/bibtex_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.3204/desy-2014-01645")
expect(bibtex[:doi]).to eq("10.3204/desy-2014-01645")
expect(bibtex[:title]).to eq("Dynamics of colloids in molecular glass forming liquids studied via X-ray photon correlation spectroscopy")
expect(bibtex[:pages]).to eq("2014-")
expect(bibtex[:pages]).to eq("2014")
expect(bibtex[:year]).to eq("2014")
end

Expand Down
4 changes: 2 additions & 2 deletions spec/writers/citation_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
subject = Bolognese::Metadata.new(input: input, from: "crossref")
expect(subject.style).to eq("apa")
expect(subject.locale).to eq("en-US")
expect(subject.citation).to eq("Sankar, M., Nieminen, K., Ragni, L., Xenarios, I., &amp; Hardtke, C. S. (2014). Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth. <i>ELife</i>, <i>3</i>. https://doi.org/10.7554/elife.01567")
expect(subject.citation).to eq("Sankar, M., Nieminen, K., Ragni, L., Xenarios, I., &amp; Hardtke, C. S. (2014). Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth. <i>ELife</i>, <i>3</i>, e01567. https://doi.org/10.7554/elife.01567")
end

it "Journal article vancouver style" do
input = "10.7554/eLife.01567"
subject = Bolognese::Metadata.new(input: input, from: "crossref", style: "vancouver", locale: "en-US")
expect(subject.style).to eq("vancouver")
expect(subject.locale).to eq("en-US")
expect(subject.citation).to eq("Sankar M, Nieminen K, Ragni L, Xenarios I, Hardtke CS. Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth. eLife [Internet]. 2014Feb11;3. Available from: https://elifesciences.org/articles/01567")
expect(subject.citation).to eq("Sankar M, Nieminen K, Ragni L, Xenarios I, Hardtke CS. Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth. eLife [Internet]. 2014Feb11;3:e01567. Available from: https://elifesciences.org/articles/01567")
end

it "Dataset" do
Expand Down
2 changes: 1 addition & 1 deletion spec/writers/datacite_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
subject.descriptions = { "description" => "This is an abstract." }
expect(subject.valid?).to be true
datacite = Maremma.from_xml(subject.datacite).fetch("resource", {})
expect(datacite.dig("descriptions", "description")).to eq( [{"__content__"=>"eLife, 3", "descriptionType"=>"SeriesInformation"}, {"__content__"=>"This is an abstract.", "descriptionType"=>"Abstract"}])
expect(datacite.dig("descriptions", "description")).to eq([{"__content__"=>"eLife, 3, e01567", "descriptionType"=>"SeriesInformation"}, {"__content__"=>"This is an abstract.", "descriptionType"=>"Abstract"}])
end

it "change description no input" do
Expand Down
5 changes: 3 additions & 2 deletions spec/writers/ris_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
expect(ris[11]).to eq("PY - 2014")
expect(ris[12]).to eq("PB - eLife Sciences Publications, Ltd")
expect(ris[13]).to eq("VL - 3")
expect(ris[14]).to eq("SN - 2050-084X")
expect(ris[15]).to eq("ER - ")
expect(ris[14]).to eq("SP - e01567")
expect(ris[15]).to eq("SN - 2050-084X")
expect(ris[16]).to eq("ER - ")
end

it "with pages" do
Expand Down
2 changes: 1 addition & 1 deletion spec/writers/schema_org_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
expect(json["@id"]).to eq("https://doi.org/10.7554/elife.01567")
expect(json["@type"]).to eq("ScholarlyArticle")
expect(json["isPartOf"]).to eq("@type"=>"Periodical", "issn"=>"2050-084X")
expect(json["periodical"]).to eq("@type"=>"Journal", "identifier"=>"2050-084X", "identifierType"=>"ISSN", "name"=>"eLife", "volume"=>"3")
expect(json["periodical"]).to eq("@type"=>"Journal", "firstPage" => "e01567", "identifier"=>"2050-084X", "identifierType"=>"ISSN", "name"=>"eLife", "volume"=>"3")
expect(json["citation"].length).to eq(26)
expect(json["citation"].first).to eq("@id"=>"https://doi.org/10.1038/nature02100", "@type"=>"CreativeWork")
expect(json["funder"]).to eq([{"name"=>"SystemsX", "@type"=>"Organization"},
Expand Down

0 comments on commit b122b37

Please sign in to comment.