From 3aad3cb73567c8f86fb1727d32296612b5836928 Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Wed, 13 Jun 2018 01:53:59 +0530 Subject: [PATCH 1/4] Add DataCite API --- src/DataCite.jl | 52 +++++++++++++++++++++++++ src/DataDepsGenerators.jl | 10 +++++ test/DataCite.jl | 9 +++++ test/references/DataCite Ceramic.txt | 20 ++++++++++ test/references/DataCite Fire Patch.txt | 30 ++++++++++++++ test/runtests.jl | 1 + 6 files changed, 122 insertions(+) create mode 100644 src/DataCite.jl create mode 100644 test/DataCite.jl create mode 100644 test/references/DataCite Ceramic.txt create mode 100644 test/references/DataCite Fire Patch.txt diff --git a/src/DataCite.jl b/src/DataCite.jl new file mode 100644 index 0000000..164e858 --- /dev/null +++ b/src/DataCite.jl @@ -0,0 +1,52 @@ +struct DataCite <: DataRepo +end + +function description(repo::DataCite, mainpage) + attributes = mainpage["attributes"] + desc = attributes["description"] + authors = join.([[names[2] for names in value] for value in attributes["author"]], " ") + author = format_authors(authors) + license = attributes["license"] + date = attributes["published"] + paper = format_papers(authors, date, attributes["title"] * " [Data set]. " * attributes["container-title"] * ".", mainpage["id"]) + + final = escape_multiline_string(""" + Author: $(author) + License: $(license) + Date: $(date) + + $(desc) + + Please cite this paper: + $(paper) + if you use this in your research. + + """, "\$") +end + +function get_urls(repo::DataCite, page) + urls = [] + urls +end + +function get_checksums(repo::DataCite, page) + nothing +end + +function data_fullname(::DataCite, mainpage) + mainpage["attributes"]["title"] +end + +function website(repo::DataCite, mainpage_url) + replace(mainpage_url, "https://api.datacite.org/works/", "https://doi.org/") +end + +function mainpage_url(repo::DataCite, dataname) + try + identifier = match(r"\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?![\"&\'<>])\S)+)\b", dataname).match + url = "https://api.datacite.org/works/" * identifier + JSON.parse(text_only(getpage(url).root))["data"], url + catch ErrorException + error("Please use a valid url") + end +end \ No newline at end of file diff --git a/src/DataDepsGenerators.jl b/src/DataDepsGenerators.jl index 97a7eda..628450f 100644 --- a/src/DataDepsGenerators.jl +++ b/src/DataDepsGenerators.jl @@ -3,7 +3,11 @@ using Gumbo, Cascadia, AbstractTrees using Suppressor using JSON +<<<<<<< HEAD export generate, UCI, GitHub, DataDryad, DataOneV1, DataOneV2, CKAN +======= +export generate, UCI, GitHub, DataDryadWeb, DataDryadAPI, DataOneV2, CKAN, DataCite +>>>>>>> Add DataCite API abstract type DataRepo end @@ -38,6 +42,7 @@ include("DataDryad.jl") include("DataOneV1.jl") include("DataOneV2/DataOneV2.jl") include("CKAN.jl") +include("DataCite.jl") function message(meta) @@ -108,6 +113,11 @@ function format_authors(authors::Vector) end end +function format_papers(authors::Vector, year::String, name::String, link::String) + #APA format. Other formats can be included here later. + join(authors, ", ") * " ($year). " * name * " " * link +end + website(::DataRepo, mainpage_url) = mainpage_url function mainpage_url(repo::DataRepo, dataname) diff --git a/test/DataCite.jl b/test/DataCite.jl new file mode 100644 index 0000000..9f2d20d --- /dev/null +++ b/test/DataCite.jl @@ -0,0 +1,9 @@ +using DataDepsGenerators +using Base.Test + +using ReferenceTests + +@testset "DataCite test" begin + @test_reference "references/DataCite Fire Patch.txt" generate(DataCite(), "https://search.datacite.org/works/10.15148/0e999ffc-e220-41ac-ac85-76e92ecd0320") + @test_reference "references/DataCite Ceramic.txt" generate(DataCite(), "10.5281/zenodo.1147572") +end \ No newline at end of file diff --git a/test/references/DataCite Ceramic.txt b/test/references/DataCite Ceramic.txt new file mode 100644 index 0000000..bb64e83 --- /dev/null +++ b/test/references/DataCite Ceramic.txt @@ -0,0 +1,20 @@ +register(DataDep( + "Study Of Surface Roughness With The Variation In Applied Load Of Rutile Ceramic Reinforced Aluminium Composite", + """ + Dataset: Study Of Surface Roughness With The Variation In Applied Load Of Rutile Ceramic Reinforced Aluminium Composite + Website: https://doi.org/10.5281/zenodo.1147572 + Author: Rama Arora + License: https://creativecommons.org/licenses/by/4.0/ + Date: 2018 + + The objective of this work is to study the surface roughness of LM13alloy composites with rutile particles .The fabrication route adopted for preparing the samples containing variable ratio of rutile reinforcement is simple vortex technique. The wear tests were carried out under different loading conditions from 9.8N to 49N. The pin specimen travelled a distance of 3000m at constant sliding speed on the hard steel disc. The addition of fine size rutile particles results in higher hardness and strength. The stress concentration at the voids due to weak interfaces leads to crack intitation, arising from the particle fracture .This can be avoided by providing more strength to the matrix which is achieved by introducing hard ceramic rutile particulates. As the soft matrix aluminium alloy is prone to scratches and indentation during the contact sliding conditions, study of surface roughness of composite after wear studies need significant attention. + + Please cite this paper: + Rama Arora (2018). Study Of Surface Roughness With The Variation In Applied Load Of Rutile Ceramic Reinforced Aluminium Composite [Data set]. Zenodo. https://doi.org/10.5281/zenodo.1147572 + if you use this in your research. + + + """, + Any[], + +)) diff --git a/test/references/DataCite Fire Patch.txt b/test/references/DataCite Fire Patch.txt new file mode 100644 index 0000000..df7f970 --- /dev/null +++ b/test/references/DataCite Fire Patch.txt @@ -0,0 +1,30 @@ +register(DataDep( + "List of fire patch properties computed and associated NetCDF maps from the MCD64A1 Collection 6 (2000-2016) and the MERIS fire_cci v4.1 (2005-2011) BA products", + """ + Dataset: List of fire patch properties computed and associated NetCDF maps from the MCD64A1 Collection 6 (2000-2016) and the MERIS fire_cci v4.1 (2005-2011) BA products + Website: https://doi.org/10.15148/0e999ffc-e220-41ac-ac85-76e92ecd0320 + Author: Pierre Laurent et al. + License: nothing + Date: 2018 + + Fire patches computed from the MCD64A1 Collection 6 and the MERIS fire_cci v4.1 (2005-2011) burned area + datasets. A flood-filling algorithm with a fixed cut-off parameter has been used to group burned pixels into + fire patches. The listed morphological properties in the csv files are (in order of appearance) : ID, Fire + ID, Minimum Burn Date, Maximum Burn Date, Mean Burn Date, Year, Number of Pixels, Number of Core Pixels, + Area of the patch (ha), Core Area of the patch (ha), Perimeter, Perimeter to Area Ratio, Shape Index, + Fractal Correlation Dimension, Core Area Index, Longitudinal coordinate of the center of the patch, + Latitudinal coordinate of the center of the patch, Minor half-axis of the SDE (in degrees), Major and minor + half-axes of the SDE (in degrees, in lonlat projection), major and minor half-axes of the SDE (in + kilometers, in local flat projection), orientation of the SDE (with respect to North, clockwise, in + degrees), orientation of the SDE in flat projection (with respect to North, clockwise, in degrees), + eccentricity of the SDE, Ratio of SDE half axes. The NetCDF files are self-described. + + Please cite this paper: + Pierre Laurent, Florent Mouillot, Chao Yue, Maria Vanesa Moreno Dominguez, Philippe Ciais, Joana M.P. Nogueira (2018). List of fire patch properties computed and associated NetCDF maps from the MCD64A1 Collection 6 (2000-2016) and the MERIS fire_cci v4.1 (2005-2011) BA products [Data set]. OSU OREME. https://doi.org/10.15148/0e999ffc-e220-41ac-ac85-76e92ecd0320 + if you use this in your research. + + + """, + Any[], + +)) diff --git a/test/runtests.jl b/test/runtests.jl index 13f5e2d..c37f2f4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,6 +9,7 @@ tests = [ "DataOneV2/KNB", "DataOneV2/TERN", "CKAN", + "DataCite", "format_checksum" ] From bb67a6e38cd82a659754b30bc49b7146176b030f Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Sun, 17 Jun 2018 20:18:16 +0530 Subject: [PATCH 2/4] Make suggested changes --- src/DataCite.jl | 10 ++++++---- src/DataDepsGenerators.jl | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/DataCite.jl b/src/DataCite.jl index 164e858..8169dd5 100644 --- a/src/DataCite.jl +++ b/src/DataCite.jl @@ -1,6 +1,8 @@ struct DataCite <: DataRepo end +base_url(::DataCite) = "https://api.datacite.org/works/" + function description(repo::DataCite, mainpage) attributes = mainpage["attributes"] desc = attributes["description"] @@ -10,7 +12,7 @@ function description(repo::DataCite, mainpage) date = attributes["published"] paper = format_papers(authors, date, attributes["title"] * " [Data set]. " * attributes["container-title"] * ".", mainpage["id"]) - final = escape_multiline_string(""" + escape_multiline_string(""" Author: $(author) License: $(license) Date: $(date) @@ -38,13 +40,13 @@ function data_fullname(::DataCite, mainpage) end function website(repo::DataCite, mainpage_url) - replace(mainpage_url, "https://api.datacite.org/works/", "https://doi.org/") + replace(mainpage_url, base_url(repo), "https://doi.org/") end function mainpage_url(repo::DataCite, dataname) try - identifier = match(r"\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?![\"&\'<>])\S)+)\b", dataname).match - url = "https://api.datacite.org/works/" * identifier + identifier = check_dois(dataname) + url = base_url(repo) * identifier JSON.parse(text_only(getpage(url).root))["data"], url catch ErrorException error("Please use a valid url") diff --git a/src/DataDepsGenerators.jl b/src/DataDepsGenerators.jl index 628450f..b94389b 100644 --- a/src/DataDepsGenerators.jl +++ b/src/DataDepsGenerators.jl @@ -118,6 +118,11 @@ function format_papers(authors::Vector, year::String, name::String, link::String join(authors, ", ") * " ($year). " * name * " " * link end +function check_dois(uri::String) + identifier = match(r"\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?![\"&\'<>])\S)+)\b", uri).match + return identifier +end + website(::DataRepo, mainpage_url) = mainpage_url function mainpage_url(repo::DataRepo, dataname) From 17c8e14631937a0e58dcb6a31489e3bf4891501d Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Thu, 21 Jun 2018 12:33:00 +0100 Subject: [PATCH 3/4] Change to match_doi --- src/DataCite.jl | 2 +- src/DataDepsGenerators.jl | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/DataCite.jl b/src/DataCite.jl index 8169dd5..21c208b 100644 --- a/src/DataCite.jl +++ b/src/DataCite.jl @@ -45,7 +45,7 @@ end function mainpage_url(repo::DataCite, dataname) try - identifier = check_dois(dataname) + identifier = match_doi(dataname) url = base_url(repo) * identifier JSON.parse(text_only(getpage(url).root))["data"], url catch ErrorException diff --git a/src/DataDepsGenerators.jl b/src/DataDepsGenerators.jl index b94389b..d8bb4d9 100644 --- a/src/DataDepsGenerators.jl +++ b/src/DataDepsGenerators.jl @@ -3,11 +3,7 @@ using Gumbo, Cascadia, AbstractTrees using Suppressor using JSON -<<<<<<< HEAD -export generate, UCI, GitHub, DataDryad, DataOneV1, DataOneV2, CKAN -======= -export generate, UCI, GitHub, DataDryadWeb, DataDryadAPI, DataOneV2, CKAN, DataCite ->>>>>>> Add DataCite API +export generate, UCI, GitHub, DataDryad, DataOneV1, DataOneV2, CKAN, DataCite abstract type DataRepo end @@ -118,7 +114,7 @@ function format_papers(authors::Vector, year::String, name::String, link::String join(authors, ", ") * " ($year). " * name * " " * link end -function check_dois(uri::String) +function match_doi(uri::String) identifier = match(r"\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?![\"&\'<>])\S)+)\b", uri).match return identifier end From b6ca9d8229941b5a0862506bc5bb1e6cbb23abd4 Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Thu, 21 Jun 2018 17:38:55 +0100 Subject: [PATCH 4/4] Fix suggested changes --- src/DataCite.jl | 7 ++++--- test/references/DataCite Ceramic.txt | 3 +-- test/references/DataCite Fire Patch.txt | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/DataCite.jl b/src/DataCite.jl index 21c208b..f4a79df 100644 --- a/src/DataCite.jl +++ b/src/DataCite.jl @@ -10,7 +10,8 @@ function description(repo::DataCite, mainpage) author = format_authors(authors) license = attributes["license"] date = attributes["published"] - paper = format_papers(authors, date, attributes["title"] * " [Data set]. " * attributes["container-title"] * ".", mainpage["id"]) + paper = format_papers(authors, date, attributes["title"] * + " [Data set]. " * attributes["container-title"] * ".", mainpage["id"]) escape_multiline_string(""" Author: $(author) @@ -22,12 +23,12 @@ function description(repo::DataCite, mainpage) Please cite this paper: $(paper) if you use this in your research. - """, "\$") end function get_urls(repo::DataCite, page) - urls = [] + urls = ["PUT DOWNLOAD URL HERE"] + info("DataCite based generation can only generate partial registration blocks, as DataCite metadata does not (currently) include the URL to the resource. You will have to edit in the URL after generation.") urls end diff --git a/test/references/DataCite Ceramic.txt b/test/references/DataCite Ceramic.txt index bb64e83..e7c3fec 100644 --- a/test/references/DataCite Ceramic.txt +++ b/test/references/DataCite Ceramic.txt @@ -13,8 +13,7 @@ register(DataDep( Rama Arora (2018). Study Of Surface Roughness With The Variation In Applied Load Of Rutile Ceramic Reinforced Aluminium Composite [Data set]. Zenodo. https://doi.org/10.5281/zenodo.1147572 if you use this in your research. - """, - Any[], + String["PUT DOWNLOAD URL HERE"], )) diff --git a/test/references/DataCite Fire Patch.txt b/test/references/DataCite Fire Patch.txt index df7f970..489b4ba 100644 --- a/test/references/DataCite Fire Patch.txt +++ b/test/references/DataCite Fire Patch.txt @@ -23,8 +23,7 @@ register(DataDep( Pierre Laurent, Florent Mouillot, Chao Yue, Maria Vanesa Moreno Dominguez, Philippe Ciais, Joana M.P. Nogueira (2018). List of fire patch properties computed and associated NetCDF maps from the MCD64A1 Collection 6 (2000-2016) and the MERIS fire_cci v4.1 (2005-2011) BA products [Data set]. OSU OREME. https://doi.org/10.15148/0e999ffc-e220-41ac-ac85-76e92ecd0320 if you use this in your research. - """, - Any[], + String["PUT DOWNLOAD URL HERE"], ))