From 489fe5339ef3e93c1f19401fc7d2f4d9a367dbd4 Mon Sep 17 00:00:00 2001 From: Stefan Bringuier Date: Fri, 7 Apr 2023 11:37:07 -0700 Subject: [PATCH 1/5] Fallback support for failed metadata retrieval (Fixes #13). --- src/doi.jl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/doi.jl b/src/doi.jl index 4f167f6..4e99dc5 100644 --- a/src/doi.jl +++ b/src/doi.jl @@ -59,13 +59,26 @@ function Base.show(io::IO, ::MIME"text/html", dois::Array{T} where {T<:AbstractD print(io, "") end +""" + meta-data structure from API: https://w3id.org/oc/meta/api/v1/metadata/ +""" function metadata_template(doi::String) + fields = (:publisher, :pub_date, :page, :venue, :issue, :editor, :author, :id, :volume, :title, :type) + r1 = Dict(f=>"\u0000" for f in fields) + r1[:id] = doi + return r1 +end + @memoize function fetch_metadata(doi::AbstractDOI) fetch_metadata(doi.doi) end @memoize function fetch_metadata(doi) r = HTTP.get("https://w3id.org/oc/meta/api/v1/metadata/doi:$(doi)") rj = JSON3.read(r.body) - return rj[1] + if isempty(rj) + return metadata_template(doi) + else + return rj[1] + end end fetch_citation_count(doi::AbstractDOI) = fetch_citation_count(doi.doi) @memoize function fetch_citation_count(doi) @@ -130,5 +143,5 @@ function strip(s) return replace(s, r" \[(.*?)\]" => "") end function year(s) - return parse(Int, first(s, 4)) + return !isempty(s) ? parse(Int, first(s, 4)) : "\u0000" end From eda6487f9c805907bd274f0b612ed6c4311e72f5 Mon Sep 17 00:00:00 2001 From: Stefan Bringuier Date: Sun, 9 Apr 2023 00:22:11 -0700 Subject: [PATCH 2/5] Add null case and change return value. --- src/doi.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/doi.jl b/src/doi.jl index 4e99dc5..e92097b 100644 --- a/src/doi.jl +++ b/src/doi.jl @@ -61,11 +61,12 @@ end """ meta-data structure from API: https://w3id.org/oc/meta/api/v1/metadata/ -""" function metadata_template(doi::String) +""" +function metadata_template(doi::String) fields = (:publisher, :pub_date, :page, :venue, :issue, :editor, :author, :id, :volume, :title, :type) - r1 = Dict(f=>"\u0000" for f in fields) - r1[:id] = doi - return r1 + rj = Dict(f => "\u0000" for f in fields) + rj[:id] = doi + return rj end @memoize function fetch_metadata(doi::AbstractDOI) @@ -119,7 +120,7 @@ end function emph_author(doi::EmDOI) emph_author(strip(doi.author), doi.highlight) end -function emph_author(authors, author = "", em = "b") +function emph_author(authors, author="", em="b") orcid = r", \d{4}-\d{4}-\d{4}-\d{4}" authors = replace(authors, orcid => "") if length(author) > 2 @@ -142,6 +143,7 @@ end function strip(s) return replace(s, r" \[(.*?)\]" => "") end + function year(s) - return !isempty(s) ? parse(Int, first(s, 4)) : "\u0000" + return !isempty(s) && s != "\0" ? parse(Int, first(s, 4)) : nothing end From c9d7d9c4c0aebc6790283160479afcb502d33620 Mon Sep 17 00:00:00 2001 From: Stefan Bringuier Date: Sun, 9 Apr 2023 00:24:49 -0700 Subject: [PATCH 3/5] Fix nothing return value on year. --- src/doi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doi.jl b/src/doi.jl index e92097b..1c85afa 100644 --- a/src/doi.jl +++ b/src/doi.jl @@ -145,5 +145,5 @@ function strip(s) end function year(s) - return !isempty(s) && s != "\0" ? parse(Int, first(s, 4)) : nothing + return !isempty(s) && s != "\0" ? parse(Int, first(s, 4)) : s end From 533fa1ebf653fe36de66d66cb6750e1d1de8246f Mon Sep 17 00:00:00 2001 From: Stefan Bringuier Date: Fri, 9 Jun 2023 08:31:38 -0700 Subject: [PATCH 4/5] Return empty string. --- src/doi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doi.jl b/src/doi.jl index 1c85afa..0a3ebfe 100644 --- a/src/doi.jl +++ b/src/doi.jl @@ -145,5 +145,5 @@ function strip(s) end function year(s) - return !isempty(s) && s != "\0" ? parse(Int, first(s, 4)) : s + return !isempty(s) && s != "" ? parse(Int, first(s, 4)) : s end From d1ea57e15ee6666f69336e48cafe10ad65b05b43 Mon Sep 17 00:00:00 2001 From: hellemo Date: Sun, 1 Oct 2023 11:33:31 +0200 Subject: [PATCH 5/5] use empty string --- src/doi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doi.jl b/src/doi.jl index 0a3ebfe..7fbc6a2 100644 --- a/src/doi.jl +++ b/src/doi.jl @@ -64,7 +64,7 @@ end """ function metadata_template(doi::String) fields = (:publisher, :pub_date, :page, :venue, :issue, :editor, :author, :id, :volume, :title, :type) - rj = Dict(f => "\u0000" for f in fields) + rj = Dict(f => "" for f in fields) rj[:id] = doi return rj end