relaton-nist 1.14.1 → 1.14.3

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: 5e57a7e2ff1d4d40e799e5abb368bc849f76484ab646bbab6f79067b74c7f277
4
- data.tar.gz: 5fa57799445d309ddd383cb229eba3408365989d9343c312c724adce6bcd9fc1
3
+ metadata.gz: 2e235a74aee86bfb4fce55d8e7a89b4ab4afc2df13ae0a733512f30a7f63cd4c
4
+ data.tar.gz: bc8e8144f15c430618d0b2d6447d33dc607cf0fac165ebffdfa9ff816c18da37
5
5
  SHA512:
6
- metadata.gz: 75391002c42e0b93fdd8afc9840c4bd0cf2df7431e366fcac43d6cbaf1049ec9363a766685b300eae470bc6262a2f0a60c79fc560c118037f2b2ce0dcf1ff872
7
- data.tar.gz: 2c6690d2974a9c337188e066e418f697028bf7bb261908e4bf459384132f54900bb9b4c4259024a4b5b0a3a4d8734e0429787336eb4cb5bc72b7940e8af79e87
6
+ metadata.gz: 2ce74d0722ef6ba698eb73f07e990c011b7247beed74e3750629a81da24f0ffd5ea1a4fc1028ad2102828f93a0076a641f9bbb9bb992bbecce34c8d494192809
7
+ data.tar.gz: 8ca7b46ccb2a5f2c689f78cb8d4c964b6c93334e6ff04f6748f9e651995607baa0cc0c4b164a1104aee41aa2c46243372a35b5c41ab0740e6dc405289becb3c2
@@ -522,7 +522,6 @@
522
522
  <value>tip</value>
523
523
  <value>important</value>
524
524
  <value>caution</value>
525
- <value>statement</value>
526
525
  </choice>
527
526
  </define>
528
527
  <define name="figure">
data/grammars/biblio.rng CHANGED
@@ -216,6 +216,9 @@
216
216
  <optional>
217
217
  <ref name="fullname"/>
218
218
  </optional>
219
+ <zeroOrMore>
220
+ <ref name="credential"/>
221
+ </zeroOrMore>
219
222
  <zeroOrMore>
220
223
  <ref name="affiliation"/>
221
224
  </zeroOrMore>
@@ -232,6 +235,11 @@
232
235
  <ref name="FullNameType"/>
233
236
  </element>
234
237
  </define>
238
+ <define name="credential">
239
+ <element name="credential">
240
+ <text/>
241
+ </element>
242
+ </define>
235
243
  <define name="FullNameType">
236
244
  <choice>
237
245
  <group>
@@ -305,7 +313,9 @@
305
313
  <zeroOrMore>
306
314
  <ref name="affiliationdescription"/>
307
315
  </zeroOrMore>
308
- <ref name="organization"/>
316
+ <optional>
317
+ <ref name="organization"/>
318
+ </optional>
309
319
  </element>
310
320
  </define>
311
321
  <define name="affiliationname">
@@ -1316,7 +1326,7 @@
1316
1326
  <value>commentaryOf</value>
1317
1327
  <value>hasCommentary</value>
1318
1328
  <value>related</value>
1319
- <value>complements</value>
1329
+ <value>hasComplement</value>
1320
1330
  <value>complementOf</value>
1321
1331
  <value>obsoletes</value>
1322
1332
  <value>obsoletedBy</value>
@@ -9,10 +9,6 @@ require "open-uri"
9
9
  module RelatonNist
10
10
  # Hit collection.
11
11
  class HitCollection < RelatonBib::HitCollection
12
- DOMAIN = "https://csrc.nist.gov"
13
- PUBS_EXPORT = URI.join(DOMAIN, "/CSRC/media/feeds/metanorma/pubs-export")
14
- DATAFILEDIR = File.expand_path ".relaton/nist", Dir.home
15
- DATAFILE = File.expand_path "pubs-export.zip", DATAFILEDIR
16
12
  GHNISTDATA = "https://raw.githubusercontent.com/relaton/relaton-data-nist/main/data/"
17
13
 
18
14
  #
@@ -65,8 +61,10 @@ module RelatonNist
65
61
  (!refparts[:vol] || refparts[:vol] == parts[:vol]) &&
66
62
  (!refparts[:ver] || refparts[:ver] == parts[:ver]) &&
67
63
  (!refparts[:rev] || refparts[:rev] == parts[:rev]) &&
68
- refparts[:draft] == parts[:draft] && refparts[:add] == parts[:add]) ||
69
- item.hit[:title]&.include?(text.sub(/^NIST\s/, ""))
64
+ refparts[:draft] == parts[:draft] && refparts[:add] == parts[:add] &&
65
+ refparts[:res] == parts[:res]) # ||
66
+ # (refparts[:code] && !refparts[:code].empty? &&
67
+ # item.hit[:title]&.include?("#{refparts[:series]} #{refparts[:code]}"))
70
68
  end
71
69
  end
72
70
 
@@ -87,6 +85,7 @@ module RelatonNist
87
85
  # (?:\s(?<rev2>Rev\.\s\d+))?
88
86
  add: match(/\sAdd(?:endum)?(?<val>\d*)/, code),
89
87
  draft: !match(/\((?:Retired\s)?Draft\)/, code).nil?,
88
+ res: match(/(?<=\s)RES/, text),
90
89
  }
91
90
  end
92
91
 
@@ -123,6 +122,7 @@ module RelatonNist
123
122
  rev: match(/(?:(?:(?<dl>\.)|[^a-z])r|\sRev\.\s)(?(<dl>)-)(?<val>\d+)/, text),
124
123
  add: match(/(?:(?<dl>\.)?add|\/Add)(?(<dl>)-)(?<val>\d*)/, text),
125
124
  draft: !(match(/\((?:Draft|PD)\)/, text).nil? && @opts[:stage].nil?),
125
+ res: match(/(?<=\s)RES/, text),
126
126
  # prt2: match(/(?<=\s)Part\s[A-Z\d]+/, text),
127
127
  # vol2: match(/(?<=\s)Vol\.\s\d+/, text),
128
128
  # ver2: match(/(?<=\s)Ver\.\s\d+/, text),
@@ -161,27 +161,6 @@ module RelatonNist
161
161
  end
162
162
  end
163
163
 
164
- #
165
- # Return short version of ID part with removed "-" or convert long version to short.
166
- # Converts "pt-1" to "pt1" and "Part 1" to "pt1", "v-1" to "v1" and "Vol. 1" to "v1",
167
- # "ver-1" to "ver1" and "Ver. 1" to "ver1", "r-1" to "r1" and "Rev. 1" to "r1".
168
- #
169
- # @param parts [MatchData] parts of ID
170
- # @param name [String] name of ID part
171
- #
172
- # @return [String, nil]
173
- #
174
- # def long_to_short(parts, name)
175
- # short = parts["#{name}1".to_sym]
176
- # return short.sub(/-/, "") if short
177
-
178
- # long_name = "#{name}2"
179
- # long = parts[long_name.to_sym]
180
- # return unless long
181
-
182
- # long.sub(/Part\s/, "pt").sub(/Vol\.\s/, "v").sub(/Rev\.\s/, "r").sub(/(Ver\.|Version)\s/, "ver")
183
- # end
184
-
185
164
  #
186
165
  # Sort hits by sort_value and release date
187
166
  #
@@ -261,10 +240,10 @@ module RelatonNist
261
240
  ref = "#{refparts[:series]} #{refparts[:code]}"
262
241
  d = Date.strptime year, "%Y" if year
263
242
  statuses = %w[draft-public draft-prelim]
264
- data.select do |doc|
243
+ PubsExport.instance.data.select do |doc|
265
244
  next unless match_year?(doc, d)
266
245
 
267
- if /PD/.match? @opts[:stage]
246
+ if @opts[:stage]&.include?("PD")
268
247
  next unless statuses.include? doc["status"]
269
248
  else
270
249
  next unless doc["status"] == "final"
@@ -287,46 +266,5 @@ module RelatonNist
287
266
  idate = RelatonBib.parse_date doc["issued-date"], false
288
267
  idate.between? date, date.next_year.prev_day
289
268
  end
290
-
291
- #
292
- # Fetches json data form server
293
- #
294
- # @return [Array<Hash>] json data
295
- #
296
- def data
297
- ctime = File.ctime DATAFILE if File.exist? DATAFILE
298
- if !ctime || ctime.to_date < Date.today || File.size(DATAFILE).zero?
299
- fetch_data(ctime)
300
- end
301
- unzip
302
- end
303
-
304
- #
305
- # Fetch data form server and save it to file
306
- #
307
- # @prarm ctime [Time, nil] file creation time
308
- #
309
- def fetch_data(ctime)
310
- if !ctime || ctime < OpenURI.open_uri("#{PUBS_EXPORT}.meta").last_modified
311
- @data = nil
312
- uri_open = URI.method(:open) || Kernel.method(:open)
313
- FileUtils.mkdir_p DATAFILEDIR
314
- IO.copy_stream(uri_open.call("#{PUBS_EXPORT}.zip"), DATAFILE)
315
- end
316
- end
317
-
318
- #
319
- # upack zip file
320
- #
321
- # @return [Array<Hash>] json data
322
- #
323
- def unzip
324
- return @data if @data
325
-
326
- Zip::File.open(DATAFILE) do |zf|
327
- @data = JSON.parse zf.first.get_input_stream.read
328
- end
329
- @data
330
- end
331
269
  end
332
270
  end
@@ -0,0 +1,58 @@
1
+ module RelatonNist
2
+ class PubsExport
3
+ include Singleton
4
+
5
+ DOMAIN = "https://csrc.nist.gov".freeze
6
+ PUBS_EXPORT = URI.join(DOMAIN, "/CSRC/media/feeds/metanorma/pubs-export")
7
+ DATAFILEDIR = File.expand_path ".relaton/nist", Dir.home
8
+ DATAFILE = File.expand_path "pubs-export.zip", DATAFILEDIR
9
+
10
+ def initialize
11
+ @mutex = Mutex.new
12
+ end
13
+
14
+ #
15
+ # Fetches json data form server
16
+ #
17
+ # @return [Array<Hash>] json data
18
+ #
19
+ def data
20
+ @mutex.synchronize do
21
+ @data ||= begin
22
+ ctime = File.ctime DATAFILE if File.exist? DATAFILE
23
+ if !ctime || ctime.to_date < Date.today || File.size(DATAFILE).zero?
24
+ fetch_data(ctime)
25
+ end
26
+ unzip
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ #
34
+ # Fetch data form server and save it to file
35
+ #
36
+ # @prarm ctime [Time, nil] file creation time
37
+ #
38
+ def fetch_data(ctime)
39
+ if !ctime || ctime < OpenURI.open_uri("#{PUBS_EXPORT}.meta").last_modified
40
+ @data = nil
41
+ uri_open = URI.method(:open) || Kernel.method(:open)
42
+ FileUtils.mkdir_p DATAFILEDIR
43
+ IO.copy_stream(uri_open.call("#{PUBS_EXPORT}.zip"), DATAFILE)
44
+ end
45
+ end
46
+
47
+ #
48
+ # upack zip file
49
+ #
50
+ # @return [Array<Hash>] json data
51
+ #
52
+ def unzip
53
+ Zip::File.open(DATAFILE) do |zf|
54
+ JSON.parse zf.first.get_input_stream.read
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.14.1".freeze
2
+ VERSION = "1.14.3".freeze
3
3
  end
data/lib/relaton_nist.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require "singleton"
1
2
  require "relaton_nist/version"
2
3
  require "relaton_nist/nist_bibliography"
3
4
  require "relaton_nist/data_fetcher"
5
+ require "relaton_nist/pubs_export"
4
6
 
5
7
  # if defined? Relaton
6
8
  # require_relative "relaton/processor"
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.14.1
4
+ version: 1.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-14 00:00:00.000000000 Z
11
+ date: 2023-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -185,6 +185,7 @@ files:
185
185
  - lib/relaton_nist/nist_bibliographic_item.rb
186
186
  - lib/relaton_nist/nist_bibliography.rb
187
187
  - lib/relaton_nist/processor.rb
188
+ - lib/relaton_nist/pubs_export.rb
188
189
  - lib/relaton_nist/scrapper.rb
189
190
  - lib/relaton_nist/series.yaml
190
191
  - lib/relaton_nist/version.rb