bolognese 0.2.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/lib/bolognese/cli.rb +3 -1
  4. data/lib/bolognese/crossref.rb +24 -2
  5. data/lib/bolognese/datacite.rb +8 -2
  6. data/lib/bolognese/datacite_utils.rb +211 -0
  7. data/lib/bolognese/version.rb +1 -1
  8. data/resources/kernel-4.0/include/datacite-contributorType-v4.xsd +35 -0
  9. data/resources/kernel-4.0/include/datacite-dateType-v4.xsd +21 -0
  10. data/resources/kernel-4.0/include/datacite-descriptionType-v4.xsd +19 -0
  11. data/resources/kernel-4.0/include/datacite-funderIdentifierType-v4.xsd +15 -0
  12. data/resources/kernel-4.0/include/datacite-relatedIdentifierType-v4.xsd +32 -0
  13. data/resources/kernel-4.0/include/datacite-relationType-v4.xsd +39 -0
  14. data/resources/kernel-4.0/include/datacite-resourceType-v4.xsd +26 -0
  15. data/resources/kernel-4.0/include/datacite-titleType-v4.xsd +14 -0
  16. data/resources/kernel-4.0/metadata.xsd +470 -0
  17. data/spec/cli_spec.rb +5 -0
  18. data/spec/crossref_spec.rb +14 -6
  19. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_crossref.yml +7 -7
  20. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_datacite.yml +1476 -0
  21. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_schema_org.yml +12 -12
  22. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/as_datacite.yml +9 -9
  23. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/as_schema_org.yml +16 -16
  24. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/not_found_error.yml +6 -6
  25. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/DOI_with_data_citation.yml +1435 -0
  26. metadata +15 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a6b175047cc9fe1cae1eba94b41164dd0c9e406
4
- data.tar.gz: f78c9e066599d1a2b6db5c66cc1a19e8024dd73b
3
+ metadata.gz: d4728c17ca6677056bae7bb34fd334b2a018bbf5
4
+ data.tar.gz: 69525494936ec8e6e4fe396f9b490b9fe19f1aa8
5
5
  SHA512:
6
- metadata.gz: fede61f6811145761b605513ae01345508e8f60a7e2d807d22ac17fd80096326d7ab4af1a8b3ca117c1856adb2f31012a23ed3392023d8f9213b424d32c2e459
7
- data.tar.gz: 4ddc0ca66cda0fbb1ea3d10021d97b1f532f733dd221c39509d1994a4c51da09f27da515fdb0536d086d425d3d0075a00fb6f498e9813802e19b0bcde70cbb87
6
+ metadata.gz: 85aa5235f96786e7f005ee588abb8d9f6bff889102d4b8d7a5b2ec91badcfd6b1f84cf2f0fdf33813768b396f98774a1ed4cd570089255628f105c2effc862d9
7
+ data.tar.gz: 6db1eb5f1ab14ec751468e4192a0d09a05a12dbf79193a80c0ceb30e9deb41c641d76d9331eba1775422308baa94f531abbae8d92cb2b0908c8f9c84ebec06ca
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Bolognese (0.2)
4
+ bolognese (0.3)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  builder (~> 3.2, >= 3.2.2)
7
7
  dotenv (~> 2.1, >= 2.1.1)
@@ -103,7 +103,7 @@ PLATFORMS
103
103
  ruby
104
104
 
105
105
  DEPENDENCIES
106
- Bolognese!
106
+ bolognese!
107
107
  bundler (~> 1.0)
108
108
  codeclimate-test-reporter (~> 1.0, >= 1.0.0)
109
109
  rack-test (~> 0)
data/lib/bolognese/cli.rb CHANGED
@@ -17,13 +17,15 @@ module Bolognese
17
17
  end
18
18
 
19
19
  desc "read pid", "read metadata for PID"
20
- method_option :as, :default => "schema_org"
20
+ method_option :as, default: "schema_org"
21
21
  def read(pid)
22
22
  provider = Metadata.new(pid).provider
23
23
 
24
24
  case
25
25
  when provider == "crossref" && options[:as] == "crossref"
26
26
  puts Crossref.new(pid).raw
27
+ when provider == "crossref" && options[:as] == "datacite"
28
+ puts Crossref.new(pid).as_datacite
27
29
  when provider == "crossref"
28
30
  puts Crossref.new(pid).as_schema_org
29
31
  when provider == "datacite" && options[:as] == "datacite"
@@ -1,13 +1,15 @@
1
1
  require_relative 'doi_utils'
2
+ require_relative 'datacite_utils'
2
3
  require_relative 'utils'
3
4
 
4
5
  module Bolognese
5
6
  class Crossref < Metadata
6
7
  include Bolognese::DoiUtils
7
8
  include Bolognese::Utils
9
+ include Bolognese::DataciteUtils
8
10
 
9
11
  # CrossRef types from https://api.crossref.org/types
10
- CROSSREF_TYPE_TRANSLATIONS = {
12
+ CR_TO_SO_TRANSLATIONS = {
11
13
  "Proceedings" => nil,
12
14
  "ReferenceBook" => nil,
13
15
  "JournalIssue" => nil,
@@ -55,6 +57,10 @@ module Bolognese
55
57
  metadata.present?
56
58
  end
57
59
 
60
+ def doi
61
+ doi_from_url(id)
62
+ end
63
+
58
64
  def journal_metadata
59
65
  metadata.dig("crossref", "journal", "journal_metadata").presence || {}
60
66
  end
@@ -82,7 +88,7 @@ module Bolognese
82
88
  end
83
89
 
84
90
  def type
85
- CROSSREF_TYPE_TRANSLATIONS[additional_type] || "CreativeWork"
91
+ CR_TO_SO_TRANSLATIONS[additional_type] || "CreativeWork"
86
92
  end
87
93
 
88
94
  def name
@@ -110,6 +116,10 @@ module Bolognese
110
116
  end
111
117
  end
112
118
 
119
+ def keywords
120
+
121
+ end
122
+
113
123
  def author
114
124
  person = bibliographic_metadata.dig("contributors", "person_name")
115
125
  Array(person).select { |a| a["contributor_role"] == "author" }.map do |a|
@@ -130,6 +140,14 @@ module Bolognese
130
140
  end.presence
131
141
  end
132
142
 
143
+ def version
144
+
145
+ end
146
+
147
+ def date_created
148
+
149
+ end
150
+
133
151
  def date_published
134
152
  pub_date = bibliographic_metadata.fetch("publication_date", nil) ||
135
153
  bibliographic_metadata.fetch("acceptance_date", nil)
@@ -173,6 +191,10 @@ module Bolognese
173
191
  end.presence
174
192
  end
175
193
 
194
+ def related_identifiers
195
+
196
+ end
197
+
176
198
  def provider
177
199
  { "@type" => "Organization",
178
200
  "name" => "Crossref" }
@@ -1,12 +1,14 @@
1
1
  require_relative 'doi_utils'
2
+ require_relative 'datacite_utils'
2
3
  require_relative 'utils'
3
4
 
4
5
  module Bolognese
5
6
  class Datacite < Metadata
6
7
  include Bolognese::DoiUtils
8
+ include Bolognese::DataciteUtils
7
9
  include Bolognese::Utils
8
10
 
9
- DATACITE_TYPE_TRANSLATIONS = {
11
+ DC_TO_SO_TRANSLATIONS = {
10
12
  "Audiovisual" => "VideoObject",
11
13
  "Collection" => "Collection",
12
14
  "Dataset" => "Dataset",
@@ -42,9 +44,13 @@ module Bolognese
42
44
  metadata.present?
43
45
  end
44
46
 
47
+ def doi
48
+ doi_from_url(id)
49
+ end
50
+
45
51
  def type
46
52
  k = metadata.dig("resourceType", "resourceTypeGeneral")
47
- DATACITE_TYPE_TRANSLATIONS[k.to_s.dasherize] || "CreativeWork"
53
+ DC_TO_SO_TRANSLATIONS[k.to_s.dasherize] || "CreativeWork"
48
54
  end
49
55
 
50
56
  def additional_type
@@ -0,0 +1,211 @@
1
+ module Bolognese
2
+ module DataciteUtils
3
+ # @resource_type = metadata.fetch("resource_type", nil)
4
+ # @rights_list = metadata.fetch("rights_list", nil)
5
+ # @descriptions = metadata.fetch("descriptions", nil)
6
+ # @contributors = metadata.fetch("contributors", nil)
7
+ # @alternate_identifier = metadata.fetch("alternate_identifier", nil)
8
+ # @media = metadata.fetch("media", nil)
9
+
10
+ SO_TO_DC_TRANSLATIONS = {
11
+ "VideoObject" => "Audiovisual",
12
+ "Collection" => "Collection",
13
+ "Dataset" => "Dataset",
14
+ "Event" => "Event",
15
+ "ImageObject" => "Image",
16
+ "Service" => "Service",
17
+ "SoftwareSourceCode" => "Software",
18
+ "AudioObject" => "Sound",
19
+ "ScholarlyArticle" => "Text",
20
+ "CreativeWork" => "Other"
21
+ }
22
+
23
+ LICENSE_NAMES = {
24
+ "http://creativecommons.org/publicdomain/zero/1.0/" => "Public Domain (CC0 1.0)",
25
+ "https://creativecommons.org/licenses/by/4.0/" => "Creative Commons Attribution 4.0 (CC-BY 4.0)",
26
+ "https://creativecommons.org/licenses/by-nc/4.0/" => "Creative Commons Attribution Noncommercial 4.0 (CC-BY-NC 4.0)",
27
+ "https://creativecommons.org/licenses/by-sa/4.0/" => "Creative Commons Attribution Share Alike 4.0 (CC-BY-SA 4.0)",
28
+ "https://creativecommons.org/licenses/by-nc-nd/4.0/" => "Creative Commons Attribution Noncommercial No Derivaties 4.0 (CC-BY-NC-ND 4.0)"
29
+ }
30
+
31
+ SCHEMA = File.expand_path("../../../resources/kernel-4.0/metadata.xsd", __FILE__)
32
+
33
+ def schema
34
+ Nokogiri::XML::Schema(open(SCHEMA))
35
+ end
36
+
37
+ def datacite_xml
38
+ Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
39
+ xml.resource(root_attributes) do
40
+ insert_work(xml)
41
+ end
42
+ end.to_xml
43
+ end
44
+
45
+ def as_datacite
46
+ if schema.validate(Nokogiri::XML(datacite_xml))
47
+ datacite_xml
48
+ end
49
+ end
50
+
51
+ def validation_errors
52
+ @validation_errors ||= schema.validate(Nokogiri::XML(datacite_xml))
53
+ end
54
+
55
+ def insert_work(xml)
56
+ insert_identifier(xml)
57
+ insert_creators(xml)
58
+ insert_titles(xml)
59
+ insert_publisher(xml)
60
+ insert_publication_year(xml)
61
+ insert_resource_type(xml)
62
+ insert_alternate_identifiers(xml)
63
+ insert_subjects(xml)
64
+ insert_contributors(xml)
65
+ insert_dates(xml)
66
+ insert_related_identifiers(xml)
67
+ insert_version(xml)
68
+ insert_rights_list(xml)
69
+ insert_descriptions(xml)
70
+ end
71
+
72
+ def insert_identifier(xml)
73
+ xml.identifier(doi, 'identifierType' => "DOI")
74
+ end
75
+
76
+ def insert_creators(xml)
77
+ xml.creators do
78
+ Array(author).each do |creator|
79
+ xml.creator do
80
+ insert_person(xml, creator, "creator")
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ def insert_contributors(xml)
87
+ return xml unless editor.present?
88
+
89
+ xml.contributors do
90
+ Array(editor).each do |contributor|
91
+ xml.contributor("contributorType" => contributor[:contributor_type]) do
92
+ insert_person(xml, contributor, "contributor")
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ def insert_person(xml, person, type)
99
+ person_name = [person["familyName"], person["givenName"], person["name"]].compact.join(", ")
100
+
101
+ xml.send(:'creatorName', person_name) if type == "creator"
102
+ xml.send(:'contributorName', person_name) if type == "contributor"
103
+ xml.send(:'givenName', person[:given_name]) if person["givenName"].present?
104
+ xml.send(:'familyName', person[:family_name]) if person["familyName"].present?
105
+ xml.nameIdentifier(person["@id"], 'schemeURI' => 'http://orcid.org/', 'nameIdentifierScheme' => 'ORCID') if person["@id"].present?
106
+ end
107
+
108
+ def insert_titles(xml)
109
+ xml.titles do
110
+ insert_title(xml)
111
+ end
112
+ end
113
+
114
+ def insert_title(xml)
115
+ xml.title(name)
116
+ end
117
+
118
+ def insert_publisher(xml)
119
+ xml.publisher(is_part_of["name"])
120
+ end
121
+
122
+ def insert_publication_year(xml)
123
+ xml.publicationYear(date_published[0..3])
124
+ end
125
+
126
+ def insert_resource_type(xml)
127
+ return xml unless type.present?
128
+
129
+ xml.resourceType(additional_type, 'resourceTypeGeneral' => SO_TO_DC_TRANSLATIONS[type])
130
+ end
131
+
132
+ def insert_alternate_identifiers(xml)
133
+ return xml unless alternate_name.present?
134
+
135
+ xml.alternateIdentifiers do
136
+ xml.alternateIdentifier(alternate_name, 'alternateIdentifierType' => "Local accession number")
137
+ end
138
+ end
139
+
140
+ def insert_dates(xml)
141
+ xml.dates do
142
+ insert_date(xml, date_created, 'Created') if date_created.present?
143
+ insert_date(xml, date_published, 'Issued') if date_published.present?
144
+ insert_date(xml, date_modified, 'Updated') if date_modified.present?
145
+ end
146
+ end
147
+
148
+ def insert_date(xml, date, date_type)
149
+ xml.date(date, 'dateType' => date_type)
150
+ end
151
+
152
+ def insert_subjects(xml)
153
+ return xml unless keywords.present?
154
+
155
+ xml.subjects do
156
+ keywords.split(", ").each do |subject|
157
+ xml.subject(subject)
158
+ end
159
+ end
160
+ end
161
+
162
+ def insert_version(xml)
163
+ return xml unless version.present?
164
+
165
+ xml.version(version)
166
+ end
167
+
168
+ def insert_related_identifiers(xml)
169
+ return xml unless related_identifiers.present?
170
+
171
+ xml.relatedIdentifiers do
172
+ related_identifiers.each do |related_identifier|
173
+ xml.relatedIdentifier(related_identifier[:value], 'relatedIdentifierType' => related_identifier[:related_identifier_type], 'relationType' => related_identifier[:relation_type])
174
+ end
175
+ end
176
+ end
177
+
178
+ def insert_rights_list(xml)
179
+ return xml unless license.present?
180
+
181
+ xml.rightsList do
182
+ xml.rights(LICENSE_NAMES[license], 'rightsURI' => license)
183
+ end
184
+ end
185
+
186
+ def insert_descriptions(xml)
187
+ return xml unless description.present?
188
+
189
+ xml.descriptions do
190
+ xml.description(description)
191
+ end
192
+ end
193
+
194
+ def without_control(s)
195
+ r = ''
196
+ s.each_codepoint do |c|
197
+ if c >= 32
198
+ r << c
199
+ end
200
+ end
201
+ r
202
+ end
203
+
204
+ def root_attributes
205
+ { :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
206
+ :'xsi:schemaLocation' => 'http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd',
207
+ :'xmlns' => 'http://datacite.org/schema/kernel-4' }
208
+ end
209
+ end
210
+ end
211
+
@@ -1,3 +1,3 @@
1
1
  module Bolognese
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3"
3
3
  end
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany
3
+ 2013-05 v3.0: Addition of ID to simpleType element, added values "ResearchGroup" & "Other"
4
+ 2014-08-20 v3.1: Addition of value "DataCurator"
5
+ 2015-05-14 v4.0 dropped value "Funder", use new "funderReference" -->
6
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-4" targetNamespace="http://datacite.org/schema/kernel-4" elementFormDefault="qualified">
7
+ <xs:simpleType name="contributorType" id="contributorType">
8
+ <xs:annotation>
9
+ <xs:documentation>The type of contributor of the resource.</xs:documentation>
10
+ </xs:annotation>
11
+ <xs:restriction base="xs:string">
12
+ <xs:enumeration value="ContactPerson"/>
13
+ <xs:enumeration value="DataCollector"/>
14
+ <xs:enumeration value="DataCurator"/>
15
+ <xs:enumeration value="DataManager"/>
16
+ <xs:enumeration value="Distributor"/>
17
+ <xs:enumeration value="Editor"/>
18
+ <xs:enumeration value="HostingInstitution"/>
19
+ <xs:enumeration value="Other"/>
20
+ <xs:enumeration value="Producer"/>
21
+ <xs:enumeration value="ProjectLeader"/>
22
+ <xs:enumeration value="ProjectManager"/>
23
+ <xs:enumeration value="ProjectMember"/>
24
+ <xs:enumeration value="RegistrationAgency"/>
25
+ <xs:enumeration value="RegistrationAuthority"/>
26
+ <xs:enumeration value="RelatedPerson"/>
27
+ <xs:enumeration value="ResearchGroup"/>
28
+ <xs:enumeration value="RightsHolder"/>
29
+ <xs:enumeration value="Researcher"/>
30
+ <xs:enumeration value="Sponsor"/>
31
+ <xs:enumeration value="Supervisor"/>
32
+ <xs:enumeration value="WorkPackageLeader"/>
33
+ </xs:restriction>
34
+ </xs:simpleType>
35
+ </xs:schema>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany
3
+ 2013-05 v3.0: Addition of ID to simpleType element; addition of value "Collected"; deleted "StartDate" & "EndDate"-->
4
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-4" targetNamespace="http://datacite.org/schema/kernel-4" elementFormDefault="qualified">
5
+ <xs:simpleType name="dateType" id="dateType">
6
+ <xs:annotation>
7
+ <xs:documentation>The type of date. Use RKMS‐ISO8601 standard for depicting date ranges.To indicate the end of an embargo period, use Available. To indicate the start of an embargo period, use Submitted or Accepted, as appropriate.</xs:documentation>
8
+ </xs:annotation>
9
+ <xs:restriction base="xs:string">
10
+ <xs:enumeration value="Accepted"/>
11
+ <xs:enumeration value="Available"/>
12
+ <xs:enumeration value="Collected"/>
13
+ <xs:enumeration value="Copyrighted"/>
14
+ <xs:enumeration value="Created"/>
15
+ <xs:enumeration value="Issued"/>
16
+ <xs:enumeration value="Submitted"/>
17
+ <xs:enumeration value="Updated"/>
18
+ <xs:enumeration value="Valid"/>
19
+ </xs:restriction>
20
+ </xs:simpleType>
21
+ </xs:schema>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany
3
+ 2013-05 v3.0: Addition of ID to simpleType element, addition of value "Methods"
4
+ 2015-02-12 v4.0: Addition of value "TechnicalInfo"-->
5
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-4" targetNamespace="http://datacite.org/schema/kernel-4" elementFormDefault="qualified">
6
+ <xs:simpleType name="descriptionType" id="descriptionType">
7
+ <xs:annotation>
8
+ <xs:documentation>The type of the description.</xs:documentation>
9
+ </xs:annotation>
10
+ <xs:restriction base="xs:string">
11
+ <xs:enumeration value="Abstract"/>
12
+ <xs:enumeration value="Methods"/>
13
+ <xs:enumeration value="SeriesInformation"/>
14
+ <xs:enumeration value="TableOfContents"/>
15
+ <xs:enumeration value="TechnicalInfo"/>
16
+ <xs:enumeration value="Other"/>
17
+ </xs:restriction>
18
+ </xs:simpleType>
19
+ </xs:schema>