bolognese 0.9.18 → 0.9.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bolognese/readers/datacite_reader.rb +22 -18
- data/lib/bolognese/utils.rb +18 -9
- data/lib/bolognese/version.rb +1 -1
- data/lib/bolognese/writers/crosscite_writer.rb +1 -1
- data/spec/readers/datacite_reader_spec.rb +1 -1
- data/spec/writers/schema_org_writer_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e774c4a8a3e9c8e2d6632ed0e6356bb9c54d611
|
4
|
+
data.tar.gz: 8230a49968ca28458cc71a55f57d90864db48b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55998c995185346c175798ee00517892aa0ac0bf5ed0059d751b38210421e501fd3b3dc7b51a20e2c43ae5803c04ff806e33b48acab134bc0966b28604937231
|
7
|
+
data.tar.gz: af2db0282a846b976d26f9c18e7e1e5561d28fcaa2949b0c43751c3ec3818058797fa34403de5411d24bfe93eead5d3d72bbb321bf45659e937b8a0f889be33a
|
data/Gemfile.lock
CHANGED
@@ -118,6 +118,28 @@ module Bolognese
|
|
118
118
|
end.uniq
|
119
119
|
end
|
120
120
|
|
121
|
+
def datacite_funder_contributor(meta)
|
122
|
+
Array.wrap(meta.dig("contributors", "contributor")).reduce([]) do |sum, f|
|
123
|
+
if f["contributorType"] == "Funder"
|
124
|
+
# handle special case of OpenAIRE metadata
|
125
|
+
id = f.dig("nameIdentifier", "__content__").to_s.start_with?("info:eu-repo/grantAgreement/EC") ? "https://doi.org/10.13039/501100000780" : nil
|
126
|
+
|
127
|
+
funder = { "type" => "Organization",
|
128
|
+
"id" => id,
|
129
|
+
"name" => f["contributorName"] }.compact
|
130
|
+
if f.dig("nameIdentifier", "nameIdentifierScheme") == "info"
|
131
|
+
sum << { "type" => "Award",
|
132
|
+
"identifier" => f.dig("nameIdentifier", "__content__").split("/").last,
|
133
|
+
"funder" => funder }
|
134
|
+
else
|
135
|
+
sum << funder
|
136
|
+
end
|
137
|
+
else
|
138
|
+
sum
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
121
143
|
def datacite_related_identifier(meta, relation_type: nil)
|
122
144
|
arr = Array.wrap(meta.dig("relatedIdentifiers", "relatedIdentifier")).select { |r| %w(DOI URL).include?(r["relatedIdentifierType"]) }
|
123
145
|
arr = arr.select { |r| relation_type.split(" ").include?(r["relationType"]) } if relation_type.present?
|
@@ -176,24 +198,6 @@ module Bolognese
|
|
176
198
|
def datacite_is_reviewed_by(meta)
|
177
199
|
datacite_related_identifier(meta, relation_type: "IsReviewedBy").presence
|
178
200
|
end
|
179
|
-
|
180
|
-
def datacite_funder_contributor(meta)
|
181
|
-
Array.wrap(meta.dig("contributors", "contributor")).reduce([]) do |sum, f|
|
182
|
-
if f["contributorType"] == "Funder"
|
183
|
-
funder = { "type" => "Organization",
|
184
|
-
"name" => f["contributorName"] }.compact
|
185
|
-
if f.dig("nameIdentifier", "nameIdentifierScheme") == "info"
|
186
|
-
sum << { "type" => "Award",
|
187
|
-
"identifier" => f.dig("nameIdentifier", "__content__").split("/").last,
|
188
|
-
"funder" => funder }
|
189
|
-
else
|
190
|
-
sum << funder
|
191
|
-
end
|
192
|
-
else
|
193
|
-
sum
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
201
|
end
|
198
202
|
end
|
199
203
|
end
|
data/lib/bolognese/utils.rb
CHANGED
@@ -383,19 +383,28 @@ module Bolognese
|
|
383
383
|
end
|
384
384
|
|
385
385
|
def to_schema_org(element)
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
a["name"] = a["title"] if a["title"].present?
|
390
|
-
a.except("type", "id", "title").compact
|
391
|
-
end.unwrap
|
386
|
+
mapping = { "type" => "@type", "id" => "@id", "title" => "name" }
|
387
|
+
|
388
|
+
map_hash_keys(element: element, mapping: mapping)
|
392
389
|
end
|
393
390
|
|
394
391
|
def from_schema_org(element)
|
392
|
+
mapping = { "@type" => "type", "@id" => "id" }
|
393
|
+
|
394
|
+
map_hash_keys(element: element, mapping: mapping)
|
395
|
+
end
|
396
|
+
|
397
|
+
def map_hash_keys(element: nil, mapping: nil)
|
395
398
|
Array.wrap(element).map do |a|
|
396
|
-
a[
|
397
|
-
|
398
|
-
|
399
|
+
a.map {|k, v| [mapping.fetch(k, k), v] }.reduce({}) do |hsh, (k, v)|
|
400
|
+
if v.is_a?(Hash)
|
401
|
+
hsh[k] = to_schema_org(v)
|
402
|
+
hsh
|
403
|
+
else
|
404
|
+
hsh[k] = v
|
405
|
+
hsh
|
406
|
+
end
|
407
|
+
end
|
399
408
|
end.unwrap
|
400
409
|
end
|
401
410
|
|
data/lib/bolognese/version.rb
CHANGED
@@ -124,7 +124,7 @@ describe Bolognese::Metadata, vcr: true do
|
|
124
124
|
expect(subject.description["text"]).to start_with("The dataset contains a sample of metadata describing papers")
|
125
125
|
expect(subject.date_published).to eq("2013-04-03")
|
126
126
|
expect(subject.publisher).to eq("OpenAIRE Orphan Record Repository")
|
127
|
-
expect(subject.funding).to eq("type"=>"Award", "identifier"=>"246686", "funder"=>{"type"=>"Organization", "name"=>"European Commission"})
|
127
|
+
expect(subject.funding).to eq("type"=>"Award", "identifier"=>"246686", "funder"=>{"type"=>"Organization", "id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"})
|
128
128
|
expect(subject.provider).to eq("DataCite")
|
129
129
|
expect(subject.schema_version).to eq("http://datacite.org/schema/kernel-3")
|
130
130
|
end
|
@@ -81,7 +81,7 @@ describe Bolognese::Metadata, vcr: true do
|
|
81
81
|
json = JSON.parse(subject.schema_org)
|
82
82
|
expect(json["@id"]).to eq("https://doi.org/10.5438/6423")
|
83
83
|
expect(json["funding"]).to eq("@type" => "Award",
|
84
|
-
"funder" => {"type"=>"Organization", "id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"},
|
84
|
+
"funder" => {"@type"=>"Organization", "@id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"},
|
85
85
|
"identifier" => "654039",
|
86
86
|
"name" => "THOR – Technical and Human Infrastructure for Open Research",
|
87
87
|
"url" => "http://cordis.europa.eu/project/rcn/194927_en.html")
|
@@ -93,7 +93,7 @@ describe Bolognese::Metadata, vcr: true do
|
|
93
93
|
json = JSON.parse(subject.schema_org)
|
94
94
|
expect(json["@id"]).to eq("https://doi.org/10.5281/zenodo.1239")
|
95
95
|
expect(json["funding"]).to eq("@type" => "Award",
|
96
|
-
"funder" => {"type"=>"Organization", "name"=>"European Commission"},
|
96
|
+
"funder" => {"@type"=>"Organization", "@id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"},
|
97
97
|
"identifier" => "246686")
|
98
98
|
end
|
99
99
|
end
|