relaton-bsi 1.8.4 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -11
- data/.rubocop.yml +2 -0
- data/README.adoc +12 -3
- data/grammars/biblio.rng +1 -0
- data/grammars/bsi.rng +30 -18
- data/grammars/isodoc.rng +246 -10
- data/grammars/isostandard.rng +19 -3
- data/grammars/reqt.rng +31 -2
- data/lib/relaton_bsi/bsi_bibliographic_item.rb +13 -14
- data/lib/relaton_bsi/bsi_bibliography.rb +20 -17
- data/lib/relaton_bsi/hit_collection.rb +25 -15
- data/lib/relaton_bsi/schema.json +24882 -0
- data/lib/relaton_bsi/scrapper.rb +136 -78
- data/lib/relaton_bsi/version.rb +1 -1
- data/lib/relaton_bsi/xml_parser.rb +1 -3
- data/relaton_bsi.gemspec +4 -10
- metadata +22 -7
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "mechanize"
|
3
|
+
# require "mechanize"
|
4
4
|
require "relaton_iso_bib"
|
5
5
|
require "relaton_bsi/bsi_bibliographic_item"
|
6
6
|
require "relaton_bsi/scrapper"
|
@@ -20,21 +20,25 @@ module RelatonBsi
|
|
20
20
|
HitCollection.new code, year
|
21
21
|
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
22
22
|
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
23
|
-
Net::ProtocolError
|
24
|
-
raise RelatonBib::RequestError,
|
23
|
+
Net::ProtocolError, Algolia::AlgoliaUnreachableHostError => e
|
24
|
+
raise RelatonBib::RequestError, e.message
|
25
25
|
end
|
26
26
|
|
27
|
+
#
|
27
28
|
# @param code [String] the BSI standard Code to look up
|
28
29
|
# @param year [String] the year the standard was published (optional)
|
29
|
-
# @param opts [Hash] options
|
30
|
+
# @param opts [Hash] options
|
31
|
+
# @option opts [Boolean] :all_parts if all-parts reference is required
|
32
|
+
# @option opts [Boolean] :no_year if last published document is required
|
33
|
+
#
|
30
34
|
# @return [String] Relaton XML serialisation of reference
|
31
|
-
def get(code, year = nil, opts = {})
|
32
|
-
c, y = code.split
|
35
|
+
def get(code, year = nil, opts = {})
|
36
|
+
c, y = code.split ":"
|
33
37
|
year ||= y
|
34
38
|
ret = bib_get1(c, year, opts)
|
35
39
|
return nil if ret.nil?
|
36
40
|
|
37
|
-
|
41
|
+
ret = ret.to_most_recent_reference unless year || opts[:keep_year]
|
38
42
|
# ret = ret.to_all_parts if opts[:all_parts]
|
39
43
|
ret
|
40
44
|
end
|
@@ -44,18 +48,19 @@ module RelatonBsi
|
|
44
48
|
def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
|
45
49
|
id = year ? "#{code}:#{year}" : code
|
46
50
|
warn "[relaton-bsi] WARNING: no match found online for #{id}. "\
|
47
|
-
|
51
|
+
"The code must be exactly like it is on the standards website."
|
48
52
|
unless missed_years.empty?
|
49
|
-
warn "[relaton-bsi] (There was no match for #{year}, though there
|
50
|
-
|
53
|
+
warn "[relaton-bsi] (There was no match for #{year}, though there "\
|
54
|
+
"were matches found for #{missed_years.join(', ')}.)"
|
51
55
|
end
|
52
56
|
# if /\d-\d/.match? code
|
53
|
-
# warn "[relaton-bsi] The provided document part may not exist, or
|
54
|
-
# "may no longer be published in parts."
|
57
|
+
# warn "[relaton-bsi] The provided document part may not exist, or "\
|
58
|
+
# "the document may no longer be published in parts."
|
55
59
|
# else
|
56
|
-
# warn "[relaton-bsi] If you wanted to cite all document parts for
|
57
|
-
# "use \"#{code} (all parts)\".\nIf the document
|
58
|
-
# "use its document type abbreviation (TS, TR,
|
60
|
+
# warn "[relaton-bsi] If you wanted to cite all document parts for "\
|
61
|
+
# "the reference, use \"#{code} (all parts)\".\nIf the document "\
|
62
|
+
# "is not a standard, use its document type abbreviation (TS, TR, "\
|
63
|
+
# "PAS, Guide)."
|
59
64
|
# end
|
60
65
|
nil
|
61
66
|
end
|
@@ -68,8 +73,6 @@ module RelatonBsi
|
|
68
73
|
|
69
74
|
result = search(code)
|
70
75
|
result.select do |i|
|
71
|
-
next true unless i.hit[:code]
|
72
|
-
|
73
76
|
%r{^(?<code2>[^:]+)} =~ i.hit[:code]
|
74
77
|
code2.include?(code1)
|
75
78
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "algolia"
|
3
4
|
require "relaton_bsi/hit"
|
4
5
|
|
5
6
|
module RelatonBsi
|
@@ -7,31 +8,40 @@ module RelatonBsi
|
|
7
8
|
class HitCollection < RelatonBib::HitCollection
|
8
9
|
DOMAIN = "https://shop.bsigroup.com"
|
9
10
|
|
10
|
-
# @return [Mechanize]
|
11
|
-
attr_reader :agent
|
12
11
|
|
13
12
|
# @param ref [String]
|
14
13
|
# @param year [String]
|
15
14
|
def initialize(ref, year = nil)
|
16
15
|
super ref, year
|
17
|
-
@agent = Mechanize.new
|
18
|
-
resp = agent.get "#{DOMAIN}/SearchResults/?q=#{ref}"
|
19
|
-
|
16
|
+
# @agent = Mechanize.new
|
17
|
+
# resp = agent.get "#{DOMAIN}/SearchResults/?q=#{ref}"
|
18
|
+
config = Algolia::Search::Config.new(application_id: "575YE157G9", api_key: "a057b4e74099445df2eddb7940828a10")
|
19
|
+
client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
|
20
|
+
index = client.init_index "shopify_products"
|
21
|
+
resp = index.search text # , facetFilters: "product_type:standard"
|
22
|
+
@array = hits resp[:hits]
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
26
|
|
24
|
-
# @param
|
27
|
+
# @param hits [Array<Hash>]
|
25
28
|
# @return [Array<RelatonBsi::Hit>]
|
26
|
-
def hits(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def hits(hits) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
30
|
+
hits.map do |h|
|
31
|
+
code = h[:meta][:global][:primaryDesignator].sub(/\sLOOSELEAF|\s\(A5 LAMINATED\)/, "")
|
32
|
+
Hit.new(
|
33
|
+
{
|
34
|
+
code: code,
|
35
|
+
title: h[:title],
|
36
|
+
url: h[:handle],
|
37
|
+
date: h[:meta][:global][:publishedDate],
|
38
|
+
publisher: h[:meta][:global][:publisher],
|
39
|
+
status: h[:meta][:global][:status],
|
40
|
+
ics: h[:meta][:global][:icsCodesAlgoliaStringArray],
|
41
|
+
doctype: h[:product_type],
|
42
|
+
}, self
|
43
|
+
)
|
44
|
+
end.sort_by { |h| h.hit[:date] }.reverse
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|