relaton-nist 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.adoc +16 -0
- data/lib/relaton_nist/comment_period.rb +1 -1
- data/lib/relaton_nist/hash_converter.rb +30 -0
- data/lib/relaton_nist/nist_bibliography.rb +4 -3
- data/lib/relaton_nist/scrapper.rb +11 -8
- data/lib/relaton_nist/version.rb +1 -1
- data/lib/relaton_nist/xml_parser.rb +4 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2eafbe4c1cb7719d3f782f77547db4b759bd8c41
|
|
4
|
+
data.tar.gz: 912039be62b33bdf6fab94966614e5de7adea3ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e49aaf8910c7fc910da3f7581fd4f6dcc3fb9beb0dba9575ca266d4bc5edf2d9a0b013470308553c9a30f563aad84c5c7ae9d85ccbc4715bc8480e7bcb27ccc4
|
|
7
|
+
data.tar.gz: 84105c9c7612a47a9f3d6bebd873434147fa5a8e9ba0bedcc8ff0961939902eaf087fd3d08682eb2e45cbec10c262afabb4c5ec364d4f0e44262a061a6507048
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
relaton-nist (0.3.
|
|
4
|
+
relaton-nist (0.3.2)
|
|
5
5
|
relaton-bib (~> 0.3.0)
|
|
6
6
|
rubyzip
|
|
7
7
|
|
|
@@ -25,7 +25,7 @@ GEM
|
|
|
25
25
|
json (2.2.0)
|
|
26
26
|
method_source (0.9.2)
|
|
27
27
|
mini_portile2 (2.4.0)
|
|
28
|
-
nokogiri (1.10.
|
|
28
|
+
nokogiri (1.10.4)
|
|
29
29
|
mini_portile2 (~> 2.4.0)
|
|
30
30
|
pry (0.12.2)
|
|
31
31
|
coderay (~> 1.1.0)
|
|
@@ -35,7 +35,7 @@ GEM
|
|
|
35
35
|
pry (~> 0.10)
|
|
36
36
|
public_suffix (3.1.1)
|
|
37
37
|
rake (10.5.0)
|
|
38
|
-
relaton-bib (0.3.
|
|
38
|
+
relaton-bib (0.3.4)
|
|
39
39
|
addressable
|
|
40
40
|
nokogiri (~> 1.10)
|
|
41
41
|
rspec (3.8.0)
|
data/README.adoc
CHANGED
|
@@ -113,6 +113,22 @@ fetching 8200...
|
|
|
113
113
|
...
|
|
114
114
|
----
|
|
115
115
|
|
|
116
|
+
=== Create bibliographic item form YAML
|
|
117
|
+
[source,ruby]
|
|
118
|
+
----
|
|
119
|
+
hash = YAML.load_file 'spec/examples/nist_bib_item.yml'
|
|
120
|
+
=> {"id"=>"NISTIR 8011 Vol. 3",
|
|
121
|
+
...
|
|
122
|
+
|
|
123
|
+
bib_hash = RelatonNist::HashConverter.hash_to_bib hash
|
|
124
|
+
=> {:id=>"NISTIR 8011 Vol. 3",
|
|
125
|
+
...
|
|
126
|
+
|
|
127
|
+
RelatonNist::NistBibliographicItem.new bib_hash
|
|
128
|
+
=> #<RelatonNist::NistBibliographicItem:0x007f8b708505b8
|
|
129
|
+
...
|
|
130
|
+
----
|
|
131
|
+
|
|
116
132
|
== Development
|
|
117
133
|
|
|
118
134
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -12,7 +12,7 @@ module RelatonNist
|
|
|
12
12
|
# @param from [Date]
|
|
13
13
|
# @param to [Date, NilClass]
|
|
14
14
|
# @param extended [Date, NilClass]
|
|
15
|
-
def initialize(from
|
|
15
|
+
def initialize(from:, to: nil, extended: nil)
|
|
16
16
|
@from = from
|
|
17
17
|
@to = to
|
|
18
18
|
@extended = extended
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module RelatonNist
|
|
2
|
+
class HashConverter < RelatonBib::HashConverter
|
|
3
|
+
class << self
|
|
4
|
+
# @override RelatonBib::HashConverter.hash_to_bib
|
|
5
|
+
# @param args [Hash]
|
|
6
|
+
# @param nested [TrueClass, FalseClass]
|
|
7
|
+
# @return [Hash]
|
|
8
|
+
def hash_to_bib(args, nested = false)
|
|
9
|
+
ret = super
|
|
10
|
+
return if ret.nil?
|
|
11
|
+
|
|
12
|
+
keyword_hash_to_bib(ret)
|
|
13
|
+
commentperiod_hash_to_bib(ret)
|
|
14
|
+
ret
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def keyword_hash_to_bib(ret)
|
|
20
|
+
ret[:keyword]&.map! { |kw| Keyword.new kw }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def commentperiod_hash_to_bib(ret)
|
|
24
|
+
return unless ret[:commentperiod]
|
|
25
|
+
|
|
26
|
+
ret[:commentperiod] = CommentPeriod.new ret[:commentperiod]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -6,6 +6,7 @@ require "relaton_nist/xml_parser"
|
|
|
6
6
|
require "relaton_nist/keyword"
|
|
7
7
|
require "relaton_nist/comment_period"
|
|
8
8
|
require "relaton_nist/document_status"
|
|
9
|
+
require "relaton_nist/hash_converter"
|
|
9
10
|
|
|
10
11
|
module RelatonNist
|
|
11
12
|
class NistBibliography
|
|
@@ -14,7 +15,7 @@ module RelatonNist
|
|
|
14
15
|
# @return [RelatonNist::HitCollection]
|
|
15
16
|
def search(text, year = nil, opts = {})
|
|
16
17
|
HitCollection.new text, year, opts
|
|
17
|
-
rescue OpenURI::HTTPError, SocketError
|
|
18
|
+
rescue OpenURI::HTTPError, SocketError, OpenSSL::SSL::SSLError
|
|
18
19
|
raise RelatonBib::RequestError, "Could not access https://www.nist.gov"
|
|
19
20
|
end
|
|
20
21
|
|
|
@@ -33,9 +34,9 @@ module RelatonNist
|
|
|
33
34
|
code = code2.strip
|
|
34
35
|
if date2
|
|
35
36
|
if /\w+\s\d{4}/ =~ date2
|
|
36
|
-
opts[:issued_date] =
|
|
37
|
+
opts[:issued_date] = Date.strptime date2, "%B %Y"
|
|
37
38
|
elsif /\w+\s\d{2},\s\d{4}/ =~ date2
|
|
38
|
-
opts[:updated_date] =
|
|
39
|
+
opts[:updated_date] = Date.strptime date2, "%B %d, %Y"
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
opts[:stage] = stage if stage
|
|
@@ -91,7 +91,8 @@ module RelatonNist
|
|
|
91
91
|
resp = Net::HTTP.get_response(uri) # .encode("UTF-8")
|
|
92
92
|
Nokogiri::HTML(resp.body)
|
|
93
93
|
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
|
94
|
-
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError
|
|
94
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
|
|
95
|
+
OpenSSL::SSL::SSLError
|
|
95
96
|
raise RelatonBib::RequestError, "Could not access #{url}"
|
|
96
97
|
end
|
|
97
98
|
|
|
@@ -208,7 +209,7 @@ module RelatonNist
|
|
|
208
209
|
org = RelatonBib::Organization.new(
|
|
209
210
|
name: name, url: "www.nist.gov", abbreviation: "NIST",
|
|
210
211
|
)
|
|
211
|
-
contribs << RelatonBib::ContributionInfo.new(entity: org, role: ["publisher"])
|
|
212
|
+
contribs << RelatonBib::ContributionInfo.new(entity: org, role: [type: "publisher"])
|
|
212
213
|
authors = doc.at('//h4[.="Author(s)"]/following-sibling::p')
|
|
213
214
|
contribs += contributors(authors, "author")
|
|
214
215
|
editors = doc.at('//h4[.="Editor(s)"]/following-sibling::p')
|
|
@@ -230,14 +231,14 @@ module RelatonNist
|
|
|
230
231
|
)
|
|
231
232
|
end
|
|
232
233
|
if contr["surname"]
|
|
233
|
-
affiliation = RelatonBib::Affilation.new org
|
|
234
|
+
affiliation = RelatonBib::Affilation.new organization: org
|
|
234
235
|
entity = RelatonBib::Person.new(
|
|
235
236
|
name: full_name(contr, lang, script), affiliation: [affiliation],
|
|
236
237
|
)
|
|
237
238
|
else
|
|
238
239
|
entity = org
|
|
239
240
|
end
|
|
240
|
-
RelatonBib::ContributionInfo.new entity: entity, role: [role]
|
|
241
|
+
RelatonBib::ContributionInfo.new entity: entity, role: [type: role]
|
|
241
242
|
end
|
|
242
243
|
end
|
|
243
244
|
|
|
@@ -266,14 +267,14 @@ module RelatonNist
|
|
|
266
267
|
url = nil
|
|
267
268
|
end
|
|
268
269
|
org = RelatonBib::Organization.new name: org_name, url: url, abbreviation: abbrev
|
|
269
|
-
affiliation = RelatonBib::Affilation.new org
|
|
270
|
+
affiliation = RelatonBib::Affilation.new organization: org
|
|
270
271
|
entity = RelatonBib::Person.new(
|
|
271
272
|
name: fullname, affiliation: [affiliation],
|
|
272
273
|
)
|
|
273
274
|
else
|
|
274
275
|
entity = RelatonBib::Organization.new name: an, abbreviation: abbrev
|
|
275
276
|
end
|
|
276
|
-
RelatonBib::ContributionInfo.new entity: entity, role: [role]
|
|
277
|
+
RelatonBib::ContributionInfo.new entity: entity, role: [type: role]
|
|
277
278
|
end
|
|
278
279
|
end
|
|
279
280
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
|
|
@@ -455,13 +456,15 @@ module RelatonNist
|
|
|
455
456
|
ex = doc.at "//strong[contains(.,'The comment closing date has been extended to')]"
|
|
456
457
|
ext = ex&.text&.match(/\w+\s\d{2},\s\d{4}/).to_s
|
|
457
458
|
extended = ext.empty? ? nil : Date.strptime(ext, "%B %d, %Y")
|
|
458
|
-
CommentPeriod.new from, to, extended
|
|
459
|
+
CommentPeriod.new from: from, to: to, extended: extended
|
|
459
460
|
end
|
|
460
461
|
|
|
461
462
|
# @param json [Hash]
|
|
462
463
|
# @return [RelatonNist::CommentPeriod, NilClass]
|
|
463
464
|
def fetch_commentperiod_json(json)
|
|
464
|
-
|
|
465
|
+
return unless json["comment-from"]
|
|
466
|
+
|
|
467
|
+
CommentPeriod.new from: json["comment-from"], to: json["comment-to"]
|
|
465
468
|
end
|
|
466
469
|
end
|
|
467
470
|
end
|
data/lib/relaton_nist/version.rb
CHANGED
|
@@ -34,7 +34,10 @@ module RelatonNist
|
|
|
34
34
|
cp = item.at "./commentperiod"
|
|
35
35
|
return unless cp
|
|
36
36
|
|
|
37
|
-
CommentPeriod.new
|
|
37
|
+
CommentPeriod.new(
|
|
38
|
+
from: cp.at("from").text, to: cp.at("to")&.text,
|
|
39
|
+
extended: cp.at("extended")&.text
|
|
40
|
+
)
|
|
38
41
|
end
|
|
39
42
|
|
|
40
43
|
def fetch_keyword(item)
|
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: 0.3.
|
|
4
|
+
version: 0.3.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: 2019-
|
|
11
|
+
date: 2019-08-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -216,6 +216,7 @@ files:
|
|
|
216
216
|
- lib/relaton_nist/comment_period.rb
|
|
217
217
|
- lib/relaton_nist/data/pubs-export.zip
|
|
218
218
|
- lib/relaton_nist/document_status.rb
|
|
219
|
+
- lib/relaton_nist/hash_converter.rb
|
|
219
220
|
- lib/relaton_nist/hit.rb
|
|
220
221
|
- lib/relaton_nist/hit_collection.rb
|
|
221
222
|
- lib/relaton_nist/keyword.rb
|