relaton-nist 1.9.2 → 1.9.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: 76cfec1954dfd58bf622a6a47e34bdbcfe4cf471106eb7ad19582654078a6d38
4
- data.tar.gz: 9769f406d5b98840b5bc099d78ab811388170d1fae5872211a7a0c9ed26d869f
3
+ metadata.gz: ea210109d9e306b8c9c6b4395812b52454dad6b8fdbd87cc08ec750e9dd2d4ac
4
+ data.tar.gz: e2dad0af3e66b42b2b5d5f2ecf48653ea21b2662d9bed9f6003a5b7a6d953f1d
5
5
  SHA512:
6
- metadata.gz: 0e3deefff699c77103afb631a03283697dc05f5c952b60b3602961df37df2095102b16c32e229aeeceb76da12cfda09e43e6b0788b6a4c1f02b74dea8a49f818
7
- data.tar.gz: 3244707d2595b5b45bab973399a04b8cc791d3b008e2ef05fcc99d9355cec6915556aea8528e5f992e4ba0452af82bda09fb93737741a72c08a64e7a0039d161
6
+ metadata.gz: '08a75dfaf1616874bab1c6edd2eb9a1f80c64a2d8d052dd66a3f4ca4f5b8aac1ee520c397f62327d718865fbd5f476db0e9a4ebef445ae3ecbe6f0366ee75e66'
7
+ data.tar.gz: cae6a5c20af9c77ead564ee5337d3092356a1786337406c260e75a387cc0446bd9937a23b2a24d1eafcc5b0bb1e98a621288e091634b7d950d112d96f13019cf
data/README.adoc CHANGED
@@ -147,6 +147,17 @@ item.docidentifier.first.id
147
147
  => "SP 800-38A-Add"
148
148
  ----
149
149
 
150
+ === Typed links
151
+
152
+ NIST documents may have `src` and `doi` link types.
153
+
154
+ [source,ruby]
155
+ ----
156
+ item.link
157
+ => [#<RelatonBib::TypedUri:0x00007f901971dc10 @content=#<Addressable::URI:0x62c URI:https://csrc.nist.gov/publications/detail/sp/800-67/rev-2/final>, @type="src">,
158
+ #<RelatonBib::TypedUri:0x00007f901971d6e8 @content=#<Addressable::URI:0x640 URI:https://doi.org/10.6028/NIST.SP.800-67r2>, @type="doi">]
159
+ ----
160
+
150
161
  === Create bibliographic item from YAML
151
162
  [source,ruby]
152
163
  ----
@@ -167,7 +178,7 @@ The method `RelatonNist::DataFetcher.fetch(output: "data", format: "yaml")` fetc
167
178
  Arguments:
168
179
 
169
180
  - `output` - folder to save documents (default './data').
170
- - `format` - format in which the documents are saved. Possimle formats are: `yaml`, `xml` (default `yaml`).
181
+ - `format` - format in which the documents are saved. Possimle formats are: `yaml`, `xml`, `bibxxml` (default `yaml`).
171
182
 
172
183
  [source,ruby]
173
184
  ----
@@ -1,12 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require 'English'
4
- # require 'mechanize'
5
- # require "fileutils"
6
3
  require "yaml"
7
- # require "open-uri"
8
- # require "nokogiri"
9
- # require "relaton_nist"
10
4
 
11
5
  module RelatonNist
12
6
  class DataFetcher
@@ -23,6 +17,7 @@ module RelatonNist
23
17
  def initialize(output, format)
24
18
  @output = output
25
19
  @format = format
20
+ @ext = format.sub(/^bib/, "")
26
21
  end
27
22
 
28
23
  def parse_docid(doc)
@@ -151,7 +146,7 @@ module RelatonNist
151
146
  #
152
147
  def write_file(bib) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
153
148
  id = bib.docidentifier[0].id.gsub(%r{[/\s:.]}, "_").upcase.sub(/^NIST_IR/, "NISTIR")
154
- file = File.join(@output, "#{id}.#{@format}")
149
+ file = File.join(@output, "#{id}.#{@ext}")
155
150
  if File.exist? file
156
151
  warn "File #{file} exists. Docid: #{bib.docidentifier[0].id}"
157
152
  # warn "Link: #{bib.link.detect { |l| l.type == 'src' }.content}"
@@ -159,6 +154,7 @@ module RelatonNist
159
154
  output = case @format
160
155
  when "yaml" then bib.to_hash.to_yaml
161
156
  when "xml" then bib.to_xml bibdata: true
157
+ else bib.send "to_#{@format}"
162
158
  end
163
159
  File.write file, output, encoding: "UTF-8"
164
160
  end
@@ -197,7 +193,7 @@ module RelatonNist
197
193
 
198
194
  docs = Nokogiri::XML OpenURI.open_uri URL
199
195
  FileUtils.mkdir @output unless Dir.exist? @output
200
- FileUtils.rm Dir[File.join(@output, "*.#{@format}")]
196
+ FileUtils.rm Dir[File.join(@output, "*.#{@ext}")]
201
197
  docs.xpath("/body/query/doi_record/report-paper/report-paper_metadata")
202
198
  .each { |doc| parse_doc doc }
203
199
 
@@ -212,7 +208,7 @@ module RelatonNist
212
208
  # Fetch all the documnts from dataset
213
209
  #
214
210
  # @param [String] output foldet name to save the documents
215
- # @param [String] format format to save the documents
211
+ # @param [String] format format to save the documents (yaml, xml, bibxml)
216
212
  #
217
213
  def self.fetch(output: "data", format: "yaml")
218
214
  new(output, format).fetch
@@ -2,7 +2,7 @@ require "relaton/processor"
2
2
 
3
3
  module RelatonNist
4
4
  class Processor < Relaton::Processor
5
- def initialize
5
+ def initialize # rubocop:disable Lint/MissingSuper
6
6
  @short = :relaton_nist
7
7
  @prefix = "NIST"
8
8
  @defaultprefix = %r{^(NIST|NISTGCR|ITL Bulletin|JPCRD|NISTIR|CSRC|FIPS)(/[^\s])?\s}
@@ -18,6 +18,14 @@ module RelatonNist
18
18
  ::RelatonNist::NistBibliography.get(code, date, opts)
19
19
  end
20
20
 
21
+ #
22
+ # Fetch all the documents from a source
23
+ #
24
+ # @param [String] _source source name
25
+ # @param [Hash] opts
26
+ # @option opts [String] :output directory to output documents
27
+ # @option opts [String] :format
28
+ #
21
29
  def fetch_data(_source, opts)
22
30
  DataFetcher.fetch(**opts)
23
31
  end
@@ -62,44 +62,10 @@ module RelatonNist
62
62
  # Fetch status.
63
63
  # @param doc [Hash]
64
64
  # @return [RelatonNist::DocumentStatus]
65
- def fetch_status(doc) # , status)
66
- # if doc.is_a? Hash
65
+ def fetch_status(doc)
67
66
  stage = doc["status"]
68
67
  subst = doc["substage"]
69
68
  iter = doc["iteration"] == "initial" ? 1 : doc["iteration"]
70
- # else
71
- # case status
72
- # when "draft (obsolete)"
73
- # stage = "draft-public"
74
- # subst = "withdrawn"
75
- # when "retired draft"
76
- # stage = "draft-public"
77
- # subst = "retired"
78
- # when "withdrawn"
79
- # stage = "final"
80
- # subst = "withdrawn"
81
- # when /^draft/
82
- # stage = "draft-public"
83
- # subst = "active"
84
- # else
85
- # stage = status
86
- # subst = "active"
87
- # end
88
-
89
- # iter = nil
90
- # if stage.include? "draft"
91
- # iter = 1
92
- # history = doc.xpath("//span[@id='pub-history-container']/a"\
93
- # "|//span[@id='pub-history-container']/span")
94
- # history.each_with_index do |h, idx|
95
- # next if h.name == "a"
96
-
97
- # iter = idx + 1 if idx.positive?
98
- # break
99
- # end
100
- # end
101
- # end
102
-
103
69
  RelatonNist::DocumentStatus.new stage: stage, substage: subst, iteration: iter.to_s
104
70
  end
105
71
 
@@ -132,7 +98,6 @@ module RelatonNist
132
98
  dates
133
99
  end
134
100
 
135
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
136
101
  # @param doc [Hash]
137
102
  # @return [Array<RelatonBib::ContributionInfo>]
138
103
  def fetch_contributors(doc)
@@ -144,23 +109,12 @@ module RelatonNist
144
109
  contribs + contributors_json(
145
110
  doc["editors"], "editor", doc["language"], doc["script"]
146
111
  )
147
- # else
148
- # name = "National Institute of Standards and Technology"
149
- # org = RelatonBib::Organization.new(
150
- # name: name, url: "www.nist.gov", abbreviation: "NIST",
151
- # )
152
- # contribs << RelatonBib::ContributionInfo.new(entity: org, role: [type: "publisher"])
153
- # authors = doc.at('//h4[.="Author(s)"]/following-sibling::p')
154
- # contribs += contributors(authors, "author")
155
- # editors = doc.at('//h4[.="Editor(s)"]/following-sibling::p')
156
- # contribs + contributors(editors, "editor")
157
- # end
158
112
  end
159
113
 
160
114
  # @param doc [Array<Hash>]
161
115
  # @param role [String]
162
116
  # @return [Array<RelatonBib::ContributionInfo>]
163
- def contributors_json(doc, role, lang = "en", script = "Latn")
117
+ def contributors_json(doc, role, lang = "en", script = "Latn") # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
164
118
  doc.map do |contr|
165
119
  if contr["affiliation"]
166
120
  if contr["affiliation"]["acronym"]
@@ -185,43 +139,6 @@ module RelatonNist
185
139
  end.compact
186
140
  end
187
141
 
188
- # rubocop:disable Metrics/CyclomaticComplexity
189
- # @param doc [Nokogiri::HTML::Element, Array<Hash>]
190
- # @param role [String]
191
- # @return [Array<RelatonBib::ContributionInfo>]
192
- # def contributors(doc, role, lang = "en", script = "Latn")
193
- # return [] if doc.nil?
194
-
195
- # doc.text.split(", ").map do |contr|
196
- # /(?<an>.+?)(\s+\((?<abbrev>.+?)\))?$/ =~ contr.strip
197
- # if abbrev && an.downcase !~ /(task|force|group)/ && an.split.size.between?(2, 3)
198
- # fullname = RelatonBib::FullName.new(
199
- # completename: RelatonBib::LocalizedString.new(an, lang, script)
200
- # )
201
- # case abbrev
202
- # when "NIST"
203
- # org_name = "National Institute of Standards and Technology"
204
- # url = "www.nist.gov"
205
- # when "MITRE"
206
- # org_name = abbrev
207
- # url = "www.mitre.org"
208
- # else
209
- # org_name = abbrev
210
- # url = nil
211
- # end
212
- # org = RelatonBib::Organization.new name: org_name, url: url, abbreviation: abbrev
213
- # affiliation = RelatonBib::Affiliation.new organization: org
214
- # entity = RelatonBib::Person.new(
215
- # name: fullname, affiliation: [affiliation],
216
- # )
217
- # else
218
- # entity = RelatonBib::Organization.new name: an, abbreviation: abbrev
219
- # end
220
- # RelatonBib::ContributionInfo.new entity: entity, role: [type: role]
221
- # end
222
- # end
223
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
224
-
225
142
  # @param name [Hash]
226
143
  # @param lang [Strong]
227
144
  # @param script [String]
@@ -253,80 +170,30 @@ module RelatonNist
253
170
  return unless doc["edition"]
254
171
 
255
172
  rev = doc["edition"]
256
- # else
257
- # return unless /(?<=Rev\.\s)(?<rev>\d+)/ =~ doc
258
- # end
259
-
260
173
  "Revision #{rev}"
261
174
  end
262
175
 
263
- # Fetch abstracts.
264
- # @param doc [Nokigiri::HTML::Document]
265
- # @return [Array<Hash>]
266
- # def fetch_abstract(doc)
267
- # abstract_content = doc.xpath(
268
- # '//div[contains(@class, "pub-abstract-callout")]/div[1]/p',
269
- # ).text
270
- # [{
271
- # content: abstract_content,
272
- # language: "en",
273
- # script: "Latn",
274
- # format: "text/plain",
275
- # }]
276
- # end
277
-
278
176
  # Fetch copyright.
279
177
  # @param doc [Nokogiri::HTL::Document, String]
280
178
  # @return [Array<Hash>]
281
179
  def fetch_copyright(doc)
282
180
  name = "National Institute of Standards and Technology"
283
181
  url = "www.nist.gov"
284
- # d = if doc.is_a? String then doc
285
- # else
286
- # doc.at("//span[@id='pub-release-date']")&.text&.strip
287
- # end
288
182
  from = doc&.match(/\d{4}/)&.to_s
289
183
  [{ owner: [{ name: name, abbreviation: "NIST", url: url }], from: from }]
290
184
  end
291
185
 
292
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
293
-
294
186
  # Fetch links.
295
187
  # @param doc [Hash]
296
188
  # @return [Array<Hash>]
297
189
  def fetch_link(doc)
298
190
  links = []
299
- # if doc.is_a? Hash
300
- links << { type: "uri", content: doc["uri"] } if doc["uri"]
301
- doi = "https://doi.org/" + doc["doi"] if doc["doi"]
302
- # else
303
- # pub = doc.at "//p/strong[contains(., 'Publication:')]"
304
- # pdf = pub&.at "./following-sibling::a[.=' Local Download']"
305
- # doi = pub&.at("./following-sibling::a[contains(.,'(DOI)')]")&.attr :href
306
- # links << { type: "pdf", content: pdf[:href] } if pdf
307
- # end
308
- links << { type: "doi", content: doi } if doi
191
+ links << { type: "src", content: doc["uri"] } if doc["uri"]
192
+ if doc["doi"]
193
+ links << { type: "doi", content: "https://doi.org/#{doc['doi']}" }
194
+ end
309
195
  links
310
196
  end
311
- # rubocop:enable Metrics/MethodLength
312
-
313
- # Fetch relations.
314
- # @param doc [Nokogiri::HTML::Document]
315
- # @return [Array<RelatonNist::DocumentRelation>]
316
- # def fetch_relations(doc)
317
- # relations = doc.xpath('//span[@id="pub-supersedes-container"]/a').map do |r|
318
- # doc_relation "supersedes", r.text, DOMAIN + r[:href]
319
- # end
320
-
321
- # relations += doc.xpath('//span[@id="pub-part-container"]/a').map do |r|
322
- # doc_relation "partOf", r.text, DOMAIN + r[:href]
323
- # end
324
-
325
- # relations + doc.xpath('//span[@id="pub-related-container"]/a').map do |r|
326
- # doc_relation "updates", r.text, DOMAIN + r[:href]
327
- # end
328
- # end
329
- # rubocop:enable Metrics/AbcSize
330
197
 
331
198
  def fetch_relations_json(doc)
332
199
  relations = doc["supersedes"].map do |r|
@@ -354,68 +221,12 @@ module RelatonNist
354
221
  )
355
222
  end
356
223
 
357
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
358
-
359
- # @param doc [Nokogiri::HTML::Document]
360
- # @return [Array<RelatonBib::Series>]
361
- # def fetch_series(doc)
362
- # series = doc.xpath "//span[@id='pub-history-container']/a"\
363
- # "|//span[@id='pub-history-container']/span"
364
- # series.map.with_index do |s, idx|
365
- # next if s.name == "span"
366
-
367
- # iter = if idx.zero? then "I"
368
- # else idx + 1
369
- # end
370
-
371
- # content = s.text.match(/^[^\(]+/).to_s.strip.squeeze " "
372
-
373
- # ref = case s.text
374
- # when /^Draft/
375
- # content.match(/(?<=Draft\s).+/).to_s + " (#{iter}PD)"
376
- # when /\(Draft\)/ then content + " (#{iter}PD)"
377
- # else content
378
- # end
379
-
380
- # fref = RelatonBib::FormattedRef.new(
381
- # content: ref, language: "en", script: "Latn", format: "text/plain",
382
- # )
383
- # RelatonBib::Series.new(formattedref: fref)
384
- # end.select { |s| s }
385
- # end
386
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
387
-
388
224
  # @param doc [Hash]
389
225
  # @return [Array<RelatonNist::Keyword>]
390
226
  def fetch_keywords(doc)
391
- # kws = if doc.is_a? Hash
392
- # doc["keywords"]
393
- # else
394
- # doc.xpath "//span[@id='pub-keywords-container']/span"
395
- # end
396
227
  doc["keywords"].map { |kw| kw.is_a?(String) ? kw : kw.text }
397
228
  end
398
229
 
399
- # rubocop:disable Metrics/AbcSize
400
- # @param doc [Nokogiri::HTML::Document]
401
- # @return [RelatonNist::CommentPeriod, NilClass]
402
- # def fetch_commentperiod(doc)
403
- # cp = doc.at "//span[@id='pub-comments-due']"
404
- # return unless cp
405
-
406
- # to = Date.strptime cp.text.strip, "%B %d, %Y"
407
-
408
- # d = doc.at("//span[@id='pub-release-date']").text.strip
409
- # from = Date.strptime(d, "%B %Y").to_s
410
-
411
- # ex = doc.at "//strong[contains(.,'The comment closing date has been "\
412
- # "extended to')]"
413
- # ext = ex&.text&.match(/\w+\s\d{2},\s\d{4}/).to_s
414
- # extended = ext.empty? ? nil : Date.strptime(ext, "%B %d, %Y")
415
- # CommentPeriod.new from: from, to: to, extended: extended
416
- # end
417
- # rubocop:enable Metrics/AbcSize
418
-
419
230
  # @param json [Hash]
420
231
  # @return [RelatonNist::CommentPeriod, NilClass]
421
232
  def fetch_commentperiod_json(json)
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.9.2".freeze
2
+ VERSION = "1.9.3".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.9.2
4
+ version: 1.9.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: 2021-09-03 00:00:00.000000000 Z
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml