relaton-nist 1.5.1 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +36 -3
- data/grammars/isodoc.rng +14 -43
- data/grammars/nist.rng +1 -0
- data/lib/relaton_nist/hit_collection.rb +7 -5
- data/lib/relaton_nist/nist_bibliography.rb +104 -17
- data/lib/relaton_nist/scrapper.rb +2 -1
- data/lib/relaton_nist/version.rb +1 -1
- data/relaton_nist.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c81efdc2d8f38426e3eba552cc116e51fac614c10901098bdc1e8eb71b09c1f1
|
4
|
+
data.tar.gz: d629498cf1943a4d0d735e55fa6d4d61727cfcfc7bd24ca1e0e4b1e102c04364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1089faa79d7cc68a375fa77f6abd1ddbc9d10a636ef00cdd56fd99112d2b3356fa95703630685a4d668badca853fb5696b7503b4b680e8117a9b1a064a785003
|
7
|
+
data.tar.gz: 105c563803b84854488ed7e02c9bfe74a3853a78f55c90f5f67ba5c36fa3f3d83df9f889a925fef89da1114fc1efff0cb0d6fbddc2e49193d8d72ae7595c4ffa
|
data/README.adoc
CHANGED
@@ -91,11 +91,14 @@ RelatonNist::NistBibliography.get("8200", "2018", {})
|
|
91
91
|
=== Get short citation
|
92
92
|
Short citation is a convetion about a citation's format. The format for NIST publications is:
|
93
93
|
----
|
94
|
-
NIST {abbrev(series)} {docnumber} {(edition), optional} {(stage),
|
94
|
+
NIST {abbrev(series)} {docnumber} {(edition), optional} {(stage), optional}
|
95
95
|
# or
|
96
|
-
{abbrev(series)} {docnumber} {(edition), optional} {(stage),
|
96
|
+
{abbrev(series)} {docnumber} {(edition), optional} {(stage), optional}
|
97
97
|
----
|
98
|
-
- `(stage)` is empty if the state is "final" (published)
|
98
|
+
- `(stage)` is empty if the state is "final" (published). In case state is "draft" it shoud be:
|
99
|
+
* PD for public draft
|
100
|
+
* IPD for initial iteration public draft or 2PD, 3PD and so one for following iterations
|
101
|
+
* FPD for final public draft
|
99
102
|
- `(edition)` is the date of publication or update
|
100
103
|
- `docnumber` is the full NIST number, including revision, e.g., 800-52
|
101
104
|
|
@@ -114,6 +117,36 @@ RelatonNist::NistBibliography.get("SP 800-205 (February 2019) (PD)")
|
|
114
117
|
...
|
115
118
|
----
|
116
119
|
|
120
|
+
=== Get specific part, volume, version, revision, and addendum
|
121
|
+
|
122
|
+
Referehces can contain optional parameters `{ptN}{vN}{verN}{rN}{/Add}`:
|
123
|
+
- Part is specified as `ptN` (SP 800-57pt1)
|
124
|
+
- Volume is specified as `vN` (SP 800-60v1)
|
125
|
+
- Version is specified as `verN` (SP 800-45ver2)
|
126
|
+
- Revision is specified as `rN` (SP 800-40r3)
|
127
|
+
- Addendum is specified as `/Add` (SP 800-38A/Add)
|
128
|
+
|
129
|
+
[source,ruby]
|
130
|
+
----
|
131
|
+
item = RelatonNist::NistBibliography.get 'SP 800-67r3'
|
132
|
+
[relaton-nist] ("SP 800-67r3") fetching...
|
133
|
+
[relaton-nist] ("SP 800-67r3") found SP 800-67 Rev. 3
|
134
|
+
=> #<RelatonNist::NistBibliographicItem:0x007fd87bbe9460
|
135
|
+
...
|
136
|
+
|
137
|
+
item.docidentifier.first.id
|
138
|
+
=> "SP 800-67 Rev. 3"
|
139
|
+
|
140
|
+
RelatonNist::NistBibliography.get 'SP 800-38A/Add'
|
141
|
+
[relaton-nist] ("SP 800-38A/Add") fetching...
|
142
|
+
[relaton-nist] ("SP 800-38A/Add") found SP 800-38A-Add
|
143
|
+
=> #<RelatonNist::NistBibliographicItem:0x007fd88c21d880
|
144
|
+
...
|
145
|
+
|
146
|
+
item.docidentifier.first.id
|
147
|
+
=> "SP 800-38A-Add"
|
148
|
+
----
|
149
|
+
|
117
150
|
=== Create bibliographic item from YAML
|
118
151
|
[source,ruby]
|
119
152
|
----
|
data/grammars/isodoc.rng
CHANGED
@@ -24,6 +24,14 @@
|
|
24
24
|
<start>
|
25
25
|
<ref name="standard-document"/>
|
26
26
|
</start>
|
27
|
+
<define name="doctype">
|
28
|
+
<element name="doctype">
|
29
|
+
<optional>
|
30
|
+
<attribute name="abbreviation"/>
|
31
|
+
</optional>
|
32
|
+
<ref name="DocumentType"/>
|
33
|
+
</element>
|
34
|
+
</define>
|
27
35
|
<define name="hyperlink">
|
28
36
|
<element name="link">
|
29
37
|
<attribute name="target">
|
@@ -141,6 +149,11 @@
|
|
141
149
|
<data type="boolean"/>
|
142
150
|
</attribute>
|
143
151
|
</optional>
|
152
|
+
<optional>
|
153
|
+
<attribute name="key">
|
154
|
+
<data type="boolean"/>
|
155
|
+
</attribute>
|
156
|
+
</optional>
|
144
157
|
<oneOrMore>
|
145
158
|
<ref name="dt"/>
|
146
159
|
<ref name="dd"/>
|
@@ -1164,49 +1177,7 @@
|
|
1164
1177
|
</define>
|
1165
1178
|
<define name="annex">
|
1166
1179
|
<element name="annex">
|
1167
|
-
<
|
1168
|
-
<attribute name="id">
|
1169
|
-
<data type="ID"/>
|
1170
|
-
</attribute>
|
1171
|
-
</optional>
|
1172
|
-
<optional>
|
1173
|
-
<attribute name="language"/>
|
1174
|
-
</optional>
|
1175
|
-
<optional>
|
1176
|
-
<attribute name="script"/>
|
1177
|
-
</optional>
|
1178
|
-
<optional>
|
1179
|
-
<attribute name="inline-header">
|
1180
|
-
<data type="boolean"/>
|
1181
|
-
</attribute>
|
1182
|
-
</optional>
|
1183
|
-
<attribute name="obligation">
|
1184
|
-
<choice>
|
1185
|
-
<value>normative</value>
|
1186
|
-
<value>informative</value>
|
1187
|
-
</choice>
|
1188
|
-
</attribute>
|
1189
|
-
<optional>
|
1190
|
-
<ref name="section-title"/>
|
1191
|
-
</optional>
|
1192
|
-
<group>
|
1193
|
-
<group>
|
1194
|
-
<zeroOrMore>
|
1195
|
-
<ref name="BasicBlock"/>
|
1196
|
-
</zeroOrMore>
|
1197
|
-
<zeroOrMore>
|
1198
|
-
<ref name="note"/>
|
1199
|
-
</zeroOrMore>
|
1200
|
-
</group>
|
1201
|
-
<zeroOrMore>
|
1202
|
-
<choice>
|
1203
|
-
<ref name="annex-subsection"/>
|
1204
|
-
<ref name="terms"/>
|
1205
|
-
<ref name="definitions"/>
|
1206
|
-
<ref name="references"/>
|
1207
|
-
</choice>
|
1208
|
-
</zeroOrMore>
|
1209
|
-
</group>
|
1180
|
+
<ref name="Annex-Section"/>
|
1210
1181
|
</element>
|
1211
1182
|
</define>
|
1212
1183
|
<define name="terms">
|
data/grammars/nist.rng
CHANGED
@@ -21,8 +21,9 @@ module RelatonNist
|
|
21
21
|
def initialize(ref_nbr, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize
|
22
22
|
super ref_nbr, year
|
23
23
|
|
24
|
-
/(?<docid>(SP|FIPS)\s[0-9-]
|
24
|
+
/(?<docid>(SP|FIPS)\s[0-9-]+)/ =~ text
|
25
25
|
@array = docid ? from_json(docid, **opts) : from_csrc(**opts)
|
26
|
+
@array = from_csrc(**opts) unless @array.any?
|
26
27
|
|
27
28
|
@array.sort! do |a, b|
|
28
29
|
if a.sort_value != b.sort_value
|
@@ -83,7 +84,7 @@ module RelatonNist
|
|
83
84
|
select_data(docid, **opts).map do |h|
|
84
85
|
/(?<serie>(?<=-)\w+$)/ =~ h["series"]
|
85
86
|
title = [h["title-main"], h["title-sub"]].compact.join " - "
|
86
|
-
release_date = RelatonBib.parse_date h["published-date"]
|
87
|
+
release_date = RelatonBib.parse_date h["published-date"], false
|
87
88
|
Hit.new({ code: h["docidentifier"], serie: serie.upcase, title: title,
|
88
89
|
url: h["uri"], status: h["status"],
|
89
90
|
release_date: release_date, json: h }, self)
|
@@ -94,8 +95,9 @@ module RelatonNist
|
|
94
95
|
# @param stage [String]
|
95
96
|
# @return [Array<Hach>]
|
96
97
|
def select_data(docid, **opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
|
98
|
+
# ref = docid.sub(/(?<=\d{3}-\d{2})r(\d+)/, ' Rev. \1')
|
97
99
|
d = Date.strptime year, "%Y" if year
|
98
|
-
didrx = Regexp.new(docid)
|
100
|
+
# didrx = Regexp.new(docid)
|
99
101
|
data.select do |doc|
|
100
102
|
next unless match_year?(doc, d)
|
101
103
|
|
@@ -104,7 +106,7 @@ module RelatonNist
|
|
104
106
|
else
|
105
107
|
next unless doc["status"] == "final"
|
106
108
|
end
|
107
|
-
doc["docidentifier"]
|
109
|
+
doc["docidentifier"].include? docid
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
@@ -114,7 +116,7 @@ module RelatonNist
|
|
114
116
|
def match_year?(doc, date)
|
115
117
|
return true unless year
|
116
118
|
|
117
|
-
idate = RelatonBib.parse_date doc["issued-date"]
|
119
|
+
idate = RelatonBib.parse_date doc["issued-date"], false
|
118
120
|
idate.between? date, date.next_year.prev_day
|
119
121
|
end
|
120
122
|
|
@@ -29,15 +29,16 @@ module RelatonNist
|
|
29
29
|
#
|
30
30
|
# @return [String] Relaton XML serialisation of reference
|
31
31
|
def get(code, year = nil, opts = {})
|
32
|
-
return fetch_ref_err(code, year, []) if code
|
32
|
+
return fetch_ref_err(code, year, []) if code.match? /\sEP$/
|
33
33
|
|
34
34
|
/^(?<code2>[^\(]+)(\((?<date2>\w+\s(\d{2},\s)?\d{4})\))?\s?\(?((?<=\()(?<stage>[^\)]+))?/ =~ code
|
35
|
+
stage ||= /(?<=\.)PD-\w+(?=\.)/.match(code)&.to_s
|
35
36
|
if code2
|
36
37
|
code = code2.strip
|
37
38
|
if date2
|
38
|
-
if /\w+\s\d{4}
|
39
|
+
if /\w+\s\d{4}/.match? date2
|
39
40
|
opts[:issued_date] = Date.strptime date2, "%B %Y"
|
40
|
-
elsif /\w+\s\d{2},\s\d{4}
|
41
|
+
elsif /\w+\s\d{2},\s\d{4}/.match? date2
|
41
42
|
opts[:updated_date] = Date.strptime date2, "%B %d, %Y"
|
42
43
|
end
|
43
44
|
end
|
@@ -81,10 +82,10 @@ module RelatonNist
|
|
81
82
|
# @option opts [Time] :issued_date
|
82
83
|
# @option opts [String] :stage
|
83
84
|
#
|
84
|
-
# @
|
85
|
+
# @return [Hash]
|
85
86
|
def nistbib_results_filter(result, year, opts)
|
86
87
|
missed_years = []
|
87
|
-
iter = opts[:stage]&.
|
88
|
+
iter = /\w+(?=PD)|(?<=PD-)\w+/.match(opts[:stage])&.to_s
|
88
89
|
iteration = case iter
|
89
90
|
when "I" then "1"
|
90
91
|
when "F" then "final"
|
@@ -93,25 +94,32 @@ module RelatonNist
|
|
93
94
|
result.each_slice(3) do |s| # ISO website only allows 3 connections
|
94
95
|
fetch_pages(s, 3).each_with_index do |r, _i|
|
95
96
|
if opts[:issued_date]
|
96
|
-
ids = r.date.select
|
97
|
+
ids = r.date.select do |d|
|
98
|
+
d.type == "issued" && d.on(:date) == opts[:issued_date]
|
99
|
+
end
|
97
100
|
next if ids.empty?
|
98
101
|
elsif opts[:updated_date]
|
99
|
-
pds = r.date.select
|
102
|
+
pds = r.date.select do |d|
|
103
|
+
d.type == "published" && d.on(:date) == opts[:updated_date]
|
104
|
+
end
|
100
105
|
next if pds.empty?
|
101
106
|
end
|
102
107
|
next if iter && r.status.iteration != iteration
|
103
108
|
return { ret: r } if !year
|
104
109
|
|
105
110
|
r.date.select { |d| d.type == "published" }.each do |d|
|
106
|
-
return { ret: r } if year.to_i == d.on
|
111
|
+
return { ret: r } if year.to_i == d.on(:year)
|
107
112
|
|
108
|
-
missed_years << d.on
|
113
|
+
missed_years << d.on(:year)
|
109
114
|
end
|
110
115
|
end
|
111
116
|
end
|
112
117
|
{ years: missed_years }
|
113
118
|
end
|
114
119
|
|
120
|
+
# @param hits [RelatonNist::HitCollection]
|
121
|
+
# @param threads [Integer]
|
122
|
+
# @return [Array<RelatonNist::NistBibliographicItem>]
|
115
123
|
def fetch_pages(hits, threads)
|
116
124
|
workers = RelatonBib::WorkersPool.new threads
|
117
125
|
workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
|
@@ -120,15 +128,94 @@ module RelatonNist
|
|
120
128
|
workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
|
121
129
|
end
|
122
130
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
131
|
+
# @param code [String]
|
132
|
+
# @param year [String, nil]
|
133
|
+
# @param opts [Hash]
|
134
|
+
# @return [RelatonNist::HitCollection]
|
135
|
+
def nistbib_search_filter(code, year, opts) # rubocop:disable Metrics/MethodLength
|
127
136
|
warn "[relaton-nist] (\"#{code}\") fetching..."
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
137
|
+
# match = %r{
|
138
|
+
# ^((?:NIST)\s)?
|
139
|
+
# (?<serie>(SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s
|
140
|
+
# (?<code>[0-9-]{3,}[A-Z]?)
|
141
|
+
# (?<prt1>pt\d+)?
|
142
|
+
# (?<vol1>v\d+)?
|
143
|
+
# (?<ver1>ver[\d\.]+)?
|
144
|
+
# (?<rev1>r\d+)?
|
145
|
+
# (\s(?<prt2>Part\s\d+))?
|
146
|
+
# (\s(?<vol2>Vol\.\s\d+))?
|
147
|
+
# (\s(?<ver2>(Ver\.|Version)\s[\d\.]+))?
|
148
|
+
# (\s(?<rev2>Rev\.\s\d+))?
|
149
|
+
# (\/(?<upd>Add))?
|
150
|
+
# }x.match(code)
|
151
|
+
# match ||= %r{
|
152
|
+
# ^NIST\.
|
153
|
+
# (?<serie>(SP|FIPS|IR|ITL\sBulletin|White\sPaper))\.
|
154
|
+
# ((PD-\d+|PUB)\.)?
|
155
|
+
# (?<code>[0-9-]{3,}[A-Z]?)
|
156
|
+
# (\.(?<prt1>pt-\d+))?
|
157
|
+
# (\.(?<vol1>v-\d+))?
|
158
|
+
# (\.(?<ver1>ver-[\d\.]+))?
|
159
|
+
# (\.(?<rev1>r-\d+))?
|
160
|
+
# }x.match(code)
|
161
|
+
matches = {
|
162
|
+
serie: match(/(SP|FIPS|(NIST)?IR|ITL\sBulletin|White\sPaper)(?=\.|\s)/, code),
|
163
|
+
code: match(/(?<=\.|\s)[0-9-]{3,}[A-Z]?/, code),
|
164
|
+
prt1: match(/(?<=(\.))?pt(?(1)-)[A-Z\d]+/, code),
|
165
|
+
vol1: match(/(?<=(\.))?v(?(1)-)\d+/, code),
|
166
|
+
ver1: match(/(?<=(\.))?ver(?(1)[-\d]|[\.\d])+/, code)&.gsub(/-/, "."),
|
167
|
+
rev1: match(/(?<=[^a-z])(?<=(\.))?r(?(1)-)\d+/, code),
|
168
|
+
add1: match(/(?<=(\.))?add(?(1)-)\d+/, code),
|
169
|
+
prt2: match(/(?<=\s)Part\s[A-Z\d]+/, code),
|
170
|
+
vol2: match(/(?<=\s)Vol\.\s\d+/, code),
|
171
|
+
ver2: match(/(?<=\s)Ver\.\s\d+/, code),
|
172
|
+
rev2: match(/(?<=\s)Rev\.\s\d+/, code),
|
173
|
+
add2: match(/(?<=\/)Add/, code),
|
174
|
+
}
|
175
|
+
ref = matches[:code] ? "#{matches[:serie]} #{matches[:code]}" : code
|
176
|
+
result = search(ref, year, opts)
|
177
|
+
result.select { |i| search_filter i, matches, code }
|
178
|
+
end
|
179
|
+
|
180
|
+
def match(regex, code)
|
181
|
+
regex.match(code)&.to_s
|
182
|
+
end
|
183
|
+
|
184
|
+
# @param item [RelatonNist::Hit]
|
185
|
+
# @param matches [Hash]
|
186
|
+
# @param text [String]
|
187
|
+
# @return [Boolean]
|
188
|
+
def search_filter(item, matches, text) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
189
|
+
%r{
|
190
|
+
^((?:NIST)\s)?
|
191
|
+
((?<serie>(SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s)?
|
192
|
+
(?<code>[0-9-]{3,}[A-Z]?)
|
193
|
+
(?<prt1>pt\d+)?
|
194
|
+
(?<vol1>v\d+)?
|
195
|
+
(?<ver1>ver[\d\.]+)?
|
196
|
+
(?<rev1>r\d+)?
|
197
|
+
(\s(?<prt2>Part\s\d+))?
|
198
|
+
(\s(?<vol2>Vol\.\s\d+))?
|
199
|
+
(\s(?<ver2>(Ver\.|Version)\s[\d\.]+))?
|
200
|
+
(\s(?<rev2>Rev\.\s\d+))?
|
201
|
+
(\s(?<add>Add)endum)?
|
202
|
+
}x =~ item.hit[:code]
|
203
|
+
matches[:code] && [serie, item.hit[:serie]].include?(matches[:serie]) && matches[:code] == code &&
|
204
|
+
long_to_short(matches[:prt1], matches[:prt2]) == long_to_short(prt1, prt2) &&
|
205
|
+
long_to_short(matches[:vol1], matches[:vol2]) == long_to_short(vol1, vol2) &&
|
206
|
+
long_to_short(matches[:ver1], matches[:ver2]) == long_to_short(ver1, ver2) &&
|
207
|
+
long_to_short(matches[:rev1], matches[:rev2]) == long_to_short(rev1, rev2) &&
|
208
|
+
long_to_short(matches[:add1], matches[:add2]) == add || item.hit[:title].include?(text.sub(/^NIST\s/, ""))
|
209
|
+
end
|
210
|
+
|
211
|
+
# @param short [String]
|
212
|
+
# @param long [String]
|
213
|
+
# @return [String, nil]
|
214
|
+
def long_to_short(short, long)
|
215
|
+
return short.sub(/-/, "") if short
|
216
|
+
return unless long
|
217
|
+
|
218
|
+
long.sub(/Part\s/, "pt").sub(/Vol\.\s/, "v").sub(/Rev\.\s/, "r").sub(/(Ver\.|Version)\s/, "ver")
|
132
219
|
end
|
133
220
|
|
134
221
|
def fetch_ref_err(code, year, missed_years)
|
@@ -110,9 +110,10 @@ module RelatonNist
|
|
110
110
|
"//div[contains(@class, 'publications-detail')]/h3"
|
111
111
|
)&.text&.strip&.sub(/(?<=\w)\([^\)]+\)$/) do |m|
|
112
112
|
" " + m.upcase
|
113
|
-
end&.squeeze(" ")&.gsub
|
113
|
+
end&.squeeze(" ")&.gsub(/ |\n|\r/, "")
|
114
114
|
end
|
115
115
|
item_ref ||= "?"
|
116
|
+
item_ref.sub! /\sAddendum$/, "-Add"
|
116
117
|
[RelatonBib::DocumentIdentifier.new(id: item_ref, type: "NIST")]
|
117
118
|
end
|
118
119
|
|
data/lib/relaton_nist/version.rb
CHANGED
data/relaton_nist.gemspec
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.
|
4
|
+
version: 1.7.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: 2020-
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debase
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
159
|
+
version: 1.7.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
166
|
+
version: 1.7.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rubyzip
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|