relaton-nist 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/grammars/nist.rng CHANGED
@@ -194,6 +194,9 @@
194
194
  <zeroOrMore>
195
195
  <ref name="termdocsource"/>
196
196
  </zeroOrMore>
197
+ <optional>
198
+ <ref name="misccontainer"/>
199
+ </optional>
197
200
  <optional>
198
201
  <ref name="boilerplate"/>
199
202
  </optional>
@@ -207,6 +210,9 @@
207
210
  <optional>
208
211
  <ref name="bibliography"/>
209
212
  </optional>
213
+ <zeroOrMore>
214
+ <ref name="indexsect"/>
215
+ </zeroOrMore>
210
216
  </element>
211
217
  </define>
212
218
  </grammar>
data/grammars/reqt.rng CHANGED
@@ -30,15 +30,34 @@
30
30
  <data type="boolean"/>
31
31
  </attribute>
32
32
  </optional>
33
+ <optional>
34
+ <attribute name="number"/>
35
+ </optional>
33
36
  <optional>
34
37
  <attribute name="subsequence"/>
35
38
  </optional>
39
+ <optional>
40
+ <attribute name="keep-with-next">
41
+ <data type="boolean"/>
42
+ </attribute>
43
+ </optional>
44
+ <optional>
45
+ <attribute name="keep-lines-together">
46
+ <data type="boolean"/>
47
+ </attribute>
48
+ </optional>
36
49
  <attribute name="id">
37
50
  <data type="ID"/>
38
51
  </attribute>
39
52
  <optional>
40
53
  <attribute name="filename"/>
41
54
  </optional>
55
+ <optional>
56
+ <attribute name="model"/>
57
+ </optional>
58
+ <optional>
59
+ <attribute name="type"/>
60
+ </optional>
42
61
  <optional>
43
62
  <ref name="reqtitle"/>
44
63
  </optional>
@@ -48,9 +67,9 @@
48
67
  <optional>
49
68
  <ref name="subject"/>
50
69
  </optional>
51
- <optional>
70
+ <zeroOrMore>
52
71
  <ref name="reqinherit"/>
53
- </optional>
72
+ </zeroOrMore>
54
73
  <zeroOrMore>
55
74
  <ref name="classification"/>
56
75
  </zeroOrMore>
@@ -135,6 +154,16 @@
135
154
  <data type="boolean"/>
136
155
  </attribute>
137
156
  </optional>
157
+ <optional>
158
+ <attribute name="keep-with-next">
159
+ <data type="boolean"/>
160
+ </attribute>
161
+ </optional>
162
+ <optional>
163
+ <attribute name="keep-lines-together">
164
+ <data type="boolean"/>
165
+ </attribute>
166
+ </optional>
138
167
  <oneOrMore>
139
168
  <ref name="BasicBlock"/>
140
169
  </oneOrMore>
@@ -18,13 +18,13 @@ module RelatonNist
18
18
  # @param item_hash [Hash]
19
19
  # @return [RelatonNist::NistBibliographicItem]
20
20
  def bib_item(item_hash)
21
- NistBibliographicItem.new item_hash
21
+ NistBibliographicItem.new **item_hash
22
22
  end
23
23
 
24
24
  def commentperiod_hash_to_bib(ret)
25
25
  return unless ret[:commentperiod]
26
26
 
27
- ret[:commentperiod] = CommentPeriod.new ret[:commentperiod]
27
+ ret[:commentperiod] = CommentPeriod.new **ret[:commentperiod]
28
28
  end
29
29
 
30
30
  # @param ret [Hash]
@@ -32,7 +32,7 @@ module RelatonNist
32
32
  super
33
33
  return unless ret[:relation]
34
34
 
35
- ret[:relation] = ret[:relation].map { |r| DocumentRelation.new r }
35
+ ret[:relation] = ret[:relation].map { |r| DocumentRelation.new **r }
36
36
 
37
37
  # ret[:relation] = array(ret[:relation])
38
38
  # ret[:relation]&.each do |r|
@@ -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-]+\w?)/ =~ text
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
@@ -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"] =~ didrx
109
+ doc["docidentifier"].include? docid
108
110
  end
109
111
  end
110
112
 
@@ -63,6 +63,13 @@ module RelatonNist
63
63
  super
64
64
  end
65
65
 
66
+ # @param hash [Hash]
67
+ # @return [RelatonNist::GbBibliographicItem]
68
+ def self.from_hash(hash)
69
+ item_hash = RelatonNist::HashConverter.hash_to_bib(hash)
70
+ new **item_hash
71
+ end
72
+
66
73
  # @param opts [Hash]
67
74
  # @option opts [Nokogiri::XML::Builder] :builder XML builder
68
75
  # @option opts [Boolean] :bibdata
@@ -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 =~ /\sEP$/
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}/ =~ date2
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}/ =~ date2
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
- # @retur [Hash]
85
+ # @return [Hash]
85
86
  def nistbib_results_filter(result, year, opts)
86
87
  missed_years = []
87
- iter = opts[:stage]&.slice(-3, 1)
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"
@@ -116,6 +117,9 @@ module RelatonNist
116
117
  { years: missed_years }
117
118
  end
118
119
 
120
+ # @param hits [RelatonNist::HitCollection]
121
+ # @param threads [Integer]
122
+ # @return [Array<RelatonNist::NistBibliographicItem>]
119
123
  def fetch_pages(hits, threads)
120
124
  workers = RelatonBib::WorkersPool.new threads
121
125
  workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
@@ -124,15 +128,94 @@ module RelatonNist
124
128
  workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
125
129
  end
126
130
 
127
- def nistbib_search_filter(code, year, opts)
128
- idregex = %r{[0-9-]{3,}\w?}
129
- docid = code.match(idregex).to_s
130
- serie = code.match(%r{(FISP|SP|NISTIR)(?=\s)})
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
131
136
  warn "[relaton-nist] (\"#{code}\") fetching..."
132
- result = search(code, year, opts)
133
- result.select do |i|
134
- i.hit[:code]&.match(idregex).to_s == docid && (!serie || i.hit[:serie] == serie.to_s)
135
- end
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")
136
219
  end
137
220
 
138
221
  def fetch_ref_err(code, year, missed_years)
@@ -26,8 +26,7 @@ module RelatonNist
26
26
  # @param hash [Hash]
27
27
  # @return [RelatonNist::GbBibliographicItem]
28
28
  def hash_to_bib(hash)
29
- item_hash = ::RelatonNist::HashConverter.hash_to_bib(hash)
30
- ::RelatonNist::NistBibliographicItem.new item_hash
29
+ ::RelatonNist::NistBibliographicItem.from_hash hash
31
30
  end
32
31
 
33
32
  # Returns hash of XML grammar
@@ -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 /&#13;|\n|\r/, ""
113
+ end&.squeeze(" ")&.gsub(/&#13;|\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
 
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.7.0".freeze
2
+ VERSION = "1.8.0".freeze
3
3
  end
@@ -17,7 +17,7 @@ module RelatonNist
17
17
  # @param item_hash [Hash]
18
18
  # @return [RelatonNist::NistBibliographicItem]
19
19
  def bib_item(item_hash)
20
- NistBibliographicItem.new item_hash
20
+ NistBibliographicItem.new **item_hash
21
21
  end
22
22
 
23
23
  def fetch_status(item)
data/relaton_nist.gemspec CHANGED
@@ -23,17 +23,17 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
25
25
 
26
- spec.add_development_dependency "debase"
26
+ # spec.add_development_dependency "debase"
27
27
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
28
28
  spec.add_development_dependency "pry-byebug"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "ruby-debug-ide"
31
+ # spec.add_development_dependency "ruby-debug-ide"
32
32
  spec.add_development_dependency "ruby-jing"
33
33
  spec.add_development_dependency "simplecov"
34
34
  spec.add_development_dependency "vcr"
35
35
  spec.add_development_dependency "webmock"
36
36
 
37
- spec.add_dependency "relaton-bib", "~> 1.7.0"
37
+ spec.add_dependency "relaton-bib", "~> 1.8.0"
38
38
  spec.add_dependency "rubyzip"
39
39
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
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-27 00:00:00.000000000 Z
11
+ date: 2021-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: debase
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: equivalent-xml
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +66,6 @@ dependencies:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: ruby-debug-ide
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: ruby-jing
99
71
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +128,14 @@ dependencies:
156
128
  requirements:
157
129
  - - "~>"
158
130
  - !ruby/object:Gem::Version
159
- version: 1.7.0
131
+ version: 1.8.0
160
132
  type: :runtime
161
133
  prerelease: false
162
134
  version_requirements: !ruby/object:Gem::Requirement
163
135
  requirements:
164
136
  - - "~>"
165
137
  - !ruby/object:Gem::Version
166
- version: 1.7.0
138
+ version: 1.8.0
167
139
  - !ruby/object:Gem::Dependency
168
140
  name: rubyzip
169
141
  requirement: !ruby/object:Gem::Requirement
@@ -185,9 +157,7 @@ executables: []
185
157
  extensions: []
186
158
  extra_rdoc_files: []
187
159
  files:
188
- - ".github/workflows/macos.yml"
189
- - ".github/workflows/ubuntu.yml"
190
- - ".github/workflows/windows.yml"
160
+ - ".github/workflows/rake.yml"
191
161
  - ".gitignore"
192
162
  - ".rspec"
193
163
  - ".rubocop.yml"
@@ -236,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
206
  - !ruby/object:Gem::Version
237
207
  version: '0'
238
208
  requirements: []
239
- rubygems_version: 3.0.6
209
+ rubygems_version: 3.2.3
240
210
  signing_key:
241
211
  specification_version: 4
242
212
  summary: 'RelatonNist: retrive NIST standards.'