relaton-nist 1.19.4 → 1.19.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: d3852462f5f9cc9e5ad9d0ea51e9c6c18ca339db6b7212333fa7a2251d37fc22
4
- data.tar.gz: 57135db61fee07d214543141fd87543b1efc81f9fdfd926fca38af8f8659709c
3
+ metadata.gz: 47c01d46202e813e27019c4beb5e5ccc4aa258a61dd4f6ea3b184009e6ae9e09
4
+ data.tar.gz: 2dadbcee5b551aefb4f4cefe04620964d3455acb842f005944e2f30e195d94ba
5
5
  SHA512:
6
- metadata.gz: 3800ffae4986f2d50dd05e7944d17fd1233d6b82865a38163760eb80a348518b26ad4d5dcd27d5900b80a202a20331a55a782159192c756c52edde655765d095
7
- data.tar.gz: c0ded3c9ecdf02fe2fb6e05df9cce69817340ebcd7d51efe2741f4e02de0534ae7d53a7082e4300572c271ff0b3553808584b52d0ca373fb24b59eb9d782b585
6
+ metadata.gz: 3e264c34cfea0e5ef97894265d0e6917081d05e7d317142475badb242036eeae4e4caafde6cd2f19c62ae12b99560cef88d92638f40d2e9592a37a704cef8aca
7
+ data.tar.gz: 262e7bf0461fbd19f9da7346128166ab2d07fdc3e8f3cffff2ec20ec5fad2b6883a8f4f85624675e5e586a29b3a17cfe28eee426b63b23ce8b7c3fc3fb83a426
@@ -6,7 +6,7 @@ require_relative "mods_parser"
6
6
 
7
7
  module RelatonNist
8
8
  class DataFetcher
9
- URL = "https://github.com/usnistgov/NIST-Tech-Pubs/releases/download/Sept2024/allrecords-MODS.xml"
9
+ URL = "https://github.com/usnistgov/NIST-Tech-Pubs/releases/download/Oct2024/allrecords-MODS.xml"
10
10
 
11
11
  def initialize(output, format)
12
12
  @output = output
@@ -23,7 +23,7 @@ module RelatonNist
23
23
  #
24
24
  def initialize(text, year = nil, opts = {})
25
25
  super text, year
26
- @reference = year && !text.match?(/:\d{4}$/) ? "#{text}:#{year}" : text
26
+ @reference = text # year && !text.match?(/:\d{4}$/) ? "#{text}-#{year}" : text
27
27
  @opts = opts
28
28
  end
29
29
 
@@ -58,21 +58,29 @@ module RelatonNist
58
58
  # @return [Array<RelatonNist::Hit>] hits
59
59
  #
60
60
  def search_filter # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
61
+ refid = ::Pubid::Nist::Identifier.parse(@reference)
61
62
  arr = @array.select do |item|
62
- parts = doi_parts(item.hit[:json]) || code_parts(item.hit[:code])
63
- iteration = item.hit.dig(:json, "iteration")
64
- draft = parts[:draft] || (!iteration.nil? && iteration.match?(/\wpd/i))
65
- refparts[:code] && [parts[:series], item.hit[:series]].include?(refparts[:series]) &&
66
- refparts[:code].casecmp(parts[:code].upcase).zero? &&
67
- refparts[:prt] == parts[:prt] &&
68
- (refparts[:vol].nil? || refparts[:vol] == parts[:vol]) &&
69
- (refparts[:ver].nil? || refparts[:ver] == parts[:ver]) &&
70
- (refparts[:rev].nil? || refparts[:rev] == parts[:rev]) &&
71
- refparts[:draft] == draft && refparts[:add] == parts[:add]
63
+ pubid = ::Pubid::Nist::Identifier.parse(item.hit[:code].sub(/\.$/, ""))
64
+ pubid == refid
65
+ # parts = doi_parts(item.hit[:json]) || code_parts(item.hit[:code])
66
+ # iteration = item.hit.dig(:json, "iteration")
67
+ # draft = parts[:draft] || (!iteration.nil? && iteration.match?(/\wpd/i))
68
+ # refparts[:code] && [parts[:series], item.hit[:series]].include?(refparts[:series]) &&
69
+ # refparts[:code].casecmp(parts[:code].upcase).zero? &&
70
+ # refparts[:prt] == parts[:prt] &&
71
+ # (refparts[:vol].nil? || refparts[:vol] == parts[:vol]) &&
72
+ # (refparts[:ver].nil? || refparts[:ver] == parts[:ver]) &&
73
+ # (refparts[:rev].nil? || refparts[:rev] == parts[:rev]) &&
74
+ # refparts[:draft] == draft && refparts[:add] == parts[:add]
75
+ rescue StandardError
76
+ item.hit[:code] == text
72
77
  end
78
+ rescue StandardError
79
+ arr = @array.select { |item| item.hit[:code] == text }
80
+ ensure
73
81
  dup = self.dup
74
82
  dup.array = arr
75
- dup
83
+ return dup
76
84
  end
77
85
 
78
86
  private
@@ -182,6 +190,12 @@ module RelatonNist
182
190
  self
183
191
  end
184
192
 
193
+ def pubid(id = text)
194
+ Pubid::Nist::Identifier.parse(id).to_s
195
+ rescue StandardError
196
+ id
197
+ end
198
+
185
199
  #
186
200
  # Get hit from GitHub repo
187
201
  #
@@ -191,8 +205,8 @@ module RelatonNist
191
205
  #
192
206
  def from_ga # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
193
207
  Util.info "Fetching from Relaton repository ...", key: @reference
194
- ref = full_ref
195
- return [] if ref.empty?
208
+ ref = pubid
209
+ # return [] if ref.empty?
196
210
 
197
211
  # fn = ref.gsub(%r{[/\s:.]}, "_").upcase
198
212
  index = Relaton::Index.find_or_create :nist, url: "#{GHNISTDATA}index-v1.zip", file: INDEX_FILE
@@ -227,24 +241,44 @@ module RelatonNist
227
241
  /(?<series>(?<=-)\w+$)/ =~ h["series"]
228
242
  title = [h["title-main"], h["title-sub"]].compact.join " - "
229
243
  release_date = RelatonBib.parse_date h["published-date"], false
230
- Hit.new({ code: docidentifier(h), series: series.upcase, title: title, url: h["uri"],
244
+ Hit.new({ code: pubs_export_id(h), series: series.upcase, title: title, url: h["uri"],
231
245
  status: h["status"], release_date: release_date, json: h }, self)
232
246
  end
233
247
  end
234
248
 
235
- def docidentifier(json) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
236
- parts = doi_parts(json) || code_parts(json["docidentifier"])
249
+ def pubs_export_id(json) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
250
+ if json && json["doi"]
251
+ json["doi"].sub(/^10.6028\//, "")
252
+ else
253
+ json["docidentifier"]
254
+ end => id
255
+ # parts = doi_parts(json) || code_parts(json["docidentifier"])
237
256
  # return json["docidentifier"] unless parts
238
257
 
239
- id = parts[:code]
240
- id = "NIST #{parts[:series]} #{id}" if parts[:series]
241
- id += " Part #{parts[:prt]}" if parts[:prt]
242
- id += " Vol. #{parts[:vol]}" if parts[:vol]
243
- id += " Ver. #{parts[:ver]}" if parts[:ver]
244
- id += " Rev. #{parts[:rev]}" if parts[:rev]
245
- id += "-Add" if parts[:add]
246
- id += " (Draft)" if parts[:draft] || @opts[:stage]
258
+ id.sub!(/(?:-draft\d*|\.\wpd)$/, "")
259
+ pid = ::Pubid::Nist::Identifier.parse(id)
260
+ case json["iteration"]
261
+ when "final"
262
+ pid.stage = ::Pubid::Nist::Stage.new id: "f", type: "pd"
263
+ when "fpd"
264
+ pid.stage = ::Pubid::Nist::Stage.new id: "f", type: "pd"
265
+ when /(\w)pd/
266
+ pid.stage = ::Pubid::Nist::Stage.new id: Regexp.last_match(1), type: "pd"
267
+ end
268
+ pid.to_s
269
+ rescue StandardError
270
+ id += " #{json["iteration"].sub('final', 'fpd')}" if json["iteration"]
247
271
  id
272
+
273
+ # id = parts[:code]
274
+ # id = "NIST #{parts[:series]} #{id}" if parts[:series]
275
+ # id += " Part #{parts[:prt]}" if parts[:prt]
276
+ # id += " Vol. #{parts[:vol]}" if parts[:vol]
277
+ # id += " Ver. #{parts[:ver]}" if parts[:ver]
278
+ # id += " Rev. #{parts[:rev]}" if parts[:rev]
279
+ # id += "-Add" if parts[:add]
280
+ # id += " (Draft)" if parts[:draft] || @opts[:stage]
281
+ # id
248
282
  end
249
283
 
250
284
  #
@@ -29,33 +29,43 @@ module RelatonNist
29
29
  def parse_docid
30
30
  [
31
31
  { type: "NIST", id: pub_id, primary: true },
32
- { type: "DOI", id: doi },
32
+ { type: "DOI", id: parse_doi },
33
33
  ].map { |id| RelatonBib::DocumentIdentifier.new(**id) }
34
34
  end
35
35
 
36
36
  # @return [String]
37
37
  def pub_id
38
- get_id_from_str doi
38
+ get_id_from_str parse_doi
39
39
  end
40
40
 
41
41
  def get_id_from_str(str)
42
- str.match(/\/((?:NBS|NIST).+)/i)[1].gsub(".", " ").sub(/^([^\d]+)/, '\1'.upcase)
42
+ ::Pubid::Nist::Identifier.parse(str).to_s
43
+ rescue ::Pubid::Core::Errors::ParseError
44
+ str.gsub(".", " ").sub(/^[\D]+/, &:upcase)
43
45
  end
44
46
 
45
47
  # @return [String]
46
- def doi
47
- url = @doc.location.reduce(nil) { |m, l| m || l.url.detect { |u| u.usage == "primary display" } }
48
- id = url.content.match(/10\.6028\/.+/)[0]
48
+ def replace_wrong_doi(id)
49
49
  case id
50
- when "10.6028/NBS.CIRC.sup" then "10.6028/NBS.CIRC.24e7sup"
51
- when "10.6028/NBS.CIRC.supJun1925-Jun1926" then "10.6028/NBS.CIRC.24e7sup2"
52
- when "10.6028/NBS.CIRC.supJun1925-Jun1927" then "10.6028/NBS.CIRC.24e7sup3"
53
- when "10.6028/NBS.CIRC.24supJuly1922" then "10.6028/NBS.CIRC.24e6sup"
54
- when "10.6028/NBS.CIRC.24supJan1924" then "10.6028/NBS.CIRC.24e6sup2"
50
+ when "NBS.CIRC.sup" then "NBS.CIRC.24e7sup"
51
+ when "NBS.CIRC.supJun1925-Jun1926" then "NBS.CIRC.24e7sup2"
52
+ when "NBS.CIRC.supJun1925-Jun1927" then "NBS.CIRC.24e7sup3"
53
+ when "NBS.CIRC.24supJuly1922" then "NBS.CIRC.24e6sup"
54
+ when "NBS.CIRC.24supJan1924" then "NBS.CIRC.24e6sup2"
55
55
  else id
56
56
  end
57
57
  end
58
58
 
59
+ def parse_doi
60
+ url = @doc.location.reduce(nil) { |m, l| m || l.url.detect { |u| u.usage == "primary display" } }
61
+ id = remove_doi_prefix(url.content)
62
+ replace_wrong_doi(id)
63
+ end
64
+
65
+ def remove_doi_prefix(id)
66
+ id.match(/10\.6028\/(.+)/)[1]
67
+ end
68
+
59
69
  # @return [Array<RelatonBib::TypedTitleString>]
60
70
  def parse_title
61
71
  title = @doc.title_info.reduce([]) do |a, ti|
@@ -180,7 +190,8 @@ module RelatonNist
180
190
  item.other_type
181
191
  else
182
192
  item.name[0].name_part[0].content
183
- end
193
+ end => id
194
+ replace_wrong_doi remove_doi_prefix(id)
184
195
  end
185
196
 
186
197
  def parse_place
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.19.4".freeze
2
+ VERSION = "1.19.5".freeze
3
3
  end
data/lib/relaton_nist.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require "singleton"
2
+ require "pubid"
2
3
  require "relaton/index"
3
4
  require "relaton_bib"
4
5
  require "relaton_nist/version"
5
6
  require "relaton_nist/util"
7
+ # require "relaton_nist/pubid"
6
8
  require "relaton_nist/nist_bibliography"
7
9
  require "relaton_nist/data_fetcher"
8
10
  require "relaton_nist/pubs_export"
data/relaton_nist.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency "base64"
27
27
  spec.add_dependency "loc_mods", "~> 0.2.0"
28
+ spec.add_dependency "pubid", "~> 0.1.0"
28
29
  spec.add_dependency "relaton-bib", "~> 1.19.2"
29
30
  spec.add_dependency "relaton-index", "~> 0.2.0"
30
31
  spec.add_dependency "rubyzip"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.4
4
+ version: 1.19.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-24 00:00:00.000000000 Z
11
+ date: 2024-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pubid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: relaton-bib
43
57
  requirement: !ruby/object:Gem::Requirement