relaton-bipm 2.0.0.pre.alpha.2 → 2.0.0.pre.alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28df241c309a5932e534f727cba44fed2414a8ca86c166b6d969b40edfea0154
4
- data.tar.gz: 962edc994ca6435fbb6346e858702f58e7ed30b47d0acfdb2f1acee40e085da0
3
+ metadata.gz: 28e812b274f936f9499e5e3499dfd4aa1dbdf6eefb5e9faee499bc77b76e4b32
4
+ data.tar.gz: cb3d30c7d029c7ab1934867f164baaab2bc13363f07921bdd969225bfce4a63c
5
5
  SHA512:
6
- metadata.gz: ece155d44403c0a38f4023b00fdc9f6aece11d33e6cf66a8c36223f744734b7154ded701a5c3a11a140bc59f2cb5b136d1cf61f78e1dc54ab75396e20d1a50ee
7
- data.tar.gz: 04fbc52a458552adb636b1355615e3d8e7dbb512a788b429bb7576e3d0a8ae17d13512429a86699e667087844f8cfeecf7b1de8353d6cff6b14062a6d7ece43e
6
+ metadata.gz: 747287435b174e1102b6a21e99db6703b432b022bd04c4a5dc66d2a7e437902493e01510cb084e068773ecb0c28cc54b530a2efdd0c9187cbbbfeb973e686d40
7
+ data.tar.gz: 98eb1a4b7fd46adc7cefdc65238ff57fd90b30454cdd4a46f7a3a2cc814bda6522416a984c7bf8c453ad32500bf8a4ce069e058b52e66c48921c9430f93f5070
@@ -4,7 +4,6 @@ require_relative "id_parser"
4
4
  module Relaton::Bipm
5
5
  class Bibliography
6
6
  GH_ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-bipm/refs/heads/data-v2/".freeze
7
- INDEX_FILE = "index-v1.yaml".freeze
8
7
 
9
8
  class << self
10
9
  # @param text [String]
@@ -63,7 +62,7 @@ module Relaton::Bipm
63
62
 
64
63
  def index
65
64
  Relaton::Index.find_or_create(
66
- :bipm, url: "#{GH_ENDPOINT}index-v1.zip", file: INDEX_FILE, id_keys: %i[group type number year corr part append]
65
+ :bipm, url: "#{GH_ENDPOINT}index-v1.zip", file: INDEXFILE, id_keys: %i[group type number year corr part append]
67
66
  )
68
67
  end
69
68
 
@@ -9,7 +9,7 @@ module Relaton::Bipm
9
9
  attr_reader :output, :format, :ext, :files, :index
10
10
 
11
11
  def index
12
- @index ||= Relaton::Index.find_or_create :bipm, file: Bibliography::INDEX_FILE
12
+ @index ||= Relaton::Index.find_or_create :bipm, file: INDEXFILE
13
13
  end
14
14
 
15
15
  #
@@ -268,26 +268,29 @@ module Relaton::Bipm
268
268
  #
269
269
  def contributors(date, body)
270
270
  contribs = [bipm_contrib]
271
- author = author_org date, body
272
- return contribs unless author
271
+ subdiv = committee_subdivision date, body
272
+ return contribs unless subdiv
273
273
 
274
- role = Relaton::Bib::Contributor::Role.new(type: "author")
275
- contribs << Relaton::Bib::Contributor.new(organization: author, role: [role])
274
+ bipm_name = [Relaton::Bib::TypedLocalizedString.new(content: "BIPM", script: "Latn")]
275
+ org = Relaton::Bib::Organization.new(name: bipm_name, subdivision: [subdiv])
276
+ desc = Relaton::Bib::LocalizedMarkedUpString.new(content: "committee")
277
+ role = Relaton::Bib::Contributor::Role.new(type: "author", description: [desc])
278
+ contribs << Relaton::Bib::Contributor.new(organization: org, role: [role])
276
279
  end
277
280
 
278
281
  #
279
- # Create author organization
282
+ # Create committee subdivision
280
283
  #
281
284
  # @param [String] date date of publication
282
285
  # @param [String] body organization abbreviation (CCTF, CIPM, CGPM)
283
286
  #
284
- # @return [Hash, nil] author organization
287
+ # @return [Relaton::Bib::Subdivision, nil] committee subdivision
285
288
  #
286
- def author_org(date, body)
289
+ def committee_subdivision(date, body)
287
290
  case body
288
- when "CCTF" then cctf_org date
289
- when "CGPM" then cgpm_org
290
- when "CIPM" then cipm_org
291
+ when "CCTF" then cctf_subdivision date
292
+ when "CGPM" then cgpm_subdivision
293
+ when "CIPM" then cipm_subdivision
291
294
  end
292
295
  end
293
296
 
@@ -307,25 +310,25 @@ module Relaton::Bipm
307
310
  end
308
311
 
309
312
  #
310
- # Create CCTF organization
313
+ # Create CCTF subdivision
311
314
  #
312
315
  # @param [String] date date of meeting
313
316
  #
314
- # @return [Hash] CCTF organization
317
+ # @return [Relaton::Bib::Subdivision] CCTF subdivision
315
318
  #
316
- def cctf_org(date) # rubocop:disable Metrics/MethodLength
319
+ def cctf_subdivision(date) # rubocop:disable Metrics/MethodLength
317
320
  if ::Date.parse(date).year < 1999
318
321
  nms = [
319
322
  { content: "Consultative Committee for the Definition of the Second", language: "en" },
320
323
  { content: "Comité Consultatif pour la Définition de la Seconde", language: "fr" },
321
324
  ]
322
- organization nms, "CCDS"
325
+ subdivision nms, "CCDS"
323
326
  else
324
327
  nms = [
325
328
  { content: "Consultative Committee for Time and Frequency", language: "en" },
326
329
  { content: "Comité consultatif du temps et des fréquences", language: "fr" },
327
330
  ]
328
- organization nms, "CCTF"
331
+ subdivision nms, "CCTF"
329
332
  end
330
333
  end
331
334
 
@@ -347,29 +350,44 @@ module Relaton::Bipm
347
350
  end
348
351
 
349
352
  #
350
- # Create CGPM organization
353
+ # Create subdivision
351
354
  #
352
- # @return [Hash] CGPM organization
355
+ # @param [Array<Hash>] names subdivision names in different languages
356
+ # @param [String] abbr abbreviation
357
+ # @param [String] abbr_lang language of abbreviation
358
+ #
359
+ # @return [Relaton::Bib::Subdivision] subdivision
360
+ #
361
+ def subdivision(names, abbr, abbr_lang: "en")
362
+ name = names.map { |n| Relaton::Bib::TypedLocalizedString.new(**n, script: "Latn") }
363
+ abbreviation = Relaton::Bib::LocalizedString.new(content: abbr, language: abbr_lang, script: "Latn")
364
+ Relaton::Bib::Subdivision.new(type: "committee", name: name, abbreviation: abbreviation)
365
+ end
366
+
367
+ #
368
+ # Create CGPM subdivision
369
+ #
370
+ # @return [Relaton::Bib::Subdivision] CGPM subdivision
353
371
  #
354
- def cgpm_org
372
+ def cgpm_subdivision
355
373
  nms = [
356
374
  { content: "General Conference on Weights and Measures", language: "en" },
357
375
  { content: "Conférence Générale des Poids et Mesures", language: "fr" },
358
376
  ]
359
- organization nms, "CGPM", abbr_lang: "fr"
377
+ subdivision nms, "CGPM", abbr_lang: "fr"
360
378
  end
361
379
 
362
380
  #
363
- # Create CIPM organization
381
+ # Create CIPM subdivision
364
382
  #
365
- # @return [Array<Hash>] CIPM organization
383
+ # @return [Relaton::Bib::Subdivision] CIPM subdivision
366
384
  #
367
- def cipm_org
385
+ def cipm_subdivision
368
386
  names = [
369
387
  { content: "International Committee for Weights and Measures", language: "en" },
370
388
  { content: "Comité international des poids et mesures", language: "fr" },
371
389
  ]
372
- organization names, "CIPM", abbr_lang: "fr"
390
+ subdivision names, "CIPM", abbr_lang: "fr"
373
391
  end
374
392
 
375
393
  #
@@ -62,7 +62,7 @@ module Relaton
62
62
  #
63
63
  def remove_index_file
64
64
  require_relative "../bipm"
65
- Relaton::Index.find_or_create(:bipm, url: true, file: Bibliography::INDEX_FILE).remove_file
65
+ Relaton::Index.find_or_create(:bipm, url: true, file: INDEXFILE).remove_file
66
66
  end
67
67
  end
68
68
  end
@@ -295,9 +295,49 @@ module Relaton::Bipm
295
295
  # @return [Array<Relaton::Bib::Relation>] array of document relations
296
296
  #
297
297
  def parse_relation
298
- dates do |d, t|
298
+ rels = dates do |d, t|
299
299
  Relaton::Bib::Relation.new(type: "hasManifestation", bibitem: bibitem(d, t))
300
300
  end
301
+ rels + parse_references
302
+ end
303
+
304
+ #
305
+ # Parse back/ref-list references as "cites" relations
306
+ #
307
+ # @return [Array<Relaton::Bib::Relation>] array of "cites" relations
308
+ #
309
+ def parse_references
310
+ @doc.xpath("./back/ref-list/ref").filter_map do |ref|
311
+ citation = ref.at("./element-citation")
312
+ next unless citation
313
+
314
+ Relaton::Bib::Relation.new(type: "cites", bibitem: citation_bibitem(citation))
315
+ end
316
+ end
317
+
318
+ #
319
+ # Build bibitem from an element-citation
320
+ #
321
+ # @param [Nokogiri::XML::Element] citation element-citation node
322
+ #
323
+ # @return [Relaton::Bipm::ItemData] bibitem
324
+ #
325
+ def citation_bibitem(citation)
326
+ attrs = {}
327
+ doi = citation.at("./pub-id[@pub-id-type='doi']")
328
+ if doi
329
+ attrs[:docidentifier] = [Relaton::Bib::Docidentifier.new(content: doi.text, type: "doi")]
330
+ attrs[:source] = [Relaton::Bib::Uri.new(content: "https://doi.org/#{doi.text}", type: "doi")]
331
+ end
332
+ source = citation.at("./source")
333
+ if source
334
+ attrs[:title] = [Relaton::Bib::Title.new(content: source.text)]
335
+ end
336
+ year = citation.at("./year")
337
+ if year
338
+ attrs[:date] = [Relaton::Bib::Date.new(type: "published", at: year.text)]
339
+ end
340
+ ItemData.new(**attrs)
301
341
  end
302
342
 
303
343
  #
@@ -33,7 +33,7 @@ module Relaton::Bipm
33
33
  #
34
34
  def fetch_articles # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
35
35
  # aff = Affiliations.parse DIR
36
- Dir["#{DIR}/**/*.xml"].each do |path|
36
+ Dir["#{DIR}/**/*.xml"].sort_by { |p| archive_date(p) }.each do |path|
37
37
  item = ArticleParser.parse path # , aff
38
38
  file = "#{item.docidentifier.first.content.downcase.tr(' ', '-')}.#{@data_fetcher.ext}"
39
39
  out_path = File.join(@data_fetcher.output, file)
@@ -150,6 +150,17 @@ module Relaton::Bipm
150
150
  [Relaton::Bib::Uri.new(type: "src", content: link(*args))]
151
151
  end
152
152
 
153
+ #
154
+ # Extract archive date from path for sorting
155
+ #
156
+ # @param [String] path file path
157
+ #
158
+ # @return [String] date string for sorting
159
+ #
160
+ def archive_date(path)
161
+ path[%r{/data/(\d{4}-\d{2}-\d{2}T[\d_]+)_content/}, 1].to_s
162
+ end
163
+
153
164
  def link(*args)
154
165
  params = id_parts(*args).join("/")
155
166
  case args.size
@@ -1,3 +1,4 @@
1
+ require "nokogiri"
1
2
  require_relative "id_parser"
2
3
 
3
4
  module Relaton::Bipm
@@ -34,6 +35,9 @@ module Relaton::Bipm
34
35
  xml = File.read(f, encoding: "UTF-8")
35
36
  xml = xml.force_encoding("UTF-8") if xml.encoding != Encoding::UTF_8
36
37
  item1 = Bibdata.from_xml(xml)
38
+ unless has_committee_contributor?(item1)
39
+ extract_editorialgroup(xml).each { |c| item1.contributor << c }
40
+ end
37
41
  fix_si_brochure_id item1
38
42
  basename = File.join @data_fetcher.output, File.basename(f).sub(/(?:-(?:en|fr))?\.rxl$/, "")
39
43
  outfile = "#{basename}.#{@data_fetcher.ext}"
@@ -75,7 +79,7 @@ module Relaton::Bipm
75
79
  else
76
80
  item.docnumber = prid.sub(/^BIPM\s/, "")
77
81
  end
78
- item.id = prid.gsub(/[,\s]/, "")
82
+ item.id = prid.gsub(/[,\s-]/, "")
79
83
  end
80
84
 
81
85
  def update_id(item)
@@ -93,6 +97,33 @@ module Relaton::Bipm
93
97
  end.content
94
98
  end
95
99
 
100
+ def has_committee_contributor?(item)
101
+ item.contributor.any? do |c|
102
+ c.role.any? { |r| r.description.any? { |d| d.content == "committee" } }
103
+ end
104
+ end
105
+
106
+ def extract_editorialgroup(xml)
107
+ doc = Nokogiri::XML(xml)
108
+ doc.xpath("//editorialgroup/committee").map do |committee|
109
+ acronym = committee["acronym"]
110
+ names = committee.xpath("variant").map do |v|
111
+ Relaton::Bib::TypedLocalizedString.new(
112
+ content: v.text, language: v["language"], script: v["script"],
113
+ )
114
+ end
115
+ subdiv = Relaton::Bib::Subdivision.new(
116
+ type: "committee", name: names,
117
+ abbreviation: Relaton::Bib::LocalizedString.new(content: acronym),
118
+ )
119
+ bipm_name = [Relaton::Bib::TypedLocalizedString.new(content: acronym)]
120
+ org = Relaton::Bib::Organization.new(name: bipm_name, subdivision: [subdiv])
121
+ desc = Relaton::Bib::LocalizedMarkedUpString.new(content: "committee")
122
+ role = Relaton::Bib::Contributor::Role.new(type: "author", description: [desc])
123
+ Relaton::Bib::Contributor.new(organization: org, role: [role])
124
+ end
125
+ end
126
+
96
127
  #
97
128
  # Deep merge two hashes
98
129
  #
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Bipm
3
- VERSION = "2.0.0-alpha.2".freeze
3
+ VERSION = "2.0.0-alpha.3".freeze
4
4
  end
5
5
  end
data/lib/relaton/bipm.rb CHANGED
@@ -16,6 +16,8 @@ module Relaton
16
16
  module Bipm
17
17
  class Error < StandardError; end
18
18
 
19
+ INDEXFILE = "index-v1.yaml".freeze
20
+
19
21
  # Returns hash of gems versions used to generate the data model.
20
22
  # @return [String]
21
23
  def grammar_hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bipm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha.2
4
+ version: 2.0.0.pre.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.