bolognese 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d95db6e5bbb36dfe35b17b59d550c461313081f73d53e905ab2b3ef8ca51406
4
- data.tar.gz: 12c67ecc1909f2b666cbc39a939bbfeba069e720c459edac0261b7da85bd8830
3
+ metadata.gz: 101b83ceef5cc504cac6e51becd5840d9c27e78a7247033d61183ce7958d5e08
4
+ data.tar.gz: 9409014f1925750a0795f8cc90607b8fdef63a23d9a8b4ce23fd7c16c7ea19a3
5
5
  SHA512:
6
- metadata.gz: 7b312da3d75d11246151383fe98c220c507d35a3de421d0241ef21c2c8a77fff95d16554a8e815cf95ed62e1489fc0b9eae737d656215432cc7f818476de4de8
7
- data.tar.gz: adfd9ce65312058e16341122109bc0636ad73048ca96577e1013c8628ca14b539447edbc141434c887be45a42cb256898df74df582d7b02958fa81a116f6cf8d
6
+ metadata.gz: b88362a0aa9c1661fcef16b3886964ec4c214a468310f8df40e9ae50be18657a4f7aae999674a1c3109d65f9f503c3f3830bc5c77597817d0a57d0cec73f45c3
7
+ data.tar.gz: 250e6261325c0b745d783b865d53d7b9c9d0726fec30b5cc02afeaa1961453f8d5f3afcf1ace249f26b60d9eb1f40d20e041fb10d9fbbbacbdf806012090f81e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bolognese (1.0.4)
4
+ bolognese (1.0.5)
5
5
  activesupport (>= 4.2.5, < 6)
6
6
  benchmark_methods (~> 0.7)
7
7
  bibtex-ruby (~> 4.1)
@@ -35,13 +35,15 @@ module Bolognese
35
35
  family_name = parse_attributes(author.fetch("familyName", nil))
36
36
  name = cleanup_author(name)
37
37
  name = [family_name, given_name].join(", ") if name.blank? && family_name.present?
38
+ contributor_type = parse_attributes(author.fetch("contributorType", nil))
38
39
 
39
40
  author = { "type" => type || "Person",
40
41
  "id" => id,
41
42
  "name" => name,
42
43
  "givenName" => given_name,
43
44
  "familyName" => family_name,
44
- "identifier" => identifier }.compact
45
+ "identifier" => identifier,
46
+ "contributorType" => contributor_type }.compact
45
47
 
46
48
  return author if family_name.present?
47
49
 
@@ -63,7 +65,8 @@ module Bolognese
63
65
  "name" => name,
64
66
  "givenName" => given_name,
65
67
  "familyName" => family_name,
66
- "identifier" => identifier }.compact
68
+ "identifier" => identifier,
69
+ "contributorType" => contributor_type }.compact
67
70
  else
68
71
  { "type" => type, "name" => name }.compact
69
72
  end
@@ -54,12 +54,12 @@ module Bolognese
54
54
  end
55
55
 
56
56
  def insert_contributors(xml)
57
- return xml unless editor.present?
57
+ return xml unless contributor.present?
58
58
 
59
59
  xml.contributors do
60
- Array.wrap(editor).each do |contributor|
61
- xml.contributor("contributorType" => "Editor") do
62
- insert_person(xml, contributor, "contributor")
60
+ Array.wrap(contributor).each do |con|
61
+ xml.contributor("contributorType" => con["contributorType"] || "Other") do
62
+ insert_person(xml, con, "contributor")
63
63
  end
64
64
  end
65
65
  end
@@ -6,11 +6,11 @@ module Bolognese
6
6
  class Metadata
7
7
  include Bolognese::MetadataUtils
8
8
 
9
- attr_writer :id, :provider_id, :client_id, :doi, :identifier, :creator, :title, :publisher, :rights, :dates, :publication_year,
10
- :volume, :first_page, :last_page, :url, :version,
11
- :keywords, :editor, :description, :alternate_identifiers, :language, :size,
9
+ attr_writer :id, :provider_id, :client_id, :doi, :identifier, :creator, :contributor, :title, :publisher,
10
+ :rights, :dates, :publication_year, :volume, :first_page, :last_page, :url, :version,
11
+ :keywords, :contributor, :description, :alternate_identifiers, :language, :size,
12
12
  :formats, :schema_version, :meta, :periodical,
13
- :format, :funding_references, :style, :locale, :state, :geo_location,
13
+ :format, :funding_references, :state, :geo_location,
14
14
  :types, :content_url, :related_identifiers
15
15
 
16
16
  def initialize(input: nil, from: nil, **options)
@@ -195,5 +195,9 @@ module Bolognese
195
195
  def creator
196
196
  @creator ||= meta.fetch("creator", nil)
197
197
  end
198
+
199
+ def contributor
200
+ @contributor ||= meta.fetch("contributor", nil)
201
+ end
198
202
  end
199
203
  end
@@ -61,8 +61,9 @@ module Bolognese
61
61
  include Bolognese::Writers::SchemaOrgWriter
62
62
  include Bolognese::Writers::TurtleWriter
63
63
 
64
- attr_accessor :string, :from, :sandbox, :meta, :regenerate, :issue, :contributor
64
+ attr_accessor :string, :from, :sandbox, :meta, :regenerate, :issue
65
65
  attr_reader :doc, :service_provider, :page_start, :page_end, :reverse, :name_detector
66
+ attr_writer :style, :locale
66
67
 
67
68
  # replace DOI in XML if provided in options
68
69
  def raw
@@ -79,10 +80,6 @@ module Bolognese
79
80
  (from == "datacite") && regenerate.blank? && raw.present?
80
81
  end
81
82
 
82
- def editor
83
- @editor ||= meta.fetch("editor", nil)
84
- end
85
-
86
83
  def service_provider
87
84
  @service_provider ||= meta.fetch("service_provider", nil)
88
85
  end
@@ -128,7 +125,7 @@ module Bolognese
128
125
  "categories" => Array.wrap(keywords).map { |k| parse_attributes(k, content: "text", first: true) }.presence,
129
126
  "language" => language,
130
127
  "author" => to_citeproc(creator),
131
- "editor" => to_citeproc(editor),
128
+ "contributor" => to_citeproc(contributor),
132
129
  "issued" => get_date(dates, "Issued") ? get_date_parts(get_date(dates, "Issued")) : nil,
133
130
  "submitted" => Array.wrap(dates).find { |d| d["type"] == "Submitted" }.to_h.fetch("__content__", nil),
134
131
  "abstract" => parse_attributes(description, content: "text", first: true),
@@ -45,7 +45,7 @@ module Bolognese
45
45
  }.compact
46
46
  doi = normalize_doi(meta.fetch("DOI", nil))
47
47
  creator = get_authors(from_citeproc(Array.wrap(meta.fetch("author", nil))))
48
- editor = get_authors(from_citeproc(Array.wrap(meta.fetch("editor", nil))))
48
+ contributor = get_authors(from_citeproc(Array.wrap(meta.fetch("editor", nil))))
49
49
  dates = if meta.fetch("issued", nil).present?
50
50
  [{ "date" => get_date_from_date_parts(meta.fetch("issued", nil)),
51
51
  "date_type" => "Issued" }]
@@ -83,6 +83,7 @@ module Bolognese
83
83
  "url" => normalize_id(meta.fetch("URL", nil)),
84
84
  "title" => [{ "text" => meta.fetch("title", nil) }],
85
85
  "creator" => creator,
86
+ "contributor" => contributor,
86
87
  "periodical" => periodical,
87
88
  "publisher" => meta.fetch("publisher", nil),
88
89
  "related_identifiers" => related_identifiers,
@@ -22,7 +22,7 @@ module Bolognese
22
22
  identifier = meta.fetch("identifier", nil)
23
23
  id = normalize_id(meta.fetch("@id", nil) || identifier)
24
24
  author = get_authors(from_schema_org(Array.wrap(meta.fetch("agents", nil))))
25
- editor = get_authors(from_schema_org(Array.wrap(meta.fetch("editor", nil))))
25
+ contributor = get_authors(from_schema_org(Array.wrap(meta.fetch("editor", nil))))
26
26
  dates = []
27
27
  dates << { "date" => meta.fetch("datePublished"), "date_type" => "Issued" } if meta.fetch("datePublished", nil).present?
28
28
  dates << { "date" => meta.fetch("dateCreated"), "date_type" => "Created" } if meta.fetch("dateCreated", nil).present?
@@ -47,7 +47,7 @@ module Bolognese
47
47
  "url" => normalize_id(meta.fetch("codeRepository", nil)),
48
48
  "title" => [{ "text" => meta.fetch("title", nil) }],
49
49
  "creator" => author,
50
- "editor" => editor,
50
+ "contributor" => contributor,
51
51
  "publisher" => publisher,
52
52
  #{}"is_part_of" => is_part_of,
53
53
  "dates" => dates,
@@ -109,7 +109,7 @@ module Bolognese
109
109
  "title" => [{ "text" => parse_attributes(bibliographic_metadata.dig("titles", "title")) }],
110
110
  "alternate_identifiers" => crossref_alternate_identifiers(bibliographic_metadata),
111
111
  "creator" => crossref_people(bibliographic_metadata, "author"),
112
- "editor" => crossref_people(bibliographic_metadata, "editor"),
112
+ "contributor" => crossref_people(bibliographic_metadata, "editor"),
113
113
  "funding_references" => crossref_funding_reference(program_metadata),
114
114
  "publisher" => publisher,
115
115
  "periodical" => periodical,
@@ -170,7 +170,8 @@ module Bolognese
170
170
  "id" => parse_attributes(a["ORCID"]),
171
171
  "name" => [a["given_name"], a["surname"]].join(" "),
172
172
  "givenName" => a["given_name"],
173
- "familyName" => a["surname"] }.compact
173
+ "familyName" => a["surname"],
174
+ "contributorType" => contributor_role == "editor" ? "Editor" : nil }.compact
174
175
  end.unwrap
175
176
  end
176
177
 
@@ -40,7 +40,7 @@ module Bolognese
40
40
  "title" => meta.fetch("title", nil),
41
41
  "alternate_identifiers" => meta.fetch("alternate-identifiers", nil),
42
42
  "creator" => meta.fetch("creator", nil),
43
- "editor" => meta.fetch("contributor", nil),
43
+ "contributor" => meta.fetch("contributor", nil),
44
44
  "publisher" => meta.fetch("publisher", nil),
45
45
  "periodical" => meta.fetch("periodical", nil),
46
46
  "service_provider" => "DataCite",
@@ -105,7 +105,7 @@ module Bolognese
105
105
  if k.nil?
106
106
  nil
107
107
  elsif k.is_a?(String)
108
- sanitize(k)
108
+ { "text" => sanitize(k) }
109
109
  else
110
110
  { "subject_scheme" => k["subjectScheme"], "scheme_uri" => k["schemeURI"], "text" => sanitize(k["__content__"]) }.compact
111
111
  end
@@ -171,6 +171,7 @@ module Bolognese
171
171
  "url" => options.fetch(:url, nil),
172
172
  "title" => title,
173
173
  "creator" => get_authors(Array.wrap(meta.dig("creators", "creator"))),
174
+ "contributor" => get_authors(Array.wrap(meta.dig("contributors", "contributor"))),
174
175
  "periodical" => periodical,
175
176
  "publisher" => meta.fetch("publisher", "").strip.presence,
176
177
  "service_provider" => "DataCite",
@@ -62,7 +62,7 @@ module Bolognese
62
62
  }.compact
63
63
  authors = meta.fetch("author", nil) || meta.fetch("creator", nil)
64
64
  author = get_authors(from_schema_org(Array.wrap(authors)))
65
- editor = get_authors(from_schema_org(Array.wrap(meta.fetch("editor", nil))))
65
+ contributor = get_authors(from_schema_org(Array.wrap(meta.fetch("editor", nil))))
66
66
  publisher = parse_attributes(meta.fetch("publisher", nil), content: "name", first: true)
67
67
 
68
68
  ct = (type == "Dataset") ? "includedInDataCatalog" : "Periodical"
@@ -136,7 +136,7 @@ module Bolognese
136
136
  "formats" => Array.wrap(meta.fetch("encodingFormat", nil) || meta.fetch("fileFormat", nil)).unwrap,
137
137
  "title" => meta.fetch("name", nil).present? ? [{ "text" => meta.fetch("name", nil) }] : nil,
138
138
  "creator" => author,
139
- "editor" => editor,
139
+ "contributor" => contributor,
140
140
  "publisher" => publisher,
141
141
  "service_provider" => parse_attributes(meta.fetch("provider", nil), content: "name", first: true),
142
142
  "periodical" => periodical,
@@ -816,6 +816,10 @@ module Bolognese
816
816
  dd.fetch("date", nil)
817
817
  end
818
818
 
819
+ def get_contributor(contributor, contributor_type)
820
+ contributor.select { |c| c["contributor_type"] == contributor_type }
821
+ end
822
+
819
823
  def jsonlint(json)
820
824
  return ["No JSON provided"] unless json.present?
821
825
 
@@ -1,3 +1,3 @@
1
1
  module Bolognese
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -51,9 +51,9 @@ module Bolognese
51
51
  end
52
52
 
53
53
  def insert_editors(xml)
54
- if editor.present?
54
+ if contributor.present?
55
55
  xml.send("person-group", "person-group-type" => "editor") do
56
- Array.wrap(editor).each do |creator|
56
+ Array.wrap(contributor).each do |creator|
57
57
  xml.name do
58
58
  insert_contributor(xml, creator)
59
59
  end
@@ -12,7 +12,7 @@ module Bolognese
12
12
  "additionalType" => types["resource_type"],
13
13
  "name" => parse_attributes(title, content: "text", first: true),
14
14
  "author" => to_schema_org(creator),
15
- "editor" => to_schema_org(editor),
15
+ "editor" => to_schema_org(contributor),
16
16
  "description" => parse_attributes(description, content: "text", first: true),
17
17
  "license" => Array.wrap(rights).map { |l| l["id"] }.compact.unwrap,
18
18
  "version" => version,
@@ -53,7 +53,7 @@ describe Bolognese::Metadata, vcr: true do
53
53
  expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resource_type"=>"JournalArticle", "resource_type_general"=>"Text", "ris"=>"JOUR", "type"=>"ScholarlyArticle")
54
54
  expect(subject.creator.length).to eq(5)
55
55
  expect(subject.creator.first).to eq("type"=>"Person", "name"=>"Markus Ralser", "givenName"=>"Markus", "familyName"=>"Ralser")
56
- expect(subject.editor).to eq("type"=>"Person", "name"=>"Guilhem Janbon", "givenName"=>"Guilhem", "familyName"=>"Janbon")
56
+ expect(subject.contributor).to eq("contributorType"=>"Editor", "familyName"=>"Janbon", "givenName"=>"Guilhem", "name"=>"Guilhem Janbon", "type"=>"Person")
57
57
  expect(subject.title).to eq([{"text"=>"Triose Phosphate Isomerase Deficiency Is Caused by Altered Dimerization–Not Catalytic Inactivity–of the Mutant Enzymes"}])
58
58
  expect(subject.rights).to eq([{"id"=>"http://creativecommons.org/licenses/by/4.0"}])
59
59
  expect(subject.dates).to eq([{"date"=>"2006-12-20", "date_type"=>"Issued"}, {"date"=>"2017-06-17T12:26:15Z", "date_type"=>"Updated"}])
@@ -741,7 +741,7 @@ describe Bolognese::Metadata, vcr: true do
741
741
  expect(subject.types["resource_type"]).to eq("DroNc-seq data")
742
742
  expect(subject.creator).to eq("name"=>"The GTEx Consortium", "type"=>"Organization")
743
743
  expect(subject.title).to eq([{"text"=>"DroNc-seq data"}])
744
- expect(subject.keywords).to eq(["gtex", "annotation", "phenotype", "gene regulation", "transcriptomics"])
744
+ expect(subject.keywords).to eq([{"text"=>"gtex"}, {"text"=>"annotation"}, {"text"=>"phenotype"}, {"text"=>"gene regulation"}, {"text"=>"transcriptomics"}])
745
745
  expect(subject.dates).to eq([{"date"=>"2017", "date_type"=>"Issued"}])
746
746
  expect(subject.publication_year).to eq("2017")
747
747
  expect(subject.related_identifiers.length).to eq(4)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolognese
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner