relaton-bsi 1.10.1 → 1.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/grammars/biblio.rng +24 -1
- data/grammars/bsi.rng +18 -18
- data/grammars/isodoc.rng +73 -3
- data/lib/relaton_bsi/bsi_bibliography.rb +34 -27
- data/lib/relaton_bsi/hit_collection.rb +54 -9
- data/lib/relaton_bsi/version.rb +1 -1
- data/relaton_bsi.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6526b98460dccb16324ffdbc6cea2309b8e1eda6b5c06ed8272c4bae289b5fa
|
4
|
+
data.tar.gz: 4d64f8b75a735c5ccfbacf3f03816b62ebd22ea4cb2d564ebbb67b87643fbaa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b640a7761c3eab1336b54904b31ce8b68477b1736bce1ec2d5b1f4775f8f2c31d9b35e9608e48a922c957e62000c4860f1fecfcb743d6602f2becc5446a7ebab
|
7
|
+
data.tar.gz: 1f80f9e3e3a9a0f613bf239e57b53bb8c9a0e189e841d11d9668a479d959eaa1accbd78a8e6ede2e1a78103a04d2658417eed19ab92712ac693ae1921aafe10d
|
data/grammars/biblio.rng
CHANGED
@@ -677,6 +677,9 @@
|
|
677
677
|
<zeroOrMore>
|
678
678
|
<ref name="extent"/>
|
679
679
|
</zeroOrMore>
|
680
|
+
<optional>
|
681
|
+
<ref name="bibliographic_size"/>
|
682
|
+
</optional>
|
680
683
|
<zeroOrMore>
|
681
684
|
<ref name="accesslocation"/>
|
682
685
|
</zeroOrMore>
|
@@ -922,9 +925,29 @@
|
|
922
925
|
<text/>
|
923
926
|
</element>
|
924
927
|
</define>
|
928
|
+
<define name="sizevalue">
|
929
|
+
<element name="value">
|
930
|
+
<attribute name="type"/>
|
931
|
+
<text/>
|
932
|
+
</element>
|
933
|
+
</define>
|
934
|
+
<define name="bibliographic_size">
|
935
|
+
<element name="size">
|
936
|
+
<oneOrMore>
|
937
|
+
<ref name="sizevalue"/>
|
938
|
+
</oneOrMore>
|
939
|
+
</element>
|
940
|
+
</define>
|
925
941
|
<define name="extent">
|
926
942
|
<element name="extent">
|
927
|
-
<
|
943
|
+
<choice>
|
944
|
+
<zeroOrMore>
|
945
|
+
<ref name="locality"/>
|
946
|
+
</zeroOrMore>
|
947
|
+
<zeroOrMore>
|
948
|
+
<ref name="localityStack"/>
|
949
|
+
</zeroOrMore>
|
950
|
+
</choice>
|
928
951
|
</element>
|
929
952
|
</define>
|
930
953
|
<define name="series">
|
data/grammars/bsi.rng
CHANGED
@@ -226,14 +226,14 @@
|
|
226
226
|
<optional>
|
227
227
|
<choice>
|
228
228
|
<ref name="floating-title"/>
|
229
|
-
<ref name="section-title"/>
|
229
|
+
<ref name="floating-section-title"/>
|
230
230
|
</choice>
|
231
231
|
</optional>
|
232
232
|
<ref name="clause"/>
|
233
233
|
<optional>
|
234
234
|
<choice>
|
235
235
|
<ref name="floating-title"/>
|
236
|
-
<ref name="section-title"/>
|
236
|
+
<ref name="floating-section-title"/>
|
237
237
|
</choice>
|
238
238
|
</optional>
|
239
239
|
<optional>
|
@@ -245,7 +245,7 @@
|
|
245
245
|
<optional>
|
246
246
|
<choice>
|
247
247
|
<ref name="floating-title"/>
|
248
|
-
<ref name="section-title"/>
|
248
|
+
<ref name="floating-section-title"/>
|
249
249
|
</choice>
|
250
250
|
</optional>
|
251
251
|
<optional>
|
@@ -254,7 +254,7 @@
|
|
254
254
|
<optional>
|
255
255
|
<choice>
|
256
256
|
<ref name="floating-title"/>
|
257
|
-
<ref name="section-title"/>
|
257
|
+
<ref name="floating-section-title"/>
|
258
258
|
</choice>
|
259
259
|
</optional>
|
260
260
|
<oneOrMore>
|
@@ -263,13 +263,26 @@
|
|
263
263
|
<ref name="term-clause"/>
|
264
264
|
<ref name="terms"/>
|
265
265
|
<ref name="floating-title"/>
|
266
|
-
<ref name="section-title"/>
|
266
|
+
<ref name="floating-section-title"/>
|
267
267
|
</choice>
|
268
268
|
</oneOrMore>
|
269
269
|
</element>
|
270
270
|
</define>
|
271
271
|
</include>
|
272
272
|
<!-- end overrides -->
|
273
|
+
<define name="floating-section-title">
|
274
|
+
<element name="section-title">
|
275
|
+
<attribute name="id">
|
276
|
+
<data type="ID"/>
|
277
|
+
</attribute>
|
278
|
+
<attribute name="depth">
|
279
|
+
<data type="int"/>
|
280
|
+
</attribute>
|
281
|
+
<zeroOrMore>
|
282
|
+
<ref name="TextElement"/>
|
283
|
+
</zeroOrMore>
|
284
|
+
</element>
|
285
|
+
</define>
|
273
286
|
<define name="AdmonitionType" combine="choice">
|
274
287
|
<value>commentary</value>
|
275
288
|
</define>
|
@@ -316,17 +329,4 @@
|
|
316
329
|
</zeroOrMore>
|
317
330
|
</element>
|
318
331
|
</define>
|
319
|
-
<!-- <define name="section-title">
|
320
|
-
<element name="section-title">
|
321
|
-
<attribute name="id">
|
322
|
-
<data type="ID"/>
|
323
|
-
</attribute>
|
324
|
-
<attribute name="depth">
|
325
|
-
<data type="int"/>
|
326
|
-
</attribute>
|
327
|
-
<zeroOrMore>
|
328
|
-
<ref name="TextElement"/>
|
329
|
-
</zeroOrMore>
|
330
|
-
</element>
|
331
|
-
</define> -->
|
332
332
|
</grammar>
|
data/grammars/isodoc.rng
CHANGED
@@ -152,9 +152,7 @@
|
|
152
152
|
<data type="boolean"/>
|
153
153
|
</attribute>
|
154
154
|
</optional>
|
155
|
-
<
|
156
|
-
<ref name="PureTextElement"/>
|
157
|
-
</oneOrMore>
|
155
|
+
<ref name="XrefBody"/>
|
158
156
|
</element>
|
159
157
|
</define>
|
160
158
|
<define name="erefType">
|
@@ -188,6 +186,42 @@
|
|
188
186
|
<ref name="PureTextElement"/>
|
189
187
|
</oneOrMore>
|
190
188
|
</define>
|
189
|
+
<define name="localityStack">
|
190
|
+
<element name="localityStack">
|
191
|
+
<optional>
|
192
|
+
<attribute name="connective">
|
193
|
+
<choice>
|
194
|
+
<value>and</value>
|
195
|
+
<value>or</value>
|
196
|
+
<value>from</value>
|
197
|
+
<value>to</value>
|
198
|
+
<value/>
|
199
|
+
</choice>
|
200
|
+
</attribute>
|
201
|
+
</optional>
|
202
|
+
<zeroOrMore>
|
203
|
+
<ref name="locality"/>
|
204
|
+
</zeroOrMore>
|
205
|
+
</element>
|
206
|
+
</define>
|
207
|
+
<define name="sourceLocalityStack">
|
208
|
+
<element name="sourceLocalityStack">
|
209
|
+
<optional>
|
210
|
+
<attribute name="connective">
|
211
|
+
<choice>
|
212
|
+
<value>and</value>
|
213
|
+
<value>or</value>
|
214
|
+
<value>from</value>
|
215
|
+
<value>to</value>
|
216
|
+
<value/>
|
217
|
+
</choice>
|
218
|
+
</attribute>
|
219
|
+
</optional>
|
220
|
+
<zeroOrMore>
|
221
|
+
<ref name="sourceLocality"/>
|
222
|
+
</zeroOrMore>
|
223
|
+
</element>
|
224
|
+
</define>
|
191
225
|
<define name="ul">
|
192
226
|
<element name="ul">
|
193
227
|
<attribute name="id">
|
@@ -1098,6 +1132,16 @@
|
|
1098
1132
|
</define>
|
1099
1133
|
</include>
|
1100
1134
|
<!-- end overrides -->
|
1135
|
+
<define name="image" combine="choice">
|
1136
|
+
<element name="svg">
|
1137
|
+
<oneOrMore>
|
1138
|
+
<choice>
|
1139
|
+
<text/>
|
1140
|
+
<ref name="AnyElement"/>
|
1141
|
+
</choice>
|
1142
|
+
</oneOrMore>
|
1143
|
+
</element>
|
1144
|
+
</define>
|
1101
1145
|
<define name="MultilingualRenderingType">
|
1102
1146
|
<choice>
|
1103
1147
|
<value>common</value>
|
@@ -2631,4 +2675,30 @@
|
|
2631
2675
|
</zeroOrMore>
|
2632
2676
|
</element>
|
2633
2677
|
</define>
|
2678
|
+
<define name="XrefBody">
|
2679
|
+
<zeroOrMore>
|
2680
|
+
<ref name="XrefTarget"/>
|
2681
|
+
</zeroOrMore>
|
2682
|
+
<oneOrMore>
|
2683
|
+
<ref name="PureTextElement"/>
|
2684
|
+
</oneOrMore>
|
2685
|
+
</define>
|
2686
|
+
<define name="XrefTarget">
|
2687
|
+
<element name="location">
|
2688
|
+
<attribute name="target">
|
2689
|
+
<data type="string">
|
2690
|
+
<param name="pattern">\i\c*|\c+#\c+</param>
|
2691
|
+
</data>
|
2692
|
+
</attribute>
|
2693
|
+
<attribute name="connective">
|
2694
|
+
<choice>
|
2695
|
+
<value>and</value>
|
2696
|
+
<value>or</value>
|
2697
|
+
<value>from</value>
|
2698
|
+
<value>to</value>
|
2699
|
+
<value/>
|
2700
|
+
</choice>
|
2701
|
+
</attribute>
|
2702
|
+
</element>
|
2703
|
+
</define>
|
2634
2704
|
</grammar>
|
@@ -35,7 +35,7 @@ module RelatonBsi
|
|
35
35
|
def get(code, year = nil, opts = {})
|
36
36
|
# y = code.split(":")[1]
|
37
37
|
year ||= code_parts(code)[:year]
|
38
|
-
ret =
|
38
|
+
ret = bib_get(code, year, opts)
|
39
39
|
return nil if ret.nil?
|
40
40
|
|
41
41
|
ret = ret.to_most_recent_reference unless year || opts[:keep_year]
|
@@ -43,10 +43,27 @@ module RelatonBsi
|
|
43
43
|
ret
|
44
44
|
end
|
45
45
|
|
46
|
+
#
|
47
|
+
# Destruct code to its parts.
|
48
|
+
#
|
49
|
+
# @param [String] code document identifier
|
50
|
+
#
|
51
|
+
# @return [MatchData] parts of the code
|
52
|
+
#
|
53
|
+
def code_parts(code)
|
54
|
+
%r{
|
55
|
+
^(?:BSI\s)?(?<code>(?:[A-Z]+\s)*[^:\s+]+)
|
56
|
+
(?::(?<year>\d{4}))?
|
57
|
+
(?:\+(?<a>[^:\s]+)(?::(?<y>\d{4}))?)?
|
58
|
+
(?:\s(?<rest>.+))?
|
59
|
+
}x.match code
|
60
|
+
end
|
61
|
+
|
46
62
|
private
|
47
63
|
|
48
64
|
def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
|
49
|
-
|
65
|
+
y = code_parts(code)[:year]
|
66
|
+
id = year && !y ? "#{code}:#{year}" : code
|
50
67
|
warn "[relaton-bsi] WARNING: no match found online for #{id}. "\
|
51
68
|
"The code must be exactly like it is on the standards website."
|
52
69
|
unless missed_years.empty?
|
@@ -65,29 +82,19 @@ module RelatonBsi
|
|
65
82
|
nil
|
66
83
|
end
|
67
84
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
85
|
+
#
|
86
|
+
# Search for a BSI standard.
|
87
|
+
#
|
88
|
+
# @param [String] code the BSI standard Code to look up
|
89
|
+
#
|
90
|
+
# @return [RelatonBsi::HitCollection] a collection of hits
|
91
|
+
#
|
92
|
+
def search_filter(code)
|
93
|
+
cp = code_parts code
|
72
94
|
warn "[relaton-bsi] (\"#{code}\") fetching..."
|
73
|
-
return [] unless
|
74
|
-
|
75
|
-
result = search(code)
|
76
|
-
result.select do |i|
|
77
|
-
# %r{^(?<code2>[^:]+)} =~ i.hit[:code]
|
78
|
-
cp2 = code_parts i.hit[:code]
|
79
|
-
cp2[:code] == cp1[:code] && (!cp1[:a] || cp2[:a] == cp1[:a]) &&
|
80
|
-
(!cp1[:y] || cp2[:y] == cp1[:y])
|
81
|
-
end
|
82
|
-
end
|
95
|
+
return [] unless cp
|
83
96
|
|
84
|
-
|
85
|
-
%r{
|
86
|
-
^(?:BSI\s)?(?<code>[^:]+)
|
87
|
-
(?::(?<year>\d{4}))?
|
88
|
-
(?:\+(?<a>[^:]+):)?
|
89
|
-
(?::(?<y>\d{4}))?
|
90
|
-
}x.match code
|
97
|
+
search(code).filter_hits!(cp)
|
91
98
|
end
|
92
99
|
|
93
100
|
# Sort through the results from Isobib, fetching them three at a time,
|
@@ -96,10 +103,10 @@ module RelatonBsi
|
|
96
103
|
# Only expects the first page of results to be populated.
|
97
104
|
# Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
|
98
105
|
# If no match, returns any years which caused mismatch, for error reporting
|
99
|
-
def
|
106
|
+
def results_filter(result, year)
|
100
107
|
missed_years = []
|
101
108
|
result.each do |r|
|
102
|
-
|
109
|
+
pyear = code_parts(r.hit[:code])[:year]
|
103
110
|
if !year || year == pyear
|
104
111
|
ret = r.fetch
|
105
112
|
return { ret: ret } if ret
|
@@ -110,9 +117,9 @@ module RelatonBsi
|
|
110
117
|
{ years: missed_years }
|
111
118
|
end
|
112
119
|
|
113
|
-
def
|
120
|
+
def bib_get(code, year, _opts)
|
114
121
|
result = search_filter(code) || return
|
115
|
-
ret =
|
122
|
+
ret = results_filter(result, year)
|
116
123
|
if ret[:ret]
|
117
124
|
warn "[relaton-bsi] (\"#{code}\") found #{ret[:ret].docidentifier.first&.id}"
|
118
125
|
ret[:ret]
|
@@ -8,8 +8,12 @@ module RelatonBsi
|
|
8
8
|
class HitCollection < RelatonBib::HitCollection
|
9
9
|
DOMAIN = "https://shop.bsigroup.com"
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
11
|
+
#
|
12
|
+
# Initialize a new HitCollection.
|
13
|
+
#
|
14
|
+
# @param ref [String] reference
|
15
|
+
# @param year [String] year
|
16
|
+
#
|
13
17
|
def initialize(ref, year = nil)
|
14
18
|
super ref, year
|
15
19
|
config = Algolia::Search::Config.new(
|
@@ -19,18 +23,40 @@ module RelatonBsi
|
|
19
23
|
client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
|
20
24
|
index = client.init_index "shopify_products"
|
21
25
|
resp = index.search text # , facetFilters: "product_type:standard"
|
22
|
-
@array =
|
26
|
+
@array = create_hits resp[:hits]
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Filter the search results for a BSI standard.
|
31
|
+
#
|
32
|
+
# @param [MatchData] code_parts parts of document identifier
|
33
|
+
#
|
34
|
+
# @return [self] filtered search results
|
35
|
+
#
|
36
|
+
def filter_hits!(code_parts)
|
37
|
+
hits = filter code_parts
|
38
|
+
hits = filter code_parts, skip_rest: true if hits.empty?
|
39
|
+
hits = filter code_parts, drop_amd: true if hits.empty?
|
40
|
+
@array = hits
|
41
|
+
self
|
23
42
|
end
|
24
43
|
|
25
44
|
private
|
26
45
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
46
|
+
#
|
47
|
+
# Create hits from search results.
|
48
|
+
#
|
49
|
+
# @param hits [Array<Hash>] search results
|
50
|
+
#
|
51
|
+
# @return [Array<RelatonBsi::Hit>] hits
|
52
|
+
#
|
53
|
+
def create_hits(hits) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
54
|
+
hits.each_with_object([]) do |h, obj|
|
55
|
+
next unless h[:meta][:global][:publishedDate]
|
56
|
+
|
31
57
|
code = h[:meta][:global][:primaryDesignator]
|
32
|
-
.sub(/\s(?:LOOSELEAF|\(A5 LAMINATED\)|-\
|
33
|
-
Hit.new(
|
58
|
+
.sub(/\s?(?:LOOSELEAF|\(A5 LAMINATED\)|-\s?TC$)/, "")
|
59
|
+
obj << Hit.new(
|
34
60
|
{
|
35
61
|
code: code,
|
36
62
|
title: h[:title],
|
@@ -44,5 +70,24 @@ module RelatonBsi
|
|
44
70
|
)
|
45
71
|
end.sort_by { |h| h.hit[:date] }.reverse
|
46
72
|
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Select hits that match the document identifier.
|
76
|
+
#
|
77
|
+
# @param [MatchData] code_parts parts of document identifier
|
78
|
+
# @param [Boolean] drop_amd drop amendments and corrigendums
|
79
|
+
# @param [Boolean] skip_rest skip rest suffix of document identifier
|
80
|
+
#
|
81
|
+
def filter(code_parts, drop_amd: false, skip_rest: false) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
82
|
+
@array.select do |i|
|
83
|
+
code = drop_amd ? i.hit[:code].sub(/\+[AC]\d+.*$/, "") : i.hit[:code]
|
84
|
+
cp = BsiBibliography.code_parts code
|
85
|
+
match = cp[:code] == code_parts[:code] && cp[:a] == code_parts[:a] &&
|
86
|
+
(!code_parts[:y] || cp[:y] == code_parts[:y]) &&
|
87
|
+
(skip_rest || cp[:rest] == code_parts[:rest])
|
88
|
+
i.hit[:code] = code if drop_amd && match
|
89
|
+
match
|
90
|
+
end
|
91
|
+
end
|
47
92
|
end
|
48
93
|
end
|
data/lib/relaton_bsi/version.rb
CHANGED
data/relaton_bsi.gemspec
CHANGED
@@ -40,5 +40,5 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency "graphql", "1.13.6"
|
41
41
|
spec.add_dependency "graphql-client", "~> 0.16.0"
|
42
42
|
# spec.add_dependency "mechanize", "~> 2.8.0"
|
43
|
-
spec.add_dependency "relaton-iso-bib", "~> 1.
|
43
|
+
spec.add_dependency "relaton-iso-bib", "~> 1.11.0"
|
44
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-bsi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.1
|
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-
|
11
|
+
date: 2022-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equivalent-xml
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
145
|
+
version: 1.11.0
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
152
|
+
version: 1.11.0
|
153
153
|
description: 'RelatonBsi: retrieve BSI Standards for bibliographic use using the BibliographicItem
|
154
154
|
model'
|
155
155
|
email:
|