relaton-nist 1.14.0 → 1.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/grammars/basicdoc.rng +0 -1
- data/grammars/biblio.rng +12 -2
- data/lib/relaton_nist/data_fetcher.rb +1 -0
- data/lib/relaton_nist/hit_collection.rb +6 -69
- data/lib/relaton_nist/pubs_export.rb +58 -0
- data/lib/relaton_nist/version.rb +1 -1
- data/lib/relaton_nist.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0a3280e8b107aa791c82020a104a35132ceab0951eef11ff280119efe01ea47
|
4
|
+
data.tar.gz: be0d5aeab00d2aa721fa2d080763062d8d768f91d0aa042889bfc8d1eaba3865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d88f097b5d1c48563e985c1e3dc780a8fadfd298b9050cd8c384d7839f2b9941dbf334ef770ce8bde7a136bafc9e1b27a0a2d07e69375619a3a3df705ffc6a70
|
7
|
+
data.tar.gz: 6e2df5491193c9d5303279eb77e30d1773f1ce524f27cc7b1e53ca70e033d56c898d99683dbee6853a7f6e9f402521f0a6226ed92b3b5dccd77430419bfe0617
|
data/grammars/basicdoc.rng
CHANGED
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
|
-
<
|
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>
|
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,7 +61,8 @@ 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]
|
64
|
+
refparts[:draft] == parts[:draft] && refparts[:add] == parts[:add] &&
|
65
|
+
refparts[:res] == parts[:res]) ||
|
69
66
|
item.hit[:title]&.include?(text.sub(/^NIST\s/, ""))
|
70
67
|
end
|
71
68
|
end
|
@@ -87,6 +84,7 @@ module RelatonNist
|
|
87
84
|
# (?:\s(?<rev2>Rev\.\s\d+))?
|
88
85
|
add: match(/\sAdd(?:endum)?(?<val>\d*)/, code),
|
89
86
|
draft: !match(/\((?:Retired\s)?Draft\)/, code).nil?,
|
87
|
+
res: match(/(?<=\s)RES/, text),
|
90
88
|
}
|
91
89
|
end
|
92
90
|
|
@@ -123,6 +121,7 @@ module RelatonNist
|
|
123
121
|
rev: match(/(?:(?:(?<dl>\.)|[^a-z])r|\sRev\.\s)(?(<dl>)-)(?<val>\d+)/, text),
|
124
122
|
add: match(/(?:(?<dl>\.)?add|\/Add)(?(<dl>)-)(?<val>\d*)/, text),
|
125
123
|
draft: !(match(/\((?:Draft|PD)\)/, text).nil? && @opts[:stage].nil?),
|
124
|
+
res: match(/(?<=\s)RES/, text),
|
126
125
|
# prt2: match(/(?<=\s)Part\s[A-Z\d]+/, text),
|
127
126
|
# vol2: match(/(?<=\s)Vol\.\s\d+/, text),
|
128
127
|
# ver2: match(/(?<=\s)Ver\.\s\d+/, text),
|
@@ -161,27 +160,6 @@ module RelatonNist
|
|
161
160
|
end
|
162
161
|
end
|
163
162
|
|
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
163
|
#
|
186
164
|
# Sort hits by sort_value and release date
|
187
165
|
#
|
@@ -261,10 +239,10 @@ module RelatonNist
|
|
261
239
|
ref = "#{refparts[:series]} #{refparts[:code]}"
|
262
240
|
d = Date.strptime year, "%Y" if year
|
263
241
|
statuses = %w[draft-public draft-prelim]
|
264
|
-
data.select do |doc|
|
242
|
+
PubsExport.instance.data.select do |doc|
|
265
243
|
next unless match_year?(doc, d)
|
266
244
|
|
267
|
-
if
|
245
|
+
if @opts[:stage]&.include?("PD")
|
268
246
|
next unless statuses.include? doc["status"]
|
269
247
|
else
|
270
248
|
next unless doc["status"] == "final"
|
@@ -287,46 +265,5 @@ module RelatonNist
|
|
287
265
|
idate = RelatonBib.parse_date doc["issued-date"], false
|
288
266
|
idate.between? date, date.next_year.prev_day
|
289
267
|
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
268
|
end
|
332
269
|
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
|
data/lib/relaton_nist/version.rb
CHANGED
data/lib/relaton_nist.rb
CHANGED
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.
|
4
|
+
version: 1.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-31 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
|