relaton-nist 1.12.3 → 1.12.4

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: ef6eeb64c2dba6079789c3192b6c335f3726af48bd43b580bc5c05cf8c8b12f9
4
- data.tar.gz: c58fa9cf63309bd404ad04797b92f1dd3f2cc0635cb061ee1211cfc9bf8e841c
3
+ metadata.gz: a08c33ae20e118a973b19b9697114dd4be09331bc3322a3d75250959c4cb0880
4
+ data.tar.gz: 1066aab4db2167b2551fd59a76248a96bbcfddbbcc11e0894cb16d91af0fe69c
5
5
  SHA512:
6
- metadata.gz: b59ef8bf5ce4d0b637cb0072cb6d18c4ddbfa07170a95095df0ed95395039c19cc2f59b9a28d852dd59f357e204b3ec50c8825fb30f5049106edc0705696b6da
7
- data.tar.gz: 22e2b8ede68f9cdd45bd921d06ba4f36c824bbc8115f3a40960d8b9f8c6f03efa8ff20d310771f8b4db30a388794654fd9e58313f6e10f4677b0945f4b67e8f8
6
+ metadata.gz: e0b46445fda68e042630f4eccfc925a317dbe22a3331fe5ef86eebcceb7a036134bedba1a2b6679987d4a2b727ee2590887d52a26c014adbbd27b382b70b2adc
7
+ data.tar.gz: cdc10291398c3f037a00f7a2b013f3a159ed1b8803a0d401522cfb4df0119036cd7b1a9cbfb28ebdf05819a4f365fd4bc0d284fc3031ef34311418e279e35eba
data/README.adoc CHANGED
@@ -1,4 +1,4 @@
1
- = RelatonNist: retrieve NIST Standards for bibliographic use using the BibliographicItem model
1
+ = Relaton for NIST: bibliographic retrieval of NIST publications
2
2
 
3
3
  image:https://img.shields.io/gem/v/relaton-nist.svg["Gem Version", link="https://rubygems.org/gems/relaton-nist"]
4
4
  image:https://github.com/relaton/relaton-nist/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/relaton/relaton-nist/actions?workflow=macos"]
@@ -8,10 +8,41 @@ image:https://codeclimate.com/github/relaton/relaton-nist/badges/gpa.svg["Code C
8
8
  image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-nist.svg["Pull Requests", link="https://github.com/relaton/relaton-nist/pulls"]
9
9
  image:https://img.shields.io/github/commits-since/relaton/relaton-nist/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-nist/releases"]
10
10
 
11
+ == Purpose
11
12
 
12
- RelatonNist is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
13
+ `relaton-nist` provides bibliographic information of NIST publications using the
14
+ https://github.com/metanorma/metanorma-model-nist#nist-bibliographic-item-model[NistBibliographicItem model].
15
+
16
+ Relaton for NIST has been developed in cooperation with the NIST Cybersecurity
17
+ Resource Center (CSRC) and the Computer Security Division (ITL/CSD).
18
+
19
+ == Data sources
20
+
21
+ Relaton for NIST retrieves bibliographic information from two sources:
22
+
23
+ * bibliographic feed from the NIST Cybersecurity Resource Center (CSRC) of
24
+ all CSRC publications (in Relaton JSON)
25
+ * bibliographic dataset from the NIST Library through the Information Services
26
+ Office (ISO) that contains information about all NIST Technical Publications
27
+ (https://github.com/usnistgov/NIST-Tech-Pubs[GitHub])
28
+
29
+ Bibliographic information offered through CSRC are provided with enhanced
30
+ metadata that is not available at the NIST Library dataset, including:
31
+
32
+ * public drafts (the NIST Library dataset only contains final publications)
33
+ * revision information: revision number, iteration
34
+ * document stage information: retired, withdrawn, etc.
35
+ * bibliographic dates, including issued date, updated date, published date,
36
+ obsolete date, commenting period
37
+ * document relationships: supersession and replacements
38
+ * contacts: enhanced name parts and affiliation information
39
+
40
+ Relaton for NIST therefore uses the following order of priority for the data
41
+ sources:
42
+
43
+ . bibliographic feed from NIST CSRC
44
+ . NIST Library dataset
13
45
 
14
- You can use it to retrieve metadata of NIST Standards from https://csrc.nist.gov, and access such metadata through the `IsoBibliographicItem` object.
15
46
 
16
47
  == Installation
17
48
 
@@ -14,7 +14,7 @@ module RelatonNist
14
14
  # @return [Iteger]
15
15
  def sort_value # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
16
16
  @sort_value ||= begin
17
- sort_phrase = [hit[:serie], hit[:code], hit[:title]].join " "
17
+ sort_phrase = [hit[:series], hit[:code], hit[:title]].join " "
18
18
  corr = hit_collection&.text&.split&.map do |w|
19
19
  if w =~ /\w+/ &&
20
20
  sort_phrase =~ Regexp.new(Regexp.escape(w), Regexp::IGNORECASE)
@@ -25,8 +25,75 @@ module RelatonNist
25
25
  sort_hits!
26
26
  end
27
27
 
28
+ # @return [Array<RelatonNist::Hit>]
29
+ def search_filter # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
30
+ @array.select do |item|
31
+ %r{
32
+ ^(?:(?:NIST|NBS)\s?)?
33
+ (?:(?<series>(?:SP|FIPS|IR|ITL\sBulletin|White\sPaper))\s)?
34
+ (?<code>[0-9-]{3,}[A-Z]?)
35
+ (?<prt1>pt\d+)?
36
+ (?<vol1>v\d+)?
37
+ (?<ver1>ver[\d.]+)?
38
+ (?<rev1>r\d+)?
39
+ (?:\s(?<prt2>Part\s\d+))?
40
+ (?:\s(?<vol2>Vol\.\s\d+))?
41
+ (?:\s(?<ver2>(?:Ver\.|Version)\s[\d.]+))?
42
+ (?:\s(?<rev2>Rev\.\s\d+))?
43
+ (?:\s(?<add>Add)endum)?
44
+ }x =~ item.hit[:code]
45
+ (refparts[:code] && [series, item.hit[:series]].include?(refparts[:series]) && refparts[:code] == code &&
46
+ long_to_short(refparts[:prt1], refparts[:prt2]) == long_to_short(prt1, prt2) &&
47
+ long_to_short(refparts[:vol1], refparts[:vol2]) == long_to_short(vol1, vol2) &&
48
+ long_to_short(refparts[:ver1], refparts[:ver2]) == long_to_short(ver1, ver2) &&
49
+ long_to_short(refparts[:rev1], refparts[:rev2]) == long_to_short(rev1, rev2) &&
50
+ long_to_short(refparts[:add1], refparts[:add2]) == add) || item.hit[:title]&.include?(text.sub(/^NIST\s/, ""))
51
+ end
52
+ end
53
+
28
54
  private
29
55
 
56
+ def refparts # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
57
+ @refparts ||= {
58
+ perfix: match(/^(NIST|NBS)\s?/, text),
59
+ series: match(/(SP|FIPS|IR|ITL\sBulletin|White\sPaper)(?=\.|\s)/, text),
60
+ code: match(/(?<=\.|\s)[0-9-]{3,}[A-Z]?/, text),
61
+ prt1: match(/(?<=(\.))?pt(?(1)-)[A-Z\d]+/, text),
62
+ vol1: match(/(?<=(\.))?v(?(1)-)\d+/, text),
63
+ ver1: match(/(?<=(\.))?ver(?(1)[-\d]|[.\d])+/, text)&.gsub(/-/, "."),
64
+ rev1: match(/(?<=[^a-z])(?<=(\.))?r(?(1)-)\d+/, text),
65
+ add1: match(/(?<=(\.))?add(?(1)-)\d+/, text),
66
+ prt2: match(/(?<=\s)Part\s[A-Z\d]+/, text),
67
+ vol2: match(/(?<=\s)Vol\.\s\d+/, text),
68
+ ver2: match(/(?<=\s)Ver\.\s\d+/, text),
69
+ rev2: match(/(?<=\s)Rev\.\s\d+/, text),
70
+ add2: match(/(?<=\/)Add/, text),
71
+ }
72
+ end
73
+
74
+ def match(regex, code)
75
+ regex.match(code)&.to_s
76
+ end
77
+
78
+ def full_ref # rubocop:disable Metrics/AbcSize
79
+ @full_ref ||= begin
80
+ ref = "#{refparts[:perfix]}#{refparts[:series]} #{refparts[:code]}"
81
+ ref += long_to_short(refparts[:prt1], refparts[:prt2]).to_s
82
+ ref += long_to_short(refparts[:vol1], refparts[:vol2]).to_s
83
+ ref
84
+ end
85
+ end
86
+
87
+ # @param short [String]
88
+ # @param long [String]
89
+ # @return [String, nil]
90
+ def long_to_short(short, long)
91
+ return short.sub(/-/, "") if short
92
+ return unless long
93
+
94
+ long.sub(/Part\s/, "pt").sub(/Vol\.\s/, "v").sub(/Rev\.\s/, "r").sub(/(Ver\.|Version)\s/, "ver")
95
+ end
96
+
30
97
  def sort_hits!
31
98
  @array.sort! do |a, b|
32
99
  if a.sort_value == b.sort_value
@@ -39,7 +106,8 @@ module RelatonNist
39
106
  end
40
107
 
41
108
  def from_ga # rubocop:disable Metrics/AbcSize
42
- fn = text.gsub(%r{[/\s:.]}, "_").upcase
109
+ ref = full_ref
110
+ fn = ref.gsub(%r{[/\s:.]}, "_").upcase
43
111
  yaml = OpenURI.open_uri "#{GHNISTDATA}#{fn}.yaml"
44
112
  hash = YAML.safe_load yaml
45
113
  bib = RelatonNist::NistBibliographicItem.from_hash hash
@@ -52,55 +120,15 @@ module RelatonNist
52
120
  raise e
53
121
  end
54
122
 
55
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
56
-
57
- # @param stage [String]
58
- # @return [Array<RelatonNist::Hit>]
59
- # def from_csrc(**opts)
60
- # from, to = nil
61
- # if year
62
- # d = Date.strptime year, "%Y"
63
- # from = d.strftime "%m/%d/%Y"
64
- # to = d.next_year.prev_day.strftime "%m/%d/%Y"
65
- # end
66
- # url = "#{DOMAIN}/publications/search?keywords-lg=#{text}"\
67
- # "&sortBy-lg=relevence"
68
- # url += "&dateFrom-lg=#{from}" if from
69
- # url += "&dateTo-lg=#{to}" if to
70
- # url += if /PD/.match? opts[:stage]
71
- # "&status-lg=Draft,Retired Draft,Withdrawn"
72
- # else
73
- # "&status-lg=Final,Withdrawn"
74
- # end
75
-
76
- # doc = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize)
77
- # doc.css("table.publications-table > tbody > tr").map do |h|
78
- # link = h.at("td/div/strong/a")
79
- # serie = h.at("td[1]").text.strip
80
- # code = h.at("td[2]").text.strip
81
- # title = link.text
82
- # doc_url = DOMAIN + link[:href]
83
- # status = h.at("td[4]").text.strip.downcase
84
- # release_date = Date.strptime h.at("td[5]").text.strip, "%m/%d/%Y"
85
- # Hit.new(
86
- # {
87
- # code: code, serie: serie, title: title, url: doc_url,
88
- # status: status, release_date: release_date
89
- # }, self
90
- # )
91
- # end
92
- # end
93
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
94
-
95
123
  # Fetches data form json
96
124
  # @param stage [String]
97
125
  # @return [Array<RelatonNist::Hit>]
98
126
  def from_json(**opts)
99
127
  select_data(**opts).map do |h|
100
- /(?<serie>(?<=-)\w+$)/ =~ h["series"]
128
+ /(?<series>(?<=-)\w+$)/ =~ h["series"]
101
129
  title = [h["title-main"], h["title-sub"]].compact.join " - "
102
130
  release_date = RelatonBib.parse_date h["published-date"], false
103
- Hit.new({ code: h["docidentifier"], serie: serie.upcase, title: title,
131
+ Hit.new({ code: h["docidentifier"], series: series.upcase, title: title,
104
132
  url: h["uri"], status: h["status"],
105
133
  release_date: release_date, json: h }, self)
106
134
  end
@@ -109,6 +137,7 @@ module RelatonNist
109
137
  # @param stage [String]
110
138
  # @return [Array<Hach>]
111
139
  def select_data(**opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
140
+ ref = "#{refparts[:series]} #{refparts[:code]}"
112
141
  d = Date.strptime year, "%Y" if year
113
142
  statuses = %w[draft-public draft-prelim]
114
143
  data.select do |doc|
@@ -119,7 +148,7 @@ module RelatonNist
119
148
  else
120
149
  next unless doc["status"] == "final"
121
150
  end
122
- doc["docidentifier"].include? text
151
+ doc["docidentifier"].include?(ref) || doc["docidentifier"].include?(full_ref)
123
152
  end
124
153
  end
125
154
 
@@ -147,7 +176,6 @@ module RelatonNist
147
176
  #
148
177
  # @prarm ctime [Time, NilClass]
149
178
  def fetch_data(ctime)
150
- # resp = OpenURI.open_uri("#{PUBS_EXPORT}.meta")
151
179
  if !ctime || ctime < OpenURI.open_uri("#{PUBS_EXPORT}.meta").last_modified
152
180
  @data = nil
153
181
  uri_open = URI.method(:open) || Kernel.method(:open)
@@ -56,12 +56,12 @@ module RelatonNist
56
56
  end
57
57
 
58
58
  code += "-1" if opts[:all_parts]
59
- nistbib_get1(code, year, opts)
59
+ nistbib_get(code, year, opts)
60
60
  end
61
61
 
62
62
  private
63
63
 
64
- def nistbib_get1(code, year, opts)
64
+ def nistbib_get(code, year, opts)
65
65
  result = nistbib_search_filter(code, year, opts) || (return nil)
66
66
  ret = nistbib_results_filter(result, year, opts)
67
67
  if ret[:ret]
@@ -85,7 +85,7 @@ module RelatonNist
85
85
  # @option opts [String] :stage
86
86
  #
87
87
  # @return [Hash]
88
- def nistbib_results_filter(result, year, opts)
88
+ def nistbib_results_filter(result, year, opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
89
89
  missed_years = []
90
90
  iter = /\w+(?=PD)|(?<=PD-)\w+/.match(opts[:stage])&.to_s
91
91
  iteration = case iter
@@ -134,111 +134,23 @@ module RelatonNist
134
134
  # @param year [String, nil]
135
135
  # @param opts [Hash]
136
136
  # @return [RelatonNist::HitCollection]
137
- def nistbib_search_filter(code, year, opts) # rubocop:disable Metrics/MethodLength
137
+ def nistbib_search_filter(code, year, opts)
138
138
  warn "[relaton-nist] (\"#{code}\") fetching..."
139
- # match = %r{
140
- # ^((?:NIST)\s)?
141
- # (?<serie>(SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s
142
- # (?<code>[0-9-]{3,}[A-Z]?)
143
- # (?<prt1>pt\d+)?
144
- # (?<vol1>v\d+)?
145
- # (?<ver1>ver[\d\.]+)?
146
- # (?<rev1>r\d+)?
147
- # (\s(?<prt2>Part\s\d+))?
148
- # (\s(?<vol2>Vol\.\s\d+))?
149
- # (\s(?<ver2>(Ver\.|Version)\s[\d\.]+))?
150
- # (\s(?<rev2>Rev\.\s\d+))?
151
- # (\/(?<upd>Add))?
152
- # }x.match(code)
153
- # match ||= %r{
154
- # ^NIST\.
155
- # (?<serie>(SP|FIPS|IR|ITL\sBulletin|White\sPaper))\.
156
- # ((PD-\d+|PUB)\.)?
157
- # (?<code>[0-9-]{3,}[A-Z]?)
158
- # (\.(?<prt1>pt-\d+))?
159
- # (\.(?<vol1>v-\d+))?
160
- # (\.(?<ver1>ver-[\d\.]+))?
161
- # (\.(?<rev1>r-\d+))?
162
- # }x.match(code)
163
- matches = {
164
- serie: match(/(SP|FIPS|(NIST)?\s?IR|ITL\sBulletin|White\sPaper)(?=\.|\s)/, code),
165
- code: match(/(?<=\.|\s)[0-9-]{3,}[A-Z]?/, code),
166
- prt1: match(/(?<=(\.))?pt(?(1)-)[A-Z\d]+/, code),
167
- vol1: match(/(?<=(\.))?v(?(1)-)\d+/, code),
168
- ver1: match(/(?<=(\.))?ver(?(1)[-\d]|[\.\d])+/, code)&.gsub(/-/, "."),
169
- rev1: match(/(?<=[^a-z])(?<=(\.))?r(?(1)-)\d+/, code),
170
- add1: match(/(?<=(\.))?add(?(1)-)\d+/, code),
171
- prt2: match(/(?<=\s)Part\s[A-Z\d]+/, code),
172
- vol2: match(/(?<=\s)Vol\.\s\d+/, code),
173
- ver2: match(/(?<=\s)Ver\.\s\d+/, code),
174
- rev2: match(/(?<=\s)Rev\.\s\d+/, code),
175
- add2: match(/(?<=\/)Add/, code),
176
- }
177
- ref = matches[:code] ? "#{matches[:serie]} #{matches[:code]}" : code
178
- result = search(ref, year, opts)
179
- selected_result = result.select { |i| search_filter i, matches, code }
180
- return selected_result if selected_result.any? || !matches[:code]
181
-
182
- search full_ref(matches)
183
- end
184
-
185
- def full_ref(matches)
186
- ref = "#{matches[:serie]} #{matches[:code]}"
187
- ref += long_to_short(matches[:prt1], matches[:prt2]).to_s
188
- ref += long_to_short(matches[:vol1], matches[:vol2]).to_s
189
- ref
190
- end
191
-
192
- def match(regex, code)
193
- regex.match(code)&.to_s
194
- end
195
-
196
- # @param item [RelatonNist::Hit]
197
- # @param matches [Hash]
198
- # @param text [String]
199
- # @return [Boolean]
200
- def search_filter(item, matches, text) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
201
- %r{
202
- ^(?:(?:NIST)\s)?
203
- (?:(?<serie>(?:SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s)?
204
- (?<code>[0-9-]{3,}[A-Z]?)
205
- (?<prt1>pt\d+)?
206
- (?<vol1>v\d+)?
207
- (?<ver1>ver[\d.]+)?
208
- (?<rev1>r\d+)?
209
- (?:\s(?<prt2>Part\s\d+))?
210
- (?:\s(?<vol2>Vol\.\s\d+))?
211
- (?:\s(?<ver2>(?:Ver\.|Version)\s[\d.]+))?
212
- (?:\s(?<rev2>Rev\.\s\d+))?
213
- (?:\s(?<add>Add)endum)?
214
- }x =~ item.hit[:code]
215
- (matches[:code] && [serie, item.hit[:serie]].include?(matches[:serie]) && matches[:code] == code &&
216
- long_to_short(matches[:prt1], matches[:prt2]) == long_to_short(prt1, prt2) &&
217
- long_to_short(matches[:vol1], matches[:vol2]) == long_to_short(vol1, vol2) &&
218
- long_to_short(matches[:ver1], matches[:ver2]) == long_to_short(ver1, ver2) &&
219
- long_to_short(matches[:rev1], matches[:rev2]) == long_to_short(rev1, rev2) &&
220
- long_to_short(matches[:add1], matches[:add2]) == add) || item.hit[:title]&.include?(text.sub(/^NIST\s/, ""))
221
- end
222
-
223
- # @param short [String]
224
- # @param long [String]
225
- # @return [String, nil]
226
- def long_to_short(short, long)
227
- return short.sub(/-/, "") if short
228
- return unless long
229
-
230
- long.sub(/Part\s/, "pt").sub(/Vol\.\s/, "v").sub(/Rev\.\s/, "r").sub(/(Ver\.|Version)\s/, "ver")
139
+ result = search(code, year, opts)
140
+ result.search_filter
231
141
  end
232
142
 
233
- def fetch_ref_err(code, year, missed_years)
143
+ def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
234
144
  id = year ? "#{code}:#{year}" : code
235
- warn "[relaton-nist] WARNING: no match found online for #{id}. "\
236
- "The code must be exactly like it is on the standards website."
237
- warn "[relaton-nist] (There was no match for #{year}, though there were matches "\
238
- "found for #{missed_years.join(', ')}.)" unless missed_years.empty?
239
- if /\d-\d/ =~ code
240
- warn "[relaton-nist] The provided document part may not exist, "\
241
- "or the document may no longer be published in parts."
145
+ warn "[relaton-nist] WARNING: no match found online for #{id}. " \
146
+ "The code must be exactly like it is on the standards website."
147
+ unless missed_years.empty?
148
+ warn "[relaton-nist] (There was no match for #{year}, though there " \
149
+ "were matches found for #{missed_years.join(', ')}.)"
150
+ end
151
+ if /\d-\d/.match? code
152
+ warn "[relaton-nist] The provided document part may not exist, " \
153
+ "or the document may no longer be published in parts."
242
154
  end
243
155
  nil
244
156
  end
@@ -5,7 +5,7 @@ module RelatonNist
5
5
  def initialize # rubocop:disable Lint/MissingSuper
6
6
  @short = :relaton_nist
7
7
  @prefix = "NIST"
8
- @defaultprefix = %r{^(NIST|NISTGCR|ITL Bulletin|JPCRD|NISTIR|CSRC|FIPS)(/[^\s])?\s}
8
+ @defaultprefix = %r{^(NIST|NBS|NISTGCR|ITL Bulletin|JPCRD|NISTIR|CSRC|FIPS)(/[^\s])?\s}
9
9
  @idtype = "NIST"
10
10
  @datasets = %w[nist-tech-pubs]
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.12.3".freeze
2
+ VERSION = "1.12.4".freeze
3
3
  end
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.12.3
4
+ version: 1.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-15 00:00:00.000000000 Z
11
+ date: 2022-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml